HLSF use long as aloloc size

This commit is contained in:
Nitload
2026-02-23 12:32:15 +08:00
parent 4bd88ccbca
commit c155cab510
552 changed files with 154266 additions and 154330 deletions
+6 -6
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.IntelliRush.Options.IntelliRushOptions"> <Root Type="DevExpress.IntelliRush.Options.IntelliRushOptions">
<Options Language="Neutral"> <Options Language="Neutral">
<Enabled>True</Enabled> <Enabled>True</Enabled>
<DisabledLanguages /> <DisabledLanguages />
</Options> </Options>
</Root> </Root>
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.VisualizePlugins.RightMarginLine.Options.RightMarginLineOptions"> <Root Type="DevExpress.CodeRush.VisualizePlugins.RightMarginLine.Options.RightMarginLineOptions">
<Options Language="Neutral"> <Options Language="Neutral">
<Enabled>True</Enabled> <Enabled>True</Enabled>
<Style>Dot</Style> <Style>Dot</Style>
<Width>2</Width> <Width>2</Width>
</Options> </Options>
</Root> </Root>
+5 -5
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.VSFeatures.SpellChecker.Options.SpellCheckerOptions"> <Root Type="DevExpress.CodeRush.VSFeatures.SpellChecker.Options.SpellCheckerOptions">
<Options Language="Neutral"> <Options Language="Neutral">
<SupportedElements>XmlComments|Comments|Strings|VerbatimStrings|PublicIdentifiers|InternalIdentifiers|ProtectedInternalIdentifiers|ProtectedIdentifiers|PrivateIdentifiers|LocalIdentifiers|FileNames</SupportedElements> <SupportedElements>XmlComments|Comments|Strings|VerbatimStrings|PublicIdentifiers|InternalIdentifiers|ProtectedInternalIdentifiers|ProtectedIdentifiers|PrivateIdentifiers|LocalIdentifiers|FileNames</SupportedElements>
</Options> </Options>
</Root> </Root>
+5 -5
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.Foundation.CodePlaces.Options.FavoritesListContainer"> <Root Type="DevExpress.CodeRush.Foundation.CodePlaces.Options.FavoritesListContainer">
<Options Language="Neutral"> <Options Language="Neutral">
<Groups /> <Groups />
</Options> </Options>
</Root> </Root>
+5 -5
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.VisualStudio.Services.Options.BuildEngineOptions"> <Root Type="DevExpress.CodeRush.VisualStudio.Services.Options.BuildEngineOptions">
<Options Language="Neutral"> <Options Language="Neutral">
<Enabled>True</Enabled> <Enabled>True</Enabled>
</Options> </Options>
</Root> </Root>
+57 -57
View File
@@ -1,58 +1,58 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.Foundation.Shortcuts.ShortcutsOptions"> <Root Type="DevExpress.CodeRush.Foundation.Shortcuts.ShortcutsOptions">
<Options Language="Neutral"> <Options Language="Neutral">
<RootFolder> <RootFolder>
<SubFolders> <SubFolders>
<Item Id="{01ea3896-6cc1-4912-824e-88c7c5a82a25}"> <Item Id="{01ea3896-6cc1-4912-824e-88c7c5a82a25}">
<Bindings> <Bindings>
<Item Id="{88959174-9ffa-429b-bef8-aeddb65b9c2a}" /> <Item Id="{88959174-9ffa-429b-bef8-aeddb65b9c2a}" />
<Item Id="{975814d0-802e-4143-a979-22d3f975cfc2}" /> <Item Id="{975814d0-802e-4143-a979-22d3f975cfc2}" />
<Item Id="{0260c6ac-cfdb-4874-88c5-66bbf9b84e9b}" /> <Item Id="{0260c6ac-cfdb-4874-88c5-66bbf9b84e9b}" />
<Item Id="{dd4ceb84-80b3-4517-ac9b-170dcffe646f}" /> <Item Id="{dd4ceb84-80b3-4517-ac9b-170dcffe646f}" />
<Item Id="{a1f4a77e-b674-41bd-880f-195c3c0c1dfe}" /> <Item Id="{a1f4a77e-b674-41bd-880f-195c3c0c1dfe}" />
<Item Id="{ee0b4600-2d2c-4700-8d4d-578027321f74}" /> <Item Id="{ee0b4600-2d2c-4700-8d4d-578027321f74}" />
<Item Id="{d37c2c40-a7c6-403f-8556-8fb690d4c656}"> <Item Id="{d37c2c40-a7c6-403f-8556-8fb690d4c656}">
<Enabled>False</Enabled> <Enabled>False</Enabled>
</Item> </Item>
<Item Id="{baf8010d-02d7-4ac9-b644-0c670f796ce4}" /> <Item Id="{baf8010d-02d7-4ac9-b644-0c670f796ce4}" />
<Item Id="{676742ae-19ea-4884-840d-2be66d9bb49c}" /> <Item Id="{676742ae-19ea-4884-840d-2be66d9bb49c}" />
<Item Id="{43d481e0-19e4-405d-b7e3-687fc610050c}"> <Item Id="{43d481e0-19e4-405d-b7e3-687fc610050c}">
<Enabled>False</Enabled> <Enabled>False</Enabled>
</Item> </Item>
<Item Id="{f1a06e4e-3241-438d-84e5-044e3e907492}" /> <Item Id="{f1a06e4e-3241-438d-84e5-044e3e907492}" />
<Item Id="{3b8cae25-e23f-443c-98ff-83d38711f26e}" /> <Item Id="{3b8cae25-e23f-443c-98ff-83d38711f26e}" />
<Item Id="{491253a6-324c-4a0f-b4e5-aff443b00fb9}" /> <Item Id="{491253a6-324c-4a0f-b4e5-aff443b00fb9}" />
<Item Id="{a06ba470-2048-47ac-b7af-93653ce09359}" /> <Item Id="{a06ba470-2048-47ac-b7af-93653ce09359}" />
<Item Id="{1562ccb9-7f21-492d-8c71-42d5ff7ecf9a}" /> <Item Id="{1562ccb9-7f21-492d-8c71-42d5ff7ecf9a}" />
<Item Id="{34c575e6-55c2-4d7f-a839-8167bfa1a831}" /> <Item Id="{34c575e6-55c2-4d7f-a839-8167bfa1a831}" />
<Item Id="{b253a65c-b13a-42bd-8d59-4a790ce19f3a}" /> <Item Id="{b253a65c-b13a-42bd-8d59-4a790ce19f3a}" />
<Item Id="{011d4fb6-22ba-4d11-8a05-ed753b5dbd8a}" /> <Item Id="{011d4fb6-22ba-4d11-8a05-ed753b5dbd8a}" />
<Item Id="{804634ae-7823-4541-a8fe-d7da6c807b41}" /> <Item Id="{804634ae-7823-4541-a8fe-d7da6c807b41}" />
<Item Id="{eb8a243c-8645-46cf-98ac-e73a6e32cf3e}" /> <Item Id="{eb8a243c-8645-46cf-98ac-e73a6e32cf3e}" />
<Item Id="{5f2e52af-bb7d-46cc-819d-3f2a2860ba8c}" /> <Item Id="{5f2e52af-bb7d-46cc-819d-3f2a2860ba8c}" />
<Item Id="{9848d5d7-d513-4f1e-98aa-fcd21b3eb498}" /> <Item Id="{9848d5d7-d513-4f1e-98aa-fcd21b3eb498}" />
</Bindings> </Bindings>
</Item> </Item>
<Item Id="{66d31aae-e1f0-43b9-8108-123cb59d73bd}" /> <Item Id="{66d31aae-e1f0-43b9-8108-123cb59d73bd}" />
<Item Id="{4fcfb46a-6fd9-4ba4-a790-6447cb1cf0a5}" /> <Item Id="{4fcfb46a-6fd9-4ba4-a790-6447cb1cf0a5}" />
<Item Id="{55d41133-671c-49f1-a934-6c5d59c3f319}"> <Item Id="{55d41133-671c-49f1-a934-6c5d59c3f319}">
<SubFolders> <SubFolders>
<Item Id="{4bc2f87d-6dc0-41b5-9b0b-251498b765df}"> <Item Id="{4bc2f87d-6dc0-41b5-9b0b-251498b765df}">
<Bindings> <Bindings>
<Item Id="{d18a79d1-fff5-4b71-8301-fb8f2397e0ac}" /> <Item Id="{d18a79d1-fff5-4b71-8301-fb8f2397e0ac}" />
<Item Id="{cc238591-6417-4f4c-bca3-08b8ecbb8a1b}"> <Item Id="{cc238591-6417-4f4c-bca3-08b8ecbb8a1b}">
<Enabled>False</Enabled> <Enabled>False</Enabled>
</Item> </Item>
</Bindings> </Bindings>
</Item> </Item>
<Item Id="{0d070b5c-9bc8-4784-9071-548ab0ef93e9}" /> <Item Id="{0d070b5c-9bc8-4784-9071-548ab0ef93e9}" />
</SubFolders> </SubFolders>
</Item> </Item>
<Item Id="{a3f2b3b4-9497-4db5-9f8b-c4b30a2240ac}" /> <Item Id="{a3f2b3b4-9497-4db5-9f8b-c4b30a2240ac}" />
<Item Id="{318b8900-85af-4c66-b37f-8a86508e7a89}" /> <Item Id="{318b8900-85af-4c66-b37f-8a86508e7a89}" />
<Item Id="{d33fb6fa-56b3-40a1-b169-71e855b2e3a2}" /> <Item Id="{d33fb6fa-56b3-40a1-b169-71e855b2e3a2}" />
<Item Id="{4aa0656f-7150-440b-8585-509c548e9d7e}" /> <Item Id="{4aa0656f-7150-440b-8585-509c548e9d7e}" />
</SubFolders> </SubFolders>
</RootFolder> </RootFolder>
</Options> </Options>
</Root> </Root>
@@ -1,93 +1,93 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.Foundation.Templates.TemplatesOptions"> <Root Type="DevExpress.CodeRush.Foundation.Templates.TemplatesOptions">
<Options Language="C#"> <Options Language="C#">
<RootCategory> <RootCategory>
<Categories> <Categories>
<Item Id="{9bc0d39a-b20c-41bb-bd1c-4d08d6d999a9}"> <Item Id="{9bc0d39a-b20c-41bb-bd1c-4d08d6d999a9}">
<Templates> <Templates>
<Item Id="{2b7014a2-6093-4095-ad6d-799b52ef74e0}"> <Item Id="{2b7014a2-6093-4095-ad6d-799b52ef74e0}">
<Items> <Items>
<Item Id="{b3ec38a7-ed71-4ab9-9a43-1623fc3d4c30}"> <Item Id="{b3ec38a7-ed71-4ab9-9a43-1623fc3d4c30}">
<Expansion>//----------------------------------------------------------------------- <Expansion>//-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="«?FileBase»" // file="«?FileBase»"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: «?GetUserInfo(Company)» // AuthorGroup: «?GetUserInfo(Company)»
// Copyright (c) «?GetUserInfo(Company)». All rights reserved. // Copyright (c) «?GetUserInfo(Company)». All rights reserved.
// //
//Permission is hereby granted, free of charge, to any person obtaining a copy //Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal //of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights //in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is //copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions: //furnished to do so, subject to the following conditions:
// //
//The above copyright notice and this permission notice shall be included in all //The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software. //copies or substantial portions of the Software.
// //
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE. //SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// -----------------------------------------------------------------------</Expansion> // -----------------------------------------------------------------------</Expansion>
</Item> </Item>
</Items> </Items>
</Item> </Item>
<Item Id="{5d7e8673-3c4d-4f8c-98e5-96799d699c6b}" /> <Item Id="{5d7e8673-3c4d-4f8c-98e5-96799d699c6b}" />
<Item Id="{871cff6e-18a7-44e2-9980-cf75ac927e7d}" /> <Item Id="{871cff6e-18a7-44e2-9980-cf75ac927e7d}" />
<Item Id="{fc65f206-ebed-4567-b2ad-5da5fe2d5383}" /> <Item Id="{fc65f206-ebed-4567-b2ad-5da5fe2d5383}" />
<Item Id="{a4ca82b6-2912-47f4-bc3e-fa61fa152c64}" /> <Item Id="{a4ca82b6-2912-47f4-bc3e-fa61fa152c64}" />
<Item Id="{55344716-9e28-4e48-b69f-4ee8c28127cb}" /> <Item Id="{55344716-9e28-4e48-b69f-4ee8c28127cb}" />
<Item Id="{cf975a83-9d8e-420e-a655-27d52cf13c09}" /> <Item Id="{cf975a83-9d8e-420e-a655-27d52cf13c09}" />
<Item Id="{83aac52b-9b01-47e7-932a-8b56e8b86b10}" /> <Item Id="{83aac52b-9b01-47e7-932a-8b56e8b86b10}" />
<Item Id="{dc9f70e9-7053-45ed-90a6-e8257db37251}" /> <Item Id="{dc9f70e9-7053-45ed-90a6-e8257db37251}" />
<Item Id="{bfc86380-a990-47cc-9262-d6d644337e35}" /> <Item Id="{bfc86380-a990-47cc-9262-d6d644337e35}" />
<Item Id="{2830b620-b907-4390-8eda-c030402a9968}" /> <Item Id="{2830b620-b907-4390-8eda-c030402a9968}" />
<Item Id="{efc78e7d-fbe7-4a4f-a489-3ff6b881442b}" /> <Item Id="{efc78e7d-fbe7-4a4f-a489-3ff6b881442b}" />
<Item Id="{336f73d0-1064-4ced-99a4-a36400438379}" /> <Item Id="{336f73d0-1064-4ced-99a4-a36400438379}" />
<Item Id="{5babdc02-57e8-4854-82f7-9a9b97e48dad}" /> <Item Id="{5babdc02-57e8-4854-82f7-9a9b97e48dad}" />
<Item Id="{8f6f1bb6-a38a-4c81-ae9b-f77a8709a73d}" /> <Item Id="{8f6f1bb6-a38a-4c81-ae9b-f77a8709a73d}" />
<Item Id="{b0fb5608-05db-47c4-94b4-2bc7f72bc642}" /> <Item Id="{b0fb5608-05db-47c4-94b4-2bc7f72bc642}" />
<Item Id="{a43c547a-2d44-46eb-b39b-d39f7eb65a24}" /> <Item Id="{a43c547a-2d44-46eb-b39b-d39f7eb65a24}" />
<Item Id="{890dc8c3-dd34-489e-996a-4f3651f3e72a}" /> <Item Id="{890dc8c3-dd34-489e-996a-4f3651f3e72a}" />
<Item Id="{d420e166-39c2-4ea1-a7b2-36416f33de4f}" /> <Item Id="{d420e166-39c2-4ea1-a7b2-36416f33de4f}" />
<Item Id="{e4028d8a-d830-4882-b3ac-88e9913d996c}" /> <Item Id="{e4028d8a-d830-4882-b3ac-88e9913d996c}" />
<Item Id="{ed44f8f7-61d8-4932-ac14-6fb30ff55efb}" /> <Item Id="{ed44f8f7-61d8-4932-ac14-6fb30ff55efb}" />
<Item Id="{d7b9b3af-94a6-4c1b-92c8-8058d1d71f0e}" /> <Item Id="{d7b9b3af-94a6-4c1b-92c8-8058d1d71f0e}" />
<Item Id="{e91be916-8c04-4ebd-a9af-ddc38a046272}" /> <Item Id="{e91be916-8c04-4ebd-a9af-ddc38a046272}" />
<Item Id="{65b10956-7ae0-44ed-a376-6195f7e4d953}" /> <Item Id="{65b10956-7ae0-44ed-a376-6195f7e4d953}" />
</Templates> </Templates>
</Item> </Item>
<Item Id="{8e4132de-c894-486f-8004-e2d08d0ba979}" /> <Item Id="{8e4132de-c894-486f-8004-e2d08d0ba979}" />
<Item Id="{2433228d-3ae2-4022-aa52-7ab7a1a3116b}" /> <Item Id="{2433228d-3ae2-4022-aa52-7ab7a1a3116b}" />
<Item Id="{1379a9c1-e7a0-4872-87e5-24ef7c4a1315}" /> <Item Id="{1379a9c1-e7a0-4872-87e5-24ef7c4a1315}" />
<Item Id="{80783537-1b32-4a51-b716-b32036574f4f}" /> <Item Id="{80783537-1b32-4a51-b716-b32036574f4f}" />
<Item Id="{6b1c63bd-043f-4639-b757-a0c6132270fa}" /> <Item Id="{6b1c63bd-043f-4639-b757-a0c6132270fa}" />
<Item Id="{2ff95045-9084-4395-93a8-70d11cc8cdeb}" /> <Item Id="{2ff95045-9084-4395-93a8-70d11cc8cdeb}" />
<Item Id="{633d268e-6d35-46c7-ac5d-d2885ca35a0d}" /> <Item Id="{633d268e-6d35-46c7-ac5d-d2885ca35a0d}" />
<Item Id="{34b6c10a-ee60-4c30-9f5c-e0c033ce7867}" /> <Item Id="{34b6c10a-ee60-4c30-9f5c-e0c033ce7867}" />
<Item Id="{e63d4dbd-49ce-4fd6-ab9d-99e0bfc60b35}" /> <Item Id="{e63d4dbd-49ce-4fd6-ab9d-99e0bfc60b35}" />
<Item Id="{f4703284-a160-4272-be22-3366ade5e43f}" /> <Item Id="{f4703284-a160-4272-be22-3366ade5e43f}" />
<Item Id="{51f7a921-200c-43e3-944c-54521ed0c201}" /> <Item Id="{51f7a921-200c-43e3-944c-54521ed0c201}" />
<Item Id="{08077498-5ebe-4300-ad58-bcbf5a3ebac3}" /> <Item Id="{08077498-5ebe-4300-ad58-bcbf5a3ebac3}" />
<Item Id="{90ee1142-998a-40f3-8aa1-fe850f766551}" /> <Item Id="{90ee1142-998a-40f3-8aa1-fe850f766551}" />
<Item Id="{662a95d0-4d80-484b-b649-044f1464ff4a}" /> <Item Id="{662a95d0-4d80-484b-b649-044f1464ff4a}" />
<Item Id="{9c9bbf9d-c82c-450d-bafa-2d8b1f6a4a63}" /> <Item Id="{9c9bbf9d-c82c-450d-bafa-2d8b1f6a4a63}" />
<Item Id="{78fc30d9-aa85-4d78-a3f0-8eeb5a2e1496}" /> <Item Id="{78fc30d9-aa85-4d78-a3f0-8eeb5a2e1496}" />
<Item Id="{cb08e1a8-1829-4409-87e1-d9a9d3eea8a3}" /> <Item Id="{cb08e1a8-1829-4409-87e1-d9a9d3eea8a3}" />
<Item Id="{96418b0c-83d3-4656-90c9-59d4139e045c}" /> <Item Id="{96418b0c-83d3-4656-90c9-59d4139e045c}" />
<Item Id="{447c50a1-8ec8-44ee-9915-7f0548350093}" /> <Item Id="{447c50a1-8ec8-44ee-9915-7f0548350093}" />
<Item Id="{a641e756-107f-4e82-9952-010819e35abe}" /> <Item Id="{a641e756-107f-4e82-9952-010819e35abe}" />
<Item Id="{4cada8e9-90e0-4fe3-8171-91a3735d1447}" /> <Item Id="{4cada8e9-90e0-4fe3-8171-91a3735d1447}" />
<Item Id="{3888be66-16ab-4a3e-b416-144246345fa0}" /> <Item Id="{3888be66-16ab-4a3e-b416-144246345fa0}" />
<Item Id="{0158dfdd-6429-462c-931f-1a37959d3b42}" /> <Item Id="{0158dfdd-6429-462c-931f-1a37959d3b42}" />
<Item Id="{bf0539d1-191e-4764-b583-c95277cfa4bf}" /> <Item Id="{bf0539d1-191e-4764-b583-c95277cfa4bf}" />
</Categories> </Categories>
</RootCategory> </RootCategory>
</Options> </Options>
</Root> </Root>
+37 -37
View File
@@ -1,38 +1,38 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.Formatting.UI.Options.WrappingOptionsContainer"> <Root Type="DevExpress.CodeRush.Formatting.UI.Options.WrappingOptionsContainer">
<Options Language="C#"> <Options Language="C#">
<Options> <Options>
<Item Id="{48f3f6c0-b3c2-4567-b071-33af7480c9a3}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.QueryExpressionFormattingOption" /> <Item Id="{48f3f6c0-b3c2-4567-b071-33af7480c9a3}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.QueryExpressionFormattingOption" />
<Item Id="{a2c75ad7-ba6a-49ca-8070-6d9e3c52e3c6}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BinaryExpressionFormattingOption" /> <Item Id="{a2c75ad7-ba6a-49ca-8070-6d9e3c52e3c6}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BinaryExpressionFormattingOption" />
<Item Id="{0e2d0391-24ba-4ed8-aeb4-1b3e9f26be55}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.RelationalExpressionFormattingOption" /> <Item Id="{0e2d0391-24ba-4ed8-aeb4-1b3e9f26be55}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.RelationalExpressionFormattingOption" />
<Item Id="{fea50ebc-99c9-4599-9b55-bf2961b9cc95}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BitwiseExpressionFormattingOption" /> <Item Id="{fea50ebc-99c9-4599-9b55-bf2961b9cc95}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BitwiseExpressionFormattingOption" />
<Item Id="{4246b900-cbb3-44f4-b59e-b3055fb4f7bc}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.LogicalExpressionFormattingOption" /> <Item Id="{4246b900-cbb3-44f4-b59e-b3055fb4f7bc}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.LogicalExpressionFormattingOption" />
<Item Id="{cd721fc1-23fb-4d88-a9f0-42d6b318a32b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.TernaryExpressionFormattingOption" /> <Item Id="{cd721fc1-23fb-4d88-a9f0-42d6b318a32b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.TernaryExpressionFormattingOption" />
<Item Id="{10e904ea-f51d-4c32-9320-1b93fa557564}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.AssignmentExpressionFormattingOption" /> <Item Id="{10e904ea-f51d-4c32-9320-1b93fa557564}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.AssignmentExpressionFormattingOption" />
<Item Id="{25746bdc-0a43-4741-a740-20784691314b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.InvocationArgumentListFormattingOption"> <Item Id="{25746bdc-0a43-4741-a740-20784691314b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.InvocationArgumentListFormattingOption">
<WrapOpenParen> <WrapOpenParen>
<Option>NoWrap</Option> <Option>NoWrap</Option>
</WrapOpenParen> </WrapOpenParen>
<WrapArgSeparator> <WrapArgSeparator>
<Option>SimpleWrap</Option> <Option>SimpleWrap</Option>
<Kind>WrapAfter</Kind> <Kind>WrapAfter</Kind>
</WrapArgSeparator> </WrapArgSeparator>
<ArgCountTolerance>4</ArgCountTolerance> <ArgCountTolerance>4</ArgCountTolerance>
</Item> </Item>
<Item Id="{D5EE2ECB-9FA6-47F7-A11F-007FC45E872D}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.AttributeArgumentsFormattingOption" /> <Item Id="{D5EE2ECB-9FA6-47F7-A11F-007FC45E872D}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.AttributeArgumentsFormattingOption" />
<Item Id="{5A186AB9-03A5-4BFE-83B1-B99B3B8408BC}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.DeclarationParameterListFormattingOption" /> <Item Id="{5A186AB9-03A5-4BFE-83B1-B99B3B8408BC}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.DeclarationParameterListFormattingOption" />
<Item Id="{8739877d-3674-40ae-90c4-38b2b160e92b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ArrayInitializerFormattingOption" /> <Item Id="{8739877d-3674-40ae-90c4-38b2b160e92b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ArrayInitializerFormattingOption" />
<Item Id="{a940ae15-f98a-4b7d-8357-2214eb421250}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CollectionInitializerFormattingOption" /> <Item Id="{a940ae15-f98a-4b7d-8357-2214eb421250}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CollectionInitializerFormattingOption" />
<Item Id="{0414181a-3915-4d0c-81d3-3bc7718da90f}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ObjectInitializerFormattingOption" /> <Item Id="{0414181a-3915-4d0c-81d3-3bc7718da90f}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ObjectInitializerFormattingOption" />
<Item Id="{ea60e2ab-d67a-45e8-ab42-36d747c494c}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ChainedMethodCallsFormattingOption" /> <Item Id="{ea60e2ab-d67a-45e8-ab42-36d747c494c}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ChainedMethodCallsFormattingOption" />
<Item Id="{5f4ed422-88b9-4e95-8401-cef404d645d6}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.LambdaExpressionFormattingOption" /> <Item Id="{5f4ed422-88b9-4e95-8401-cef404d645d6}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.LambdaExpressionFormattingOption" />
<Item Id="{0531de5e-ff20-4043-a67c-eeef76a8f3c3}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ArrowExpressionFormattingOption" /> <Item Id="{0531de5e-ff20-4043-a67c-eeef76a8f3c3}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ArrowExpressionFormattingOption" />
<Item Id="{08fa5953-cc71-4ded-bd41-ef5d5b690585}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.TypeParameterListFormattingOption" /> <Item Id="{08fa5953-cc71-4ded-bd41-ef5d5b690585}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.TypeParameterListFormattingOption" />
<Item Id="{dc060d33-cfc0-411e-9508-8d27b84934e8}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CoalesceExpressionFormattingOption" /> <Item Id="{dc060d33-cfc0-411e-9508-8d27b84934e8}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CoalesceExpressionFormattingOption" />
<Item Id="{b25d25a0-dd92-45ed-88ef-51953e28222c}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BaseListWrappingFormattingOption" /> <Item Id="{b25d25a0-dd92-45ed-88ef-51953e28222c}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BaseListWrappingFormattingOption" />
<Item Id="{4db5e14f-8f4c-416f-9b59-7e9239f2150e}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CtorInitWrappingFormattingOption" /> <Item Id="{4db5e14f-8f4c-416f-9b59-7e9239f2150e}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CtorInitWrappingFormattingOption" />
<Item Id="{be0c2117-5732-40fd-9b4a-0fe749356e87}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.SwitchExpressionWrappingFormattingOption" /> <Item Id="{be0c2117-5732-40fd-9b4a-0fe749356e87}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.SwitchExpressionWrappingFormattingOption" />
<Item Id="{099d9359-1af3-40a2-8841-50f6cc9527e1}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CollectionExpressionWrappingFormattingOption" /> <Item Id="{099d9359-1af3-40a2-8841-50f6cc9527e1}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CollectionExpressionWrappingFormattingOption" />
</Options> </Options>
</Options> </Options>
</Root> </Root>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Root Type="DevExpress.CodeRush.VisualizePlugins.RightMarginLine.Options.RightMarginLineOptions"> <Root Type="DevExpress.CodeRush.VisualizePlugins.RightMarginLine.Options.RightMarginLineOptions">
<Options Language="Neutral"> <Options Language="Neutral">
<Column>120</Column> <Column>120</Column>
</Options> </Options>
</Root> </Root>
+116 -116
View File
@@ -1,117 +1,117 @@
[*.cs] [*.cs]
# CS1591: 缺少对公共可见类型或成员的 XML 注释 # CS1591: 缺少对公共可见类型或成员的 XML 注释
dotnet_diagnostic.CS1591.severity = suggestion dotnet_diagnostic.CS1591.severity = suggestion
[*.cs] [*.cs]
#### 命名样式 #### #### 命名样式 ####
# 命名规则 # 命名规则
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
# 符号规范 # 符号规范
dotnet_naming_symbols.interface.applicable_kinds = interface dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers = dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers = dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers = dotnet_naming_symbols.non_field_members.required_modifiers =
# 命名样式 # 命名样式
dotnet_naming_style.begins_with_i.required_prefix = I dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix = dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator = dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case dotnet_naming_style.begins_with_i.capitalization = pascal_case
dotnet_naming_style.pascal_case.required_prefix = dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix = dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator = dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_style.pascal_case.required_prefix = dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix = dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator = dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case dotnet_naming_style.pascal_case.capitalization = pascal_case
csharp_using_directive_placement = outside_namespace:silent csharp_using_directive_placement = outside_namespace:silent
csharp_style_expression_bodied_methods = false:silent csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent csharp_style_expression_bodied_local_functions = false:silent
csharp_style_conditional_delegate_call = true:suggestion csharp_style_conditional_delegate_call = true:suggestion
csharp_style_var_for_built_in_types = false:silent csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = false:silent csharp_style_var_elsewhere = false:silent
csharp_prefer_simple_using_statement = false:suggestion csharp_prefer_simple_using_statement = false:suggestion
csharp_prefer_braces = true:silent csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = false:silent csharp_style_prefer_top_level_statements = false:silent
csharp_style_prefer_primary_constructors = true:suggestion csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_static_local_function = true:suggestion csharp_prefer_static_local_function = true:suggestion
csharp_prefer_static_anonymous_function = true:suggestion csharp_prefer_static_anonymous_function = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion csharp_style_prefer_readonly_struct = true:suggestion
csharp_space_around_binary_operators = before_and_after csharp_space_around_binary_operators = before_and_after
csharp_indent_labels = one_less_than_current csharp_indent_labels = one_less_than_current
[*.vb] [*.vb]
#### 命名样式 #### #### 命名样式 ####
# 命名规则 # 命名规则
dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion
dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface
dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始 dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始
dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion
dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型 dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型
dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法 dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法
dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion
dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员 dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员
dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法 dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法
# 符号规范 # 符号规范
dotnet_naming_symbols.interface.applicable_kinds = interface dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.interface.required_modifiers = dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.类型.required_modifiers = dotnet_naming_symbols.类型.required_modifiers =
dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method
dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.非字段成员.required_modifiers = dotnet_naming_symbols.非字段成员.required_modifiers =
# 命名样式 # 命名样式
dotnet_naming_style.以_i_开始.required_prefix = I dotnet_naming_style.以_i_开始.required_prefix = I
dotnet_naming_style.以_i_开始.required_suffix = dotnet_naming_style.以_i_开始.required_suffix =
dotnet_naming_style.以_i_开始.word_separator = dotnet_naming_style.以_i_开始.word_separator =
dotnet_naming_style.以_i_开始.capitalization = pascal_case dotnet_naming_style.以_i_开始.capitalization = pascal_case
dotnet_naming_style.帕斯卡拼写法.required_prefix = dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotenv dotenv
+2 -2
View File
@@ -1,3 +1,3 @@
{ {
"help":"https://go.microsoft.com/fwlink/?linkid=866610" "help":"https://go.microsoft.com/fwlink/?linkid=866610"
} }
+13 -13
View File
@@ -1,13 +1,13 @@
/build /build
/.idea /.idea
/.vs /.vs
/.vscode /.vscode
*/obj */obj
*/bin */bin
*/build */build
*/Debug */Debug
*/Release */Release
/TestResults /TestResults
*/x64 */x64
*/.vs */.vs
/StgSharp.Native/lib /StgSharp.Native/lib
+37 -37
View File
@@ -1,37 +1,37 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.14.36705.20 VisualStudioVersion = 17.14.36705.20
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenerateGL", "StgSharp.GenerateGL\GenerateGL.csproj", "{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenerateGL", "StgSharp.GenerateGL\GenerateGL.csproj", "{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StgSharp.Common", "StgSharp.Common\StgSharp.Common.csproj", "{5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StgSharp.Common", "StgSharp.Common\StgSharp.Common.csproj", "{5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64 Release|x64 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Debug|Any CPU.Build.0 = Debug|Any CPU {9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Debug|x64.ActiveCfg = Debug|x64 {9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Debug|x64.ActiveCfg = Debug|x64
{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Debug|x64.Build.0 = Debug|x64 {9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Debug|x64.Build.0 = Debug|x64
{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Release|Any CPU.ActiveCfg = Release|Any CPU {9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Release|Any CPU.Build.0 = Release|Any CPU {9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Release|Any CPU.Build.0 = Release|Any CPU
{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Release|x64.ActiveCfg = Release|x64 {9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Release|x64.ActiveCfg = Release|x64
{9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Release|x64.Build.0 = Release|x64 {9FD27EE6-E94D-4E64-A13B-5A349DEA215A}.Release|x64.Build.0 = Release|x64
{5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}.Debug|Any CPU.ActiveCfg = Debug|x64 {5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}.Debug|Any CPU.ActiveCfg = Debug|x64
{5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}.Debug|x64.ActiveCfg = Debug|x64 {5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}.Debug|x64.ActiveCfg = Debug|x64
{5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}.Release|Any CPU.ActiveCfg = Release|x64 {5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}.Release|Any CPU.ActiveCfg = Release|x64
{5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}.Release|x64.ActiveCfg = Release|x64 {5D646C0E-CCF8-B5B4-7DE8-1C37542E7B4D}.Release|x64.ActiveCfg = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AC71C01F-9867-4E43-85AB-4A8A7896B1BC} SolutionGuid = {AC71C01F-9867-4E43-85AB-4A8A7896B1BC}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
+155 -155
View File
@@ -1,155 +1,155 @@
MIT License MIT License
Copyright (c) 2024 Nitload StgSharp Team Copyright (c) 2024 Nitload StgSharp Team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
StgSharp program uses the following open source projects, StgSharp program uses the following open source projects,
I'd like to refer to them here and show my sincere appreciation, I'd like to refer to them here and show my sincere appreciation,
while the names are sorted in no particular order while the names are sorted in no particular order
1. GLFW 1. GLFW
Remote repository on: https://www.glfw.org/ Remote repository on: https://www.glfw.org/
License of GLFW: License of GLFW:
Copyright (c) 2002-2006 Marcus Geelnard Copyright (c) 2002-2006 Marcus Geelnard
Copyright (c) 2006-2019 Camilla Löwy Copyright (c) 2006-2019 Camilla Löwy
This software is provided 'as-is', This software is provided 'as-is',
without any express or implied warranty. without any express or implied warranty.
In no event will the authors be held liable for In no event will the authors be held liable for
any damages arising from the use of this software. any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: subject to the following restrictions:
The origin of this software must not be misrepresented; The origin of this software must not be misrepresented;
you must not claim that you wrote the original software. you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required. in the product documentation would be appreciated but is not required.
Altered source versions must be plainly marked as such, Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software. and must not be misrepresented as being the original software.
This notice may not be removed or altered from any source distribution. This notice may not be removed or altered from any source distribution.
2. GLAD, Khronos Specifications and other Specification headers 2. GLAD, Khronos Specifications and other Specification headers
Web service available on https://gen.glad.sh/ Web service available on https://gen.glad.sh/
The glad source code: The glad source code:
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2013-2022 David Herberth Copyright (c) 2013-2022 David Herberth
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so, the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The Khronos Specifications: The Khronos Specifications:
Copyright (c) 2013-2020 The Khronos Group Inc. Copyright (c) 2013-2020 The Khronos Group Inc.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
3. docs.gl 3. docs.gl
4. Terminal.GUI 4. Terminal.GUI
Remote repository on: https://github.com/gui-cs/Terminal.Gui Remote repository on: https://github.com/gui-cs/Terminal.Gui
License of Terminal.GUI: License of Terminal.GUI:
Copyright 2007-2011 Novell Inc Copyright 2007-2011 Novell Inc
Copyright 2017 Microsoft Corp Copyright 2017 Microsoft Corp
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software. included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5. IxMilia.Step 5. IxMilia.Step
License of IxMilia.Step: License of IxMilia.Step:
The MIT License (MIT) The MIT License (MIT)
Copyright (c) IxMilia. Copyright (c) IxMilia.
All rights reserved. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
+236 -236
View File
@@ -1,237 +1,237 @@
# StgSharp # StgSharp
![StgSharp Logo](STG%23LOGO.png) ![StgSharp Logo](STG%23LOGO.png)
StgSharp is a modern C# framework that combines game engine capabilities with high-performance computing features. Originally designed as a next-generation STG (Shoot 'em Up) game engine, it has evolved to include advanced mathematical libraries, parallel computing capabilities, and comprehensive graphics APIs. StgSharp is a modern C# framework that combines game engine capabilities with high-performance computing features. Originally designed as a next-generation STG (Shoot 'em Up) game engine, it has evolved to include advanced mathematical libraries, parallel computing capabilities, and comprehensive graphics APIs.
## Overview ## Overview
StgSharp provides both low-level and high-level bindings to OpenGL, multimedia control, and device management, offering everything needed to create STG games and high-performance applications. The framework is built on .NET 8 and supports Windows and Linux platforms. StgSharp provides both low-level and high-level bindings to OpenGL, multimedia control, and device management, offering everything needed to create STG games and high-performance applications. The framework is built on .NET 8 and supports Windows and Linux platforms.
## Core Modules ## Core Modules
### StgSharp.Common ### StgSharp.Common
The foundational library containing shared functionality: The foundational library containing shared functionality:
- **Mathematics**: High-performance linear algebra, matrix operations, and mathematical utilities - **Mathematics**: High-performance linear algebra, matrix operations, and mathematical utilities
- **Graphics**: OpenGL bindings, rendering pipeline, and graphics framework - **Graphics**: OpenGL bindings, rendering pipeline, and graphics framework
- **High Performance**: SIMD operations, memory management, and parallel computing - **High Performance**: SIMD operations, memory management, and parallel computing
- **Collections**: Specialized data structures and containers - **Collections**: Specialized data structures and containers
- **MVVM**: Model-View-ViewModel framework for UI applications - **MVVM**: Model-View-ViewModel framework for UI applications
- **Entities**: Game entity system and behavior management - **Entities**: Game entity system and behavior management
- **Environment**: Platform abstraction and system integration - **Environment**: Platform abstraction and system integration
### StgSharp.Mathematics (Numeric) ### StgSharp.Mathematics (Numeric)
Numerics and linear algebra built on top of the core library: Numerics and linear algebra built on top of the core library:
- **Matrix & Vector Types**: High-performance math primitives - **Matrix & Vector Types**: High-performance math primitives
- **Numeric Utilities**: Core numeric helpers and algorithms - **Numeric Utilities**: Core numeric helpers and algorithms
- **SIMD-Friendly Kernels**: Data layouts optimized for hardware acceleration - **SIMD-Friendly Kernels**: Data layouts optimized for hardware acceleration
### StgSharp.RegularAnalysis ### StgSharp.RegularAnalysis
Regular-language and parsing infrastructure (replaces the former Script module): Regular-language and parsing infrastructure (replaces the former Script module):
- **Regex/Automata Core**: Regular expression processing and automata utilities - **Regex/Automata Core**: Regular expression processing and automata utilities
- **Parsing Primitives**: Reusable tokenizer and grammar building blocks - **Parsing Primitives**: Reusable tokenizer and grammar building blocks
- **Analysis Pipeline**: Structured processing for language-like inputs - **Analysis Pipeline**: Structured processing for language-like inputs
### StgSharp.Native ### StgSharp.Native
Native library integration: Native library integration:
- **GLFW Integration**: Cross-platform window and input management - **GLFW Integration**: Cross-platform window and input management
- **SIMD Operations**: Hardware-accelerated vector operations - **SIMD Operations**: Hardware-accelerated vector operations
- **Matrix Kernels**: Optimized matrix computation routines - **Matrix Kernels**: Optimized matrix computation routines
- **Context Management**: Graphics context and resource management - **Context Management**: Graphics context and resource management
### StgSharp.Device ### StgSharp.Device
Low-level device and port abstractions: Low-level device and port abstractions:
- **Command Interfaces**: Command shapes and serialization contracts - **Command Interfaces**: Command shapes and serialization contracts
- **Port Control**: Stream-oriented device access - **Port Control**: Stream-oriented device access
- **Decoder/Response Models**: Protocol-level data handling - **Decoder/Response Models**: Protocol-level data handling
### StgSharp.TerminalDialogue ### StgSharp.TerminalDialogue
Terminal-based user interface application and components: Terminal-based user interface application and components:
- **Interactive Terminal**: Command-line UI components - **Interactive Terminal**: Command-line UI components
- **Dialogue System**: User interaction and input handling - **Dialogue System**: User interaction and input handling
- **Terminal Graphics**: Text-based UI rendering - **Terminal Graphics**: Text-based UI rendering
> Note: The legacy Script module has been superseded by RegularAnalysis. The Model module is under refactoring and is currently out of the core framework. > Note: The legacy Script module has been superseded by RegularAnalysis. The Model module is under refactoring and is currently out of the core framework.
## Key Features ## Key Features
### High-Performance Computing ### High-Performance Computing
- **Parallel Matrix Operations**: Multi-threaded matrix computations with optimized scheduling - **Parallel Matrix Operations**: Multi-threaded matrix computations with optimized scheduling
- **SIMD Acceleration**: Hardware-optimized vector operations - **SIMD Acceleration**: Hardware-optimized vector operations
- **Memory Management**: Custom allocators including HLSF (Hybrid Layer Segregated Fit) - **Memory Management**: Custom allocators including HLSF (Hybrid Layer Segregated Fit)
- **Thread Pool Management**: Efficient task scheduling and execution - **Thread Pool Management**: Efficient task scheduling and execution
#### HLSF Benchmark Snapshot (BenchmarkDotNet) #### HLSF Benchmark Snapshot (BenchmarkDotNet)
``` ```
BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.7623) BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.7623)
AMD Ryzen 7 6800H with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores AMD Ryzen 7 6800H with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK 10.0.102 .NET SDK 10.0.102
[Host] : .NET 8.0.23 (8.0.2325.60607), X64 RyuJIT AVX2 [Host] : .NET 8.0.23 (8.0.2325.60607), X64 RyuJIT AVX2
Toolchain=InProcessEmitToolchain InvocationCount=2048 UnrollFactor=1 Toolchain=InProcessEmitToolchain InvocationCount=2048 UnrollFactor=1
``` ```
| Method | Mean | Error | StdDev | Ratio | RatioSD | | Method | Mean | Error | StdDev | Ratio | RatioSD |
|------- |-----:|-----:|------:|------:|-------:| |------- |-----:|-----:|------:|------:|-------:|
| Hlsf | 76.23 µs | 0.355 µs | 0.315 µs | 0.44 | 0.01 | | Hlsf | 76.23 µs | 0.355 µs | 0.315 µs | 0.44 | 0.01 |
| Libc | 172.98 µs | 3.042 µs | 2.988 µs | 1.00 | 0.02 | | Libc | 172.98 µs | 3.042 µs | 2.988 µs | 1.00 | 0.02 |
This run shows HLSF significantly faster than libc under the current configuration. See the HLSF document for details and caveats. This run shows HLSF significantly faster than libc under the current configuration. See the HLSF document for details and caveats.
### Graphics and Rendering ### Graphics and Rendering
- **OpenGL Integration**: Complete OpenGL API coverage - **OpenGL Integration**: Complete OpenGL API coverage
- **Cross-Platform Support**: Windows and Linux compatibility - **Cross-Platform Support**: Windows and Linux compatibility
- **Rendering Pipeline**: Flexible and extensible graphics framework - **Rendering Pipeline**: Flexible and extensible graphics framework
- **Shader Management**: Dynamic shader compilation and management - **Shader Management**: Dynamic shader compilation and management
### Game Engine Capabilities ### Game Engine Capabilities
- **Entity System**: Flexible game object management - **Entity System**: Flexible game object management
- **State Machine**: Game state and behavior management - **State Machine**: Game state and behavior management
- **Input Handling**: Comprehensive input and control systems - **Input Handling**: Comprehensive input and control systems
- **Resource Management**: Efficient asset loading and management - **Resource Management**: Efficient asset loading and management
### Data Processing ### Data Processing
- **STEP File Support**: Industrial data format processing - **STEP File Support**: Industrial data format processing
- **EXPRESS Language**: Domain-specific language compilation - **EXPRESS Language**: Domain-specific language compilation
- **Pipeline Processing**: Efficient data transformation workflows - **Pipeline Processing**: Efficient data transformation workflows
## Requirements ## Requirements
- .NET 8.0 or later - .NET 8.0 or later
- Windows 10/11 or Linux - Windows 10/11 or Linux
- x64 or ARM64 architecture - x64 or ARM64 architecture
- OpenGL 3.3+ support - OpenGL 3.3+ support
## Installation ## Installation
StgSharp is currently in development and requires compilation from source. **NuGet packages are not yet available** - you must build the project from source code. StgSharp is currently in development and requires compilation from source. **NuGet packages are not yet available** - you must build the project from source code.
### Prerequisites ### Prerequisites
- **Windows**: Visual Studio 2022 or later with C++ development tools - **Windows**: Visual Studio 2022 or later with C++ development tools
- **Linux**: CMake and compatible C++ compiler (planned support) - **Linux**: CMake and compatible C++ compiler (planned support)
- .NET 8.0 SDK or later - .NET 8.0 SDK or later
- Git for source code retrieval - Git for source code retrieval
### Building from Source ### Building from Source
1. **Clone the repository**: 1. **Clone the repository**:
```bash ```bash
git clone https://github.com/Nitload-NSI/StgSharp.git git clone https://github.com/Nitload-NSI/StgSharp.git
cd StgSharp cd StgSharp
``` ```
2. **Windows (Recommended)**: 2. **Windows (Recommended)**:
- Open `StgSharp.sln` in Visual Studio - Open `StgSharp.sln` in Visual Studio
- Build the solution (Debug or Release configuration) - Build the solution (Debug or Release configuration)
- The native components will be automatically compiled - The native components will be automatically compiled
3. **Linux (Experimental)**: 3. **Linux (Experimental)**:
```bash ```bash
# Build .NET components only # Build .NET components only
# Note: Native components are not yet supported on Linux # Note: Native components are not yet supported on Linux
dotnet build dotnet build
``` ```
### Build Configuration ### Build Configuration
- **Debug**: Full debugging symbols, unoptimized - **Debug**: Full debugging symbols, unoptimized
- **Release**: Optimized for performance - **Release**: Optimized for performance
### Notes ### Notes
- Windows compilation with Visual Studio is fully supported and tested - Windows compilation with Visual Studio is fully supported and tested
- Linux support is experimental and limited to .NET components only - Linux support is experimental and limited to .NET components only
- Native components (StgSharp.Native) are currently Windows-only and require MSVC - Native components (StgSharp.Native) are currently Windows-only and require MSVC
- CMake support for native components is not yet implemented - CMake support for native components is not yet implemented
- Some features may not be available on all platforms - Some features may not be available on all platforms
## Quick Start ## Quick Start
### Basic Graphics Application ### Basic Graphics Application
```csharp ```csharp
/*To be implemented*/ /*To be implemented*/
``` ```
### Matrix Operations ### Matrix Operations
```csharp ```csharp
using StgSharp.Mathematics; using StgSharp.Mathematics;
// Create matrices // Create matrices
var matrixA = Matrix<float>.Create(4, 4); var matrixA = Matrix<float>.Create(4, 4);
var matrixB = Matrix<float>.Create(4, 4); var matrixB = Matrix<float>.Create(4, 4);
// Perform parallel matrix multiplication // Perform parallel matrix multiplication
var result = matrixA * matrixB; var result = matrixA * matrixB;
``` ```
### Memory Management ### Memory Management
```csharp ```csharp
using StgSharp.HighPerformance.Memory; using StgSharp.HighPerformance.Memory;
// Create high-performance allocator // Create high-performance allocator
using var allocator = new HybridLayerSegregatedFitAllocator(64 * 1024 * 1024); using var allocator = new HybridLayerSegregatedFitAllocator(64 * 1024 * 1024);
// Allocate memory // Allocate memory
var handle = allocator.Alloc(1024); var handle = allocator.Alloc(1024);
// Use allocated memory // Use allocated memory
allocator.Free(handle); allocator.Free(handle);
``` ```
## Documentation ## Documentation
### Technical Documentation ### Technical Documentation
- [HLSF Allocator](StgSharp.Common/HighPerformance/Memory/InroductionToHLSF.md) - High-performance memory allocator documentation - [HLSF Allocator](StgSharp.Common/HighPerformance/Memory/InroductionToHLSF.md) - High-performance memory allocator documentation
- [Native Library Naming](StgSharp.Native/naming.md) - Native library file naming conventions - [Native Library Naming](StgSharp.Native/naming.md) - Native library file naming conventions
## Contributing ## Contributing
StgSharp is developed by Nitload Space. Contributions are welcome, particularly in: StgSharp is developed by Nitload Space. Contributions are welcome, particularly in:
- Performance optimizations - Performance optimizations
- Cross-platform compatibility - Cross-platform compatibility
- Documentation improvements - Documentation improvements
- New feature implementations - New feature implementations
## License ## License
StgSharp is licensed under the MIT License. See [LICENSE](LICENSE) for details. StgSharp is licensed under the MIT License. See [LICENSE](LICENSE) for details.
## Future Plans ## Future Plans
- **Vulkan Support**: Planned for version 2.0 - **Vulkan Support**: Planned for version 2.0
- **Enhanced Cross-Platform**: Improved Linux and mobile support - **Enhanced Cross-Platform**: Improved Linux and mobile support
- **Performance Optimizations**: Further SIMD and parallel processing improvements - **Performance Optimizations**: Further SIMD and parallel processing improvements
- **Extended Language Support**: Additional domain-specific languages - **Extended Language Support**: Additional domain-specific languages
## Support ## Support
For questions, issues, or contributions, please refer to the project repository or contact the development team. For questions, issues, or contributions, please refer to the project repository or contact the development team.
+36 -36
View File
@@ -1,36 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>preview</LangVersion> <LangVersion>preview</LangVersion>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject> <IsTestProject>true</IsTestProject>
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" /> <PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.MSTest" Version="1.1.2" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.MSTest" Version="1.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> <PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> <PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\StgSharp.Common\StgSharp.Common.csproj" /> <ProjectReference Include="..\StgSharp.Common\StgSharp.Common.csproj" />
<ProjectReference Include="..\StgSharp.Model\StgSharp.Model.csproj" /> <ProjectReference Include="..\StgSharp.Model\StgSharp.Model.csproj" />
<ProjectReference Include="..\StgSharp.Script\StgSharp.Script.csproj" /> <ProjectReference Include="..\StgSharp.Script\StgSharp.Script.csproj" />
<ProjectReference Include="..\StgSharp.TerminalDialogue\StgSharp.TerminalDialogue.csproj" /> <ProjectReference Include="..\StgSharp.TerminalDialogue\StgSharp.TerminalDialogue.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy /E /I /Y $(SolutionDir)build $(OutDir)" /> <Exec Command="xcopy /E /I /Y $(SolutionDir)build $(OutDir)" />
</Target> </Target>
</Project> </Project>
+117 -117
View File
@@ -1,118 +1,118 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// file="UnitTest1.cs" // file="UnitTest1.cs"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload Space // AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the ¡°Software¡±), to deal in the Software without restriction, // files (the ¡°Software¡±), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, // including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, // publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so, // and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions: // subject to the following conditions:
// //
// The above copyright notice and // The above copyright notice and
// this permission notice shall be included in all copies // this permission notice shall be included in all copies
// or substantial portions of the Software. // or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED ¡°AS IS¡±, // THE SOFTWARE IS PROVIDED ¡°AS IS¡±,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH // ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
using StgSharp; using StgSharp;
using StgSharp.Collections; using StgSharp.Collections;
using StgSharp.Script; using StgSharp.Script;
using StgSharp.Script.Express; using StgSharp.Script.Express;
//using StgSharp.Model; //using StgSharp.Model;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace STgSharpTest namespace STgSharpTest
{ {
[TestClass] [TestClass]
public class UnitTest1 public class UnitTest1
{ {
string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp"; string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
[TestMethod] [TestMethod]
public void RegexTest() public void RegexTest()
{ {
string sample = "FILE_DESCRIPTION(('CATIA V5 STEP Exchange'),'2;1');"; string sample = "FILE_DESCRIPTION(('CATIA V5 STEP Exchange'),'2;1');";
foreach( var match in Regex.Match( foreach( var match in Regex.Match(
sample, @"^(?<CALLER>[A-Z_]+)\s?\((?<PARAM>.+)\)\;" ) sample, @"^(?<CALLER>[A-Z_]+)\s?\((?<PARAM>.+)\)\;" )
.Groups ) { .Groups ) {
Console.WriteLine( $"{match.ToString()}" ); Console.WriteLine( $"{match.ToString()}" );
Console.WriteLine( "\t\t\t" ); Console.WriteLine( "\t\t\t" );
} }
} }
[TestMethod] [TestMethod]
public void TestSource() public void TestSource()
{ {
ScriptSourceTransmitter st = new ScriptSourceTransmitter("end", 0); ScriptSourceTransmitter st = new ScriptSourceTransmitter("end", 0);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
st.WriteLine($"Code{i} {new string(' ', i + 1)}-- Comment{i}"); st.WriteLine($"Code{i} {new string(' ', i + 1)}-- Comment{i}");
} }
st.WriteLine("Code (* comment"); st.WriteLine("Code (* comment");
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
st.WriteLine($"comment-code"); st.WriteLine($"comment-code");
} }
st.WriteLine($"comment *) code"); st.WriteLine($"comment *) code");
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
st.WriteLine($" Code{i} (* (* Comment *) *) Code{i}"); st.WriteLine($" Code{i} (* (* Comment *) *) Code{i}");
} }
st.WriteLine("end"); st.WriteLine("end");
ExpSourceReader reader = new ExpSourceReader(st); ExpSourceReader reader = new ExpSourceReader(st);
while (!st.IsEmpty) while (!st.IsEmpty)
{ {
Console.WriteLine(new string(reader.ReadLine())); Console.WriteLine(new string(reader.ReadLine()));
} }
} }
[TestMethod] [TestMethod]
public void TestMethod() public void TestMethod()
{ {
ScriptSourceTransmitter st = new ScriptSourceTransmitter("end", 0); ScriptSourceTransmitter st = new ScriptSourceTransmitter("end", 0);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
st.WriteLine($"Code{i} {new string(' ',i+1)}-- Comment{i}"); st.WriteLine($"Code{i} {new string(' ',i+1)}-- Comment{i}");
} }
st.WriteLine("Code (* comment"); st.WriteLine("Code (* comment");
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
st.WriteLine($"comment-code"); st.WriteLine($"comment-code");
} }
st.WriteLine($"comment *) code"); st.WriteLine($"comment *) code");
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
st.WriteLine($" Code{i} (* (* Comment *) *) Code{i}"); st.WriteLine($" Code{i} (* (* Comment *) *) Code{i}");
} }
st.WriteLine("end"); st.WriteLine("end");
ExpSourceReader reader = new ExpSourceReader(st); ExpSourceReader reader = new ExpSourceReader(st);
while (!st.IsEmpty) while (!st.IsEmpty)
{ {
Console.WriteLine(reader.ReadToken().Value.ToString()); Console.WriteLine(reader.ReadToken().Value.ToString());
} }
} }
} }
} }
+153 -153
View File
@@ -1,153 +1,153 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="HlsfAllocatorBench" // file="HlsfAllocatorBench"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using StgSharp.HighPerformance.Memory; using StgSharp.HighPerformance.Memory;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace StgSharp.Benchmark namespace StgSharp.Benchmark
{ {
[MemoryDiagnoser] [MemoryDiagnoser]
[InvocationCount(2048)] [InvocationCount(2048)]
public class HlsfAllocatorBench public class HlsfAllocatorBench
{ {
private const uint Alignment = 64; private const uint Alignment = 64;
private const int AllocationCount = 2048; private const int AllocationCount = 2048;
private static readonly int[] AllocSizes = [ private static readonly int[] AllocSizes = [
64, 64,
96, 96,
150, 150,
200, 200,
400, 400,
1024, 1024,
4096 4096
]; ];
private HybridLayerSegregatedFitAllocator _hlsfAllocator = null!; private HybridLayerSegregatedFitAllocator _hlsfAllocator = null!;
private readonly List<HybridLayerSegregatedFitAllocationHandle> _hlsfLocalList = new(); private readonly List<HybridLayerSegregatedFitAllocationHandle> _hlsfLocalList = new();
private readonly List<nint> _libcLocalList = new(); private readonly List<nint> _libcLocalList = new();
private Random _random = new(42); private Random _random = new(42);
[GlobalCleanup] [GlobalCleanup]
public void Cleanup() public void Cleanup()
{ {
_hlsfAllocator?.Dispose(); _hlsfAllocator?.Dispose();
_hlsfLocalList.Clear(); _hlsfLocalList.Clear();
_hlsfLocalList.TrimExcess(); _hlsfLocalList.TrimExcess();
_libcLocalList.Clear(); _libcLocalList.Clear();
_libcLocalList.TrimExcess(); _libcLocalList.TrimExcess();
} }
[Benchmark] [Benchmark]
public void Hlsf() public void Hlsf()
{ {
RunHlsf(_hlsfAllocator, FreePolicy.NoCollect); RunHlsf(_hlsfAllocator, FreePolicy.NoCollect);
} }
[IterationSetup] [IterationSetup]
public void IterationSetup() public void IterationSetup()
{ {
_hlsfLocalList.Clear(); _hlsfLocalList.Clear();
_libcLocalList.Clear(); _libcLocalList.Clear();
} }
[Benchmark(Baseline = true)] [Benchmark(Baseline = true)]
public unsafe void Libc() public unsafe void Libc()
{ {
_libcLocalList.Clear(); _libcLocalList.Clear();
for (int i = 0; i < AllocationCount; i++) for (int i = 0; i < AllocationCount; i++)
{ {
uint size = AlignSize(GetNextRandomSize()); uint size = AlignSize(GetNextRandomSize());
void* allocate = NativeMemory.AlignedAlloc(size, Alignment); void* allocate = NativeMemory.AlignedAlloc(size, Alignment);
if (allocate == null) { if (allocate == null) {
throw new OutOfMemoryException("NativeMemory.AlignedAlloc returned null."); throw new OutOfMemoryException("NativeMemory.AlignedAlloc returned null.");
} }
_libcLocalList.Add((nint)allocate); _libcLocalList.Add((nint)allocate);
} }
for (int i = 0; i < _libcLocalList.Count; i++) { for (int i = 0; i < _libcLocalList.Count; i++) {
NativeMemory.AlignedFree((void*)_libcLocalList[i]); NativeMemory.AlignedFree((void*)_libcLocalList[i]);
} }
} }
[GlobalSetup] [GlobalSetup]
public void Setup() public void Setup()
{ {
_random = new Random(42); _random = new Random(42);
_hlsfAllocator = new HybridLayerSegregatedFitAllocator(GetArenaBytes(), align:(int)Alignment); _hlsfAllocator = new HybridLayerSegregatedFitAllocator(GetArenaBytes(), align:(int)Alignment);
} }
private static uint AlignSize( private static uint AlignSize(
uint size uint size
) )
{ {
uint mask = Alignment - 1; uint mask = Alignment - 1;
return (size + mask) & ~mask; return (size + mask) & ~mask;
} }
private static nuint GetArenaBytes() private static nuint GetArenaBytes()
{ {
const int defaultMb = 512; const int defaultMb = 512;
const int minMb = 64; const int minMb = 64;
int mb = defaultMb; int mb = defaultMb;
string? env = Environment.GetEnvironmentVariable("HLSF_BENCH_ARENA_MB"); string? env = Environment.GetEnvironmentVariable("HLSF_BENCH_ARENA_MB");
if (!string.IsNullOrWhiteSpace(env) && if (!string.IsNullOrWhiteSpace(env) &&
int.TryParse(env, out int parsed) && int.TryParse(env, out int parsed) &&
parsed >= minMb) { parsed >= minMb) {
mb = parsed; mb = parsed;
} }
return (nuint)mb * 1024u * 1024u; return (nuint)mb * 1024u * 1024u;
} }
private uint GetNextRandomSize() => (uint)AllocSizes[_random.Next(AllocSizes.Length)]; private uint GetNextRandomSize() => (uint)AllocSizes[_random.Next(AllocSizes.Length)];
private void RunHlsf( private void RunHlsf(
HybridLayerSegregatedFitAllocator allocator, HybridLayerSegregatedFitAllocator allocator,
FreePolicy policy FreePolicy policy
) )
{ {
_hlsfLocalList.Clear(); _hlsfLocalList.Clear();
for (int i = 0; i < AllocationCount; i++) for (int i = 0; i < AllocationCount; i++)
{ {
uint size = AlignSize(GetNextRandomSize()); uint size = AlignSize(GetNextRandomSize());
HybridLayerSegregatedFitAllocationHandle allocate = allocator.Alloc(size); HybridLayerSegregatedFitAllocationHandle allocate = allocator.Alloc(size);
_hlsfLocalList.Add(allocate); _hlsfLocalList.Add(allocate);
} }
for (int i = 0; i < _hlsfLocalList.Count; i++) { for (int i = 0; i < _hlsfLocalList.Count; i++) {
allocator.Free(_hlsfLocalList[i], policy); allocator.Free(_hlsfLocalList[i], policy);
} }
} }
} }
} }
+51 -51
View File
@@ -1,51 +1,51 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Program" // file="Program"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using BenchmarkDotNet.Configs; using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Loggers; using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running; using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.InProcess.Emit; using BenchmarkDotNet.Toolchains.InProcess.Emit;
using StgSharp.Benchmark; using StgSharp.Benchmark;
namespace StgSharp.Benchmark namespace StgSharp.Benchmark
{ {
internal static class Program internal static class Program
{ {
private static void Main( private static void Main(
string[] args string[] args
) )
{ {
IConfig config = ManualConfig.Create(DefaultConfig.Instance) IConfig config = ManualConfig.Create(DefaultConfig.Instance)
.AddLogger(ConsoleLogger.Default) .AddLogger(ConsoleLogger.Default)
.AddJob(Job.Default.WithToolchain(InProcessEmitToolchain.Instance)); .AddJob(Job.Default.WithToolchain(InProcessEmitToolchain.Instance));
BenchmarkRunner.Run<HlsfAllocatorBench>(config); BenchmarkRunner.Run<HlsfAllocatorBench>(config);
} }
} }
} }
+32 -32
View File
@@ -1,32 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>x64</Platforms> <Platforms>x64</Platforms>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SolutionDir Condition="'$(SolutionDir)'=='' Or '$(SolutionDir)'=='*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir> <SolutionDir Condition="'$(SolutionDir)'=='' Or '$(SolutionDir)'=='*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" /> <PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\StgSharp.Common\StgSharp.Common.csproj" Properties="DisablePostBuildCopy=true" /> <ProjectReference Include="..\StgSharp.Common\StgSharp.Common.csproj" Properties="DisablePostBuildCopy=true" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<NativeArtifacts Include="$(SolutionDir)build\**\StgSharp.Native*.dll" /> <NativeArtifacts Include="$(SolutionDir)build\**\StgSharp.Native*.dll" />
<NativeArtifacts Include="$(SolutionDir)build\**\StgSharp.Native*.pdb" /> <NativeArtifacts Include="$(SolutionDir)build\**\StgSharp.Native*.pdb" />
</ItemGroup> </ItemGroup>
<Target Name="CopyNativeArtifacts" AfterTargets="Build" Condition="'$(DisableNativeCopy)'!='true'"> <Target Name="CopyNativeArtifacts" AfterTargets="Build" Condition="'$(DisableNativeCopy)'!='true'">
<Copy SourceFiles="@(NativeArtifacts)" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" Condition="@(NativeArtifacts) != ''" /> <Copy SourceFiles="@(NativeArtifacts)" DestinationFolder="$(TargetDir)" SkipUnchangedFiles="true" Condition="@(NativeArtifacts) != ''" />
</Target> </Target>
</Project> </Project>
@@ -1,194 +1,194 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="BidirectionalDictionary" // file="BidirectionalDictionary"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
public sealed class BidirectionalDictionary<TFirst, TSecond> : IBidirectionalDictionary<TFirst, TSecond> public sealed class BidirectionalDictionary<TFirst, TSecond> : IBidirectionalDictionary<TFirst, TSecond>
where TFirst: notnull where TFirst: notnull
where TSecond: notnull where TSecond: notnull
{ {
private readonly Dictionary<TFirst, TSecond> _forward; private readonly Dictionary<TFirst, TSecond> _forward;
private readonly Dictionary<TSecond, TFirst> _reverse; private readonly Dictionary<TSecond, TFirst> _reverse;
public BidirectionalDictionary() public BidirectionalDictionary()
{ {
_forward = []; _forward = [];
_reverse = []; _reverse = [];
} }
public TFirst this[TSecond key] public TFirst this[TSecond key]
{ {
get => _reverse.TryGetValue(key, out TFirst value) ? get => _reverse.TryGetValue(key, out TFirst value) ?
value : value :
throw new ArgumentException($"Cannot find key {key} in dictionary."); throw new ArgumentException($"Cannot find key {key} in dictionary.");
set set
{ {
if (_reverse.TryGetValue(key, out TFirst origin)) if (_reverse.TryGetValue(key, out TFirst origin))
{ {
_reverse[key] = value; _reverse[key] = value;
_ = _forward.Remove(origin); _ = _forward.Remove(origin);
} else } else
{ {
_reverse.Add(key, value); _reverse.Add(key, value);
} }
_forward.Add(value, key); _forward.Add(value, key);
} }
} }
public TSecond this[TFirst key] public TSecond this[TFirst key]
{ {
get => _forward.TryGetValue(key, out TSecond value) ? get => _forward.TryGetValue(key, out TSecond value) ?
value : value :
throw new ArgumentException($"Cannot find key {key} in dictionary."); throw new ArgumentException($"Cannot find key {key} in dictionary.");
set set
{ {
if (_forward.TryGetValue(key, out TSecond origin)) if (_forward.TryGetValue(key, out TSecond origin))
{ {
_forward[key] = value; _forward[key] = value;
_ = _reverse.Remove(origin); _ = _reverse.Remove(origin);
} else } else
{ {
_forward.Add(key, value); _forward.Add(key, value);
} }
_reverse.Add(value, key); _reverse.Add(value, key);
} }
} }
public bool IsReadOnly => false; public bool IsReadOnly => false;
public ICollection<TFirst> FirstIndex => _forward.Keys; public ICollection<TFirst> FirstIndex => _forward.Keys;
public ICollection<TSecond> SecondIndex => _reverse.Keys; public ICollection<TSecond> SecondIndex => _reverse.Keys;
public int Count => _forward.Count; public int Count => _forward.Count;
public IReadOnlyDictionary<TFirst, TSecond> Forward => new ReadOnlyDictionary<TFirst, TSecond>( public IReadOnlyDictionary<TFirst, TSecond> Forward => new ReadOnlyDictionary<TFirst, TSecond>(
_forward); _forward);
public IReadOnlyDictionary<TSecond, TFirst> Reverse => new ReadOnlyDictionary<TSecond, TFirst>( public IReadOnlyDictionary<TSecond, TFirst> Reverse => new ReadOnlyDictionary<TSecond, TFirst>(
_reverse); _reverse);
public void Add(KeyValuePair<TFirst, TSecond> item) public void Add(KeyValuePair<TFirst, TSecond> item)
{ {
if (_forward.ContainsKey(item.Key) || _reverse.ContainsKey(item.Value)) { if (_forward.ContainsKey(item.Key) || _reverse.ContainsKey(item.Value)) {
throw new ArgumentException("Duplicate key or value."); throw new ArgumentException("Duplicate key or value.");
} }
_forward.Add(item.Key, item.Value); _forward.Add(item.Key, item.Value);
_reverse.Add(item.Value, item.Key); _reverse.Add(item.Value, item.Key);
} }
public void Add(TFirst key, TSecond value) public void Add(TFirst key, TSecond value)
{ {
if (_forward.ContainsKey(key) || _reverse.ContainsKey(value)) { if (_forward.ContainsKey(key) || _reverse.ContainsKey(value)) {
throw new ArgumentException("Duplicate key or value."); throw new ArgumentException("Duplicate key or value.");
} }
_forward.Add(key, value); _forward.Add(key, value);
_reverse.Add(value, key); _reverse.Add(value, key);
} }
public void Clear() public void Clear()
{ {
_forward.Clear(); _forward.Clear();
_reverse.Clear(); _reverse.Clear();
} }
public bool Contains(KeyValuePair<TFirst, TSecond> item) public bool Contains(KeyValuePair<TFirst, TSecond> item)
{ {
return _forward.Contains(item) && _reverse.TryGetValue(item.Value, out TFirst var) && var!.Equals(item.Key); return _forward.Contains(item) && _reverse.TryGetValue(item.Value, out TFirst var) && var!.Equals(item.Key);
} }
public bool Contains(TSecond key) public bool Contains(TSecond key)
{ {
return _reverse.ContainsKey(key); return _reverse.ContainsKey(key);
} }
public bool Contains(TFirst key) public bool Contains(TFirst key)
{ {
return _forward.ContainsKey(key); return _forward.ContainsKey(key);
} }
public void CopyTo(KeyValuePair<TFirst, TSecond>[] array, int arrayIndex) public void CopyTo(KeyValuePair<TFirst, TSecond>[] array, int arrayIndex)
{ {
if (array == null) { if (array == null) {
throw new ArgumentNullException(nameof(array)); throw new ArgumentNullException(nameof(array));
} }
if (arrayIndex < 0 || arrayIndex > array.Length) { if (arrayIndex < 0 || arrayIndex > array.Length) {
throw new ArgumentOutOfRangeException(nameof(arrayIndex)); throw new ArgumentOutOfRangeException(nameof(arrayIndex));
} }
if (array.Length - arrayIndex < _forward.Count) { if (array.Length - arrayIndex < _forward.Count) {
throw new ArgumentException("The array is too small to copy the elements."); throw new ArgumentException("The array is too small to copy the elements.");
} }
foreach (KeyValuePair<TFirst, TSecond> pair in _forward) { foreach (KeyValuePair<TFirst, TSecond> pair in _forward) {
array[arrayIndex++] = pair; array[arrayIndex++] = pair;
} }
} }
public IEnumerator<KeyValuePair<TFirst, TSecond>> GetEnumerator() public IEnumerator<KeyValuePair<TFirst, TSecond>> GetEnumerator()
{ {
foreach (KeyValuePair<TFirst, TSecond> pair in _forward) { foreach (KeyValuePair<TFirst, TSecond> pair in _forward) {
yield return pair; yield return pair;
} }
} }
public bool Remove(TFirst key) public bool Remove(TFirst key)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public bool Remove(KeyValuePair<TFirst, TSecond> item) public bool Remove(KeyValuePair<TFirst, TSecond> item)
{ {
if (_forward.Remove(item.Key)) { if (_forward.Remove(item.Key)) {
return _reverse.Remove(item.Value); return _reverse.Remove(item.Value);
} }
return false; return false;
} }
public bool TryGetValue(TFirst key, out TSecond value) public bool TryGetValue(TFirst key, out TSecond value)
{ {
return _forward.TryGetValue(key, out value); return _forward.TryGetValue(key, out value);
} }
public bool TryGetValue(TSecond key, out TFirst value) public bool TryGetValue(TSecond key, out TFirst value)
{ {
return _reverse.TryGetValue(key, out value); return _reverse.TryGetValue(key, out value);
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }
} }
} }
+92 -92
View File
@@ -1,92 +1,92 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="CapacityFixedBag" // file="CapacityFixedBag"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
public sealed class CapacityFixedBag<T> : IEnumerable<T> public sealed class CapacityFixedBag<T> : IEnumerable<T>
{ {
private readonly T[] _buffer; private readonly T[] _buffer;
public CapacityFixedBag(int capacity) public CapacityFixedBag(int capacity)
{ {
_buffer = new T[capacity]; _buffer = new T[capacity];
} }
public int Count { get; set; } public int Count { get; set; }
public int Capacity => _buffer.Length; public int Capacity => _buffer.Length;
public void Add(T item) public void Add(T item)
{ {
if (Count >= _buffer.Length) { if (Count >= _buffer.Length) {
throw new InvalidOperationException("Bag capacity exceeded."); throw new InvalidOperationException("Bag capacity exceeded.");
} }
_buffer[Count] = item; _buffer[Count] = item;
Count++; Count++;
} }
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for (int i = 0; i < Count; i++) { for (int i = 0; i < Count; i++) {
yield return _buffer[i]; yield return _buffer[i];
} }
} }
public void Remove(T item) public void Remove(T item)
{ {
int index = Array.IndexOf(_buffer, item, 0, Count); int index = Array.IndexOf(_buffer, item, 0, Count);
if (index >= 0) if (index >= 0)
{ {
_buffer[index] = _buffer[Count - 1]; _buffer[index] = _buffer[Count - 1];
_buffer[Count - 1] = default!; _buffer[Count - 1] = default!;
Count--; Count--;
} }
} }
public void RemoveAt(int index) public void RemoveAt(int index)
{ {
if (index >= 0) if (index >= 0)
{ {
_buffer[index] = _buffer[Count - 1]; _buffer[index] = _buffer[Count - 1];
_buffer[Count - 1] = default!; _buffer[Count - 1] = default!;
Count--; Count--;
} }
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }
} }
} }
+183 -183
View File
@@ -1,183 +1,183 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="CapacityFixedList" // file="CapacityFixedList"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
public static class CapacityFixedListBuilder public static class CapacityFixedListBuilder
{ {
internal static CapacityFixedList<T> Create<T>(ReadOnlySpan<T> values) internal static CapacityFixedList<T> Create<T>(ReadOnlySpan<T> values)
{ {
return new CapacityFixedList<T>(values); return new CapacityFixedList<T>(values);
} }
} }
[CollectionBuilder(typeof(CapacityFixedListBuilder), nameof(CapacityFixedListBuilder.Create))] [CollectionBuilder(typeof(CapacityFixedListBuilder), nameof(CapacityFixedListBuilder.Create))]
public class CapacityFixedList<T> : IList<T> public class CapacityFixedList<T> : IList<T>
{ {
private T[] _values; private T[] _values;
private int capacity, _index; private int capacity, _index;
public CapacityFixedList(int size) public CapacityFixedList(int size)
{ {
_values = new T[size]; _values = new T[size];
} }
public CapacityFixedList(ReadOnlySpan<T> values) public CapacityFixedList(ReadOnlySpan<T> values)
{ {
_values = values.ToArray(); _values = values.ToArray();
} }
public T this[int index] public T this[int index]
{ {
get => index < _index ? _values[index] : throw new ArgumentOutOfRangeException(nameof(index)); get => index < _index ? _values[index] : throw new ArgumentOutOfRangeException(nameof(index));
set set
{ {
if (index < _index) if (index < _index)
{ {
_values[index] = value; _values[index] = value;
} else } else
{ {
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
} }
} }
} }
public bool IsReadOnly => false; public bool IsReadOnly => false;
public int Count => _index + 1; public int Count => _index + 1;
public void Add(T item) public void Add(T item)
{ {
if (_index < capacity - 1) if (_index < capacity - 1)
{ {
_index++; _index++;
this[_index] = item; this[_index] = item;
} }
} }
public void Clear() public void Clear()
{ {
_values = new T[capacity]; _values = new T[capacity];
_index = 0; _index = 0;
} }
public bool Contains(T item) public bool Contains(T item)
{ {
for (int i = 0; i <= _index; i++) for (int i = 0; i <= _index; i++)
{ {
if (item.Equals(_values[i])) { if (item.Equals(_values[i])) {
return true; return true;
} }
} }
return false; return false;
} }
public void CopyTo(T[] array, int arrayIndex) public void CopyTo(T[] array, int arrayIndex)
{ {
_values.CopyTo(array, arrayIndex); _values.CopyTo(array, arrayIndex);
} }
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for (int i = 0; i <= _index; i++) { for (int i = 0; i <= _index; i++) {
yield return _values[i]; yield return _values[i];
} }
} }
public int IndexOf(T item) public int IndexOf(T item)
{ {
T v; T v;
for (int i = 0; i <= _index; i++) for (int i = 0; i <= _index; i++)
{ {
if ((v = _values[i]) != null && v.Equals(item)) { if ((v = _values[i]) != null && v.Equals(item)) {
return i; return i;
} }
} }
return -1; return -1;
} }
public bool Remove(T item) public bool Remove(T item)
{ {
T v; T v;
for (int i = 0; i <= _index; i++) for (int i = 0; i <= _index; i++)
{ {
if ((v = _values[i]) != null && v.Equals(item)) if ((v = _values[i]) != null && v.Equals(item))
{ {
_values[i] = _values[_index]; _values[i] = _values[_index];
_index--; _index--;
return true; return true;
} }
} }
return false; return false;
} }
public void RemoveAll(Predicate<T> predicate) public void RemoveAll(Predicate<T> predicate)
{ {
for (int i = _index; i > 0; i--) for (int i = _index; i > 0; i--)
{ {
if (predicate(_values[i])) if (predicate(_values[i]))
{ {
_values[i] = _values[_index]; _values[i] = _values[_index];
_index--; _index--;
} }
} }
} }
public void RemoveAt(int index) public void RemoveAt(int index)
{ {
if (index <= _index) if (index <= _index)
{ {
_values[index] = _values[_index]; _values[index] = _values[_index];
_index--; _index--;
} }
} }
public void Resize(int newSize) public void Resize(int newSize)
{ {
Array.Resize(ref _values, newSize); Array.Resize(ref _values, newSize);
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
yield return GetEnumerator(); yield return GetEnumerator();
} }
void IList<T>.Insert(int index, T item) void IList<T>.Insert(int index, T item)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
}//------------------------------------- End of Class ------------------------------------------ }//------------------------------------- End of Class ------------------------------------------
} }
+169 -169
View File
@@ -1,170 +1,170 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="CapacityFixedStack" // file="CapacityFixedStack"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
[CollectionBuilder(typeof(CapacityFixedStackBuilder), nameof(CapacityFixedStackBuilder.Create))] [CollectionBuilder(typeof(CapacityFixedStackBuilder), nameof(CapacityFixedStackBuilder.Create))]
public class CapacityFixedStack<T> : IEnumerable<T> public class CapacityFixedStack<T> : IEnumerable<T>
{ {
private readonly T[] _values; private readonly T[] _values;
// _index points to the next free slot (top empty position). Therefore Count == _index. // _index points to the next free slot (top empty position). Therefore Count == _index.
private int _index; private int _index;
public CapacityFixedStack(int size) public CapacityFixedStack(int size)
{ {
ArgumentOutOfRangeException.ThrowIfNegative(size); ArgumentOutOfRangeException.ThrowIfNegative(size);
_values = new T[size]; _values = new T[size];
_index = 0; // empty stack _index = 0; // empty stack
} }
public T? First => Volatile.Read(ref _index) > 0 ? _values[0] : default; public T? First => Volatile.Read(ref _index) > 0 ? _values[0] : default;
public bool IsEmpty => Volatile.Read(ref _index) == 0; public bool IsEmpty => Volatile.Read(ref _index) == 0;
public int Count => Volatile.Read(ref _index); public int Count => Volatile.Read(ref _index);
public int Capacity => _values.Length; public int Capacity => _values.Length;
public ReadOnlySpan<T> AsSpan() => _values.AsSpan(0, _index); public ReadOnlySpan<T> AsSpan() => _values.AsSpan(0, _index);
public void Clear() public void Clear()
{ {
if (_index > 0) if (_index > 0)
{ {
Array.Clear(_values, 0, _index); Array.Clear(_values, 0, _index);
_index = 0; _index = 0;
} }
} }
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for (int i = _index - 1; i >= 0; i--) { for (int i = _index - 1; i >= 0; i--) {
yield return _values[i]; yield return _values[i];
} }
} }
public T Peek() public T Peek()
{ {
if (_index == 0) { if (_index == 0) {
throw new InvalidOperationException("Stack is empty."); throw new InvalidOperationException("Stack is empty.");
} }
return _values[_index - 1]; return _values[_index - 1];
} }
public T Pop() public T Pop()
{ {
if (_index == 0) { if (_index == 0) {
throw new InvalidOperationException("Stack is empty."); throw new InvalidOperationException("Stack is empty.");
} }
_index--; _index--;
T item = _values[_index]; T item = _values[_index];
_values[_index] = default!; // Clear reference for GC _values[_index] = default!; // Clear reference for GC
return item; return item;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public T[] PopRange(int count) public T[] PopRange(int count)
{ {
if (count <= 0 || _index == 0) { if (count <= 0 || _index == 0) {
return Array.Empty<T>(); return Array.Empty<T>();
} }
int n = Math.Min(count, _index); int n = Math.Min(count, _index);
int start = _index - n; int start = _index - n;
T[] ret = new T[n]; T[] ret = new T[n];
Array.Copy(_values, start, ret, 0, n); Array.Copy(_values, start, ret, 0, n);
Array.Clear(_values, start, n); Array.Clear(_values, start, n);
_index -= n; _index -= n;
return ret; return ret;
} }
public void Push(T item) public void Push(T item)
{ {
if (_index >= _values.Length) { if (_index >= _values.Length) {
throw new InvalidOperationException("Stack is full."); throw new InvalidOperationException("Stack is full.");
} }
_values[_index] = item; _values[_index] = item;
_index++; _index++;
} }
public void PushRange(ReadOnlySpan<T> span) public void PushRange(ReadOnlySpan<T> span)
{ {
if (span.Length == 0) { if (span.Length == 0) {
return; return;
} }
if (_index + span.Length > _values.Length) { if (_index + span.Length > _values.Length) {
throw new InvalidOperationException("Not enough space in the stack to push the entire span."); throw new InvalidOperationException("Not enough space in the stack to push the entire span.");
} }
span.CopyTo(_values.AsSpan(_index, span.Length)); span.CopyTo(_values.AsSpan(_index, span.Length));
_index += span.Length; _index += span.Length;
} }
public bool TryPop(out T value) public bool TryPop(out T value)
{ {
if (_index == 0) if (_index == 0)
{ {
value = default!; value = default!;
return false; return false;
} }
_index--; _index--;
value = _values[_index]; value = _values[_index];
_values[_index] = default!; _values[_index] = default!;
return true; return true;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal Span<T> GetValueLayout() internal Span<T> GetValueLayout()
{ {
return _values.AsSpan(); return _values.AsSpan();
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }
} }
public static class CapacityFixedStackBuilder public static class CapacityFixedStackBuilder
{ {
public static CapacityFixedStack<T> Create<T>(ReadOnlySpan<T> values) public static CapacityFixedStack<T> Create<T>(ReadOnlySpan<T> values)
{ {
CapacityFixedStack<T> stack = new(values.Length); CapacityFixedStack<T> stack = new(values.Length);
stack.PushRange(values); // Push in order stack.PushRange(values); // Push in order
return stack; return stack;
} }
} }
} }
@@ -1,287 +1,287 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ConcurrentCapacityFixedStack" // file="ConcurrentCapacityFixedStack"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload Space // AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
/// <summary> /// <summary>
/// Lock-free, fixed-capacity stack implemented on top of an array using atomic index /// Lock-free, fixed-capacity stack implemented on top of an array using atomic index
/// operations. - No linked list; only array slots - Uses CAS on a shared top index to /// operations. - No linked list; only array slots - Uses CAS on a shared top index to
/// reserve/release slots - Per-slot state flag to safely publish/consume values under races /// reserve/release slots - Per-slot state flag to safely publish/consume values under races
/// </summary> /// </summary>
public class ConcurrentCapacityFixedStack<T> : IEnumerable<T> public class ConcurrentCapacityFixedStack<T> : IEnumerable<T>
{ {
private readonly int[] _states; // 0 = empty, 1 = full private readonly int[] _states; // 0 = empty, 1 = full
private readonly T[] _values; private readonly T[] _values;
private readonly int _capacity; private readonly int _capacity;
// Number of full slots (observable count) // Number of full slots (observable count)
private int _count; private int _count;
// Next push position (0.._capacity). Only modified via CAS. // Next push position (0.._capacity). Only modified via CAS.
private int _top; private int _top;
public ConcurrentCapacityFixedStack(int capacity) public ConcurrentCapacityFixedStack(int capacity)
{ {
if (capacity <= 0) { if (capacity <= 0) {
throw new ArgumentOutOfRangeException(nameof(capacity)); throw new ArgumentOutOfRangeException(nameof(capacity));
} }
_capacity = capacity; _capacity = capacity;
_values = new T[capacity]; _values = new T[capacity];
_states = new int[capacity]; _states = new int[capacity];
_top = 0; _top = 0;
_count = 0; _count = 0;
} }
public bool IsEmpty => Count == 0; public bool IsEmpty => Count == 0;
public int Capacity => _capacity; public int Capacity => _capacity;
public int Count => Volatile.Read(ref _count); public int Count => Volatile.Read(ref _count);
public void Clear() public void Clear()
{ {
// Pop all elements to return slots to empty state // Pop all elements to return slots to empty state
while (TryPop(out _)) { } while (TryPop(out _)) { }
} }
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
T[] snap = ToArraySnapshot(); T[] snap = ToArraySnapshot();
for (int i = 0; i < snap.Length; i++) { for (int i = 0; i < snap.Length; i++) {
yield return snap[i]; yield return snap[i];
} }
} }
public T Peek() public T Peek()
{ {
if (TryPeek(out T? v)) { if (TryPeek(out T? v)) {
return v; return v;
} }
throw new InvalidOperationException("Stack is empty."); throw new InvalidOperationException("Stack is empty.");
} }
public T Pop() public T Pop()
{ {
if (TryPop(out T value)) { if (TryPop(out T value)) {
return value; return value;
} }
throw new InvalidOperationException("Stack is empty."); throw new InvalidOperationException("Stack is empty.");
} }
public T[] PopRange(int count) public T[] PopRange(int count)
{ {
if (count <= 0) { if (count <= 0) {
return []; return [];
} }
T[] result = new T[count]; T[] result = new T[count];
int i = 0; int i = 0;
for (; i < count; i++) for (; i < count; i++)
{ {
if (!TryPop(out result[i])) if (!TryPop(out result[i]))
{ {
break; break;
} }
} }
if (i == count) { if (i == count) {
return result; return result;
} }
if (i == 0) { if (i == 0) {
return []; return [];
} }
T[] trimmed = new T[i]; T[] trimmed = new T[i];
Array.Copy(result, trimmed, i); Array.Copy(result, trimmed, i);
return trimmed; return trimmed;
} }
public void Push(T item) public void Push(T item)
{ {
SpinWait sw = default; SpinWait sw = default;
while (true) while (true)
{ {
int oldTop = Volatile.Read(ref _top); int oldTop = Volatile.Read(ref _top);
if (oldTop >= _capacity) { if (oldTop >= _capacity) {
throw new InvalidOperationException("Stack is full."); throw new InvalidOperationException("Stack is full.");
} }
if (Interlocked.CompareExchange(ref _top, oldTop + 1, oldTop) != oldTop) if (Interlocked.CompareExchange(ref _top, oldTop + 1, oldTop) != oldTop)
{ {
sw.SpinOnce(); sw.SpinOnce();
continue; // failed to reserve slot continue; // failed to reserve slot
} }
// We exclusively own slot oldTop. Publish value then state. // We exclusively own slot oldTop. Publish value then state.
_values[oldTop] = item; _values[oldTop] = item;
Volatile.Write(ref _states[oldTop], 1); // publish Volatile.Write(ref _states[oldTop], 1); // publish
_ = Interlocked.Increment(ref _count); _ = Interlocked.Increment(ref _count);
return; return;
} }
} }
public void PushRange(ReadOnlySpan<T> span) public void PushRange(ReadOnlySpan<T> span)
{ {
for (int i = 0; i < span.Length; i++) { for (int i = 0; i < span.Length; i++) {
Push(span[i]); Push(span[i]);
} }
} }
/// <summary> /// <summary>
/// Best-effort snapshot for enumeration; not strongly consistent under concurrent /// Best-effort snapshot for enumeration; not strongly consistent under concurrent
/// mutations. /// mutations.
/// </summary> /// </summary>
public T[] ToArraySnapshot() public T[] ToArraySnapshot()
{ {
int expected = Math.Min(Volatile.Read(ref _count), _capacity); int expected = Math.Min(Volatile.Read(ref _count), _capacity);
if (expected == 0) { if (expected == 0) {
return Array.Empty<T>(); return Array.Empty<T>();
} }
T[] snap = new T[expected]; T[] snap = new T[expected];
int copied = 0; int copied = 0;
int idx = Volatile.Read(ref _top) - 1; int idx = Volatile.Read(ref _top) - 1;
while (idx >= 0 && copied < expected) while (idx >= 0 && copied < expected)
{ {
if (Volatile.Read(ref _states[idx]) == 1) { if (Volatile.Read(ref _states[idx]) == 1) {
snap[copied++] = _values[idx]; snap[copied++] = _values[idx];
} }
idx--; idx--;
} }
if (copied == snap.Length) { if (copied == snap.Length) {
return snap; return snap;
} }
T[] trimmed = new T[copied]; T[] trimmed = new T[copied];
Array.Copy(snap, trimmed, copied); Array.Copy(snap, trimmed, copied);
return trimmed; return trimmed;
} }
public bool TryPeek(out T value) public bool TryPeek(out T value)
{ {
value = default!; value = default!;
SpinWait sw = default; SpinWait sw = default;
while (true) while (true)
{ {
int top = Volatile.Read(ref _top); int top = Volatile.Read(ref _top);
if (top <= 0) { if (top <= 0) {
return false; return false;
} }
int idx = top - 1; int idx = top - 1;
// If not yet published or racing, retry/spin // If not yet published or racing, retry/spin
if (Volatile.Read(ref _states[idx]) == 0) if (Volatile.Read(ref _states[idx]) == 0)
{ {
if (Volatile.Read(ref _top) != top) if (Volatile.Read(ref _top) != top)
{ {
continue; // head moved, retry continue; // head moved, retry
} }
sw.SpinOnce(); sw.SpinOnce();
continue; continue;
} }
T v = _values[idx]; T v = _values[idx];
// Validate consistency // Validate consistency
if (Volatile.Read(ref _top) == top && Volatile.Read(ref _states[idx]) == 1) if (Volatile.Read(ref _top) == top && Volatile.Read(ref _states[idx]) == 1)
{ {
value = v; value = v;
return true; return true;
} }
} }
} }
public bool TryPop(out T value) public bool TryPop(out T value)
{ {
value = default!; value = default!;
SpinWait sw = default; SpinWait sw = default;
while (true) while (true)
{ {
int oldTop = Volatile.Read(ref _top); int oldTop = Volatile.Read(ref _top);
if (oldTop <= 0) if (oldTop <= 0)
{ {
return false; // empty return false; // empty
} }
int newTop = oldTop - 1; // index to consume int newTop = oldTop - 1; // index to consume
if (Interlocked.CompareExchange(ref _top, newTop, oldTop) != oldTop) if (Interlocked.CompareExchange(ref _top, newTop, oldTop) != oldTop)
{ {
sw.SpinOnce(); sw.SpinOnce();
continue; // failed to reserve element continue; // failed to reserve element
} }
// If producer hasn't published yet, roll back our reservation and retry. // If producer hasn't published yet, roll back our reservation and retry.
if (Volatile.Read(ref _states[newTop]) == 0) if (Volatile.Read(ref _states[newTop]) == 0)
{ {
// attempt to restore top; ok if it fails due to concurrent operations // attempt to restore top; ok if it fails due to concurrent operations
_ = Interlocked.CompareExchange(ref _top, newTop + 1, newTop); _ = Interlocked.CompareExchange(ref _top, newTop + 1, newTop);
sw.SpinOnce(); sw.SpinOnce();
continue; continue;
} }
value = _values[newTop]; value = _values[newTop];
_values[newTop] = default!; // avoid ref retention _values[newTop] = default!; // avoid ref retention
Volatile.Write(ref _states[newTop], 0); // mark empty Volatile.Write(ref _states[newTop], 0); // mark empty
_ = Interlocked.Decrement(ref _count); _ = Interlocked.Decrement(ref _count);
return true; return true;
} }
} }
public int TryPopRange(Span<T> destination) public int TryPopRange(Span<T> destination)
{ {
if (destination.IsEmpty) { if (destination.IsEmpty) {
return 0; return 0;
} }
int i = 0; int i = 0;
for (; i < destination.Length; i++) for (; i < destination.Length; i++)
{ {
if (!TryPop(out destination[i])) if (!TryPop(out destination[i]))
{ {
break; break;
} }
} }
return i; return i;
} }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
} }
} }
@@ -1,95 +1,84 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IBidirectionalDictionary" // file="IBidirectionalDictionary"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload Space
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System.Collections.Generic; using System.Collections.Generic;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
public interface IBidirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond> public interface IBidirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond>
{ {
TFirst this[ TFirst this[TSecond key] { get; set; }
TSecond key
] { get; set; } ICollection<TFirst> FirstIndex { get; }
ICollection<TFirst> FirstIndex { get; } ICollection<TSecond> SecondIndex { get; }
ICollection<TSecond> SecondIndex { get; } IReadOnlyDictionary<TFirst, TSecond> Forward { get; }
IReadOnlyDictionary<TFirst, TSecond> Forward { get; } IReadOnlyDictionary<TSecond, TFirst> Reverse { get; }
IReadOnlyDictionary<TSecond, TFirst> Reverse { get; } /// <summary>
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
/// <summary> /// specified key.
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the /// </summary>
/// specified key. /// <param _label="key">
/// </summary> /// The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />.
/// <param _label="key"> /// </param>
/// The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />. /// <returns>
/// </param> /// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
/// <returns> /// the specified key; otherwise, false.
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with /// </returns>
/// the specified key; otherwise, false. bool Contains(TSecond key);
/// </returns>
bool Contains( /// <summary>
TSecond key /// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
); /// specified key.
/// </summary>
/// <summary> /// <param _label="key">
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the /// The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />.
/// specified key. /// </param>
/// </summary> /// <returns>
/// <param _label="key"> /// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
/// The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />. /// the specified key; otherwise, false.
/// </param> /// </returns>
/// <returns> bool Contains(TFirst key);
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with
/// the specified key; otherwise, false. bool TryGetValue(TSecond key, out TFirst value);
/// </returns>
bool Contains( #pragma warning disable CA1033
TFirst key ICollection<TFirst> IDictionary<TFirst, TSecond>.Keys => FirstIndex;
);
ICollection<TSecond> IDictionary<TFirst, TSecond>.Values => SecondIndex;
bool TryGetValue(
TSecond key, bool IDictionary<TFirst, TSecond>.ContainsKey(TFirst key)
out TFirst value {
); return Contains(key);
}
#pragma warning disable CA1033 #pragma warning restore CA1033
ICollection<TFirst> IDictionary<TFirst, TSecond>.Keys => FirstIndex; }
ICollection<TSecond> IDictionary<TFirst, TSecond>.Values => SecondIndex;
bool IDictionary<TFirst, TSecond>.ContainsKey(
TFirst key
)
{
return Contains(key);
}
#pragma warning restore CA1033
}
} }
+52 -52
View File
@@ -1,53 +1,53 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IHashMultiplexer" // file="IHashMultiplexer"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System.Collections.Generic; using System.Collections.Generic;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
public interface IHashMultiplexer<T> : IEqualityComparer<T> public interface IHashMultiplexer<T> : IEqualityComparer<T>
{ {
int RemainedMultiplexCount { get; set; } int RemainedMultiplexCount { get; set; }
/// <summary> /// <summary>
/// Cache hash result for obj with counts. /// Cache hash result for obj with counts.
/// </summary> /// </summary>
/// <param name="obj"> /// <param name="obj">
/// ///
/// </param> /// </param>
/// <param name="count"> /// <param name="count">
/// ///
/// </param> /// </param>
void CacheHash(T obj, int count); void CacheHash(T obj, int count);
void ExtendCache(int count); void ExtendCache(int count);
int ForceComputeHash(T count); int ForceComputeHash(T count);
} }
} }
+131 -131
View File
@@ -1,131 +1,131 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ListSegment" // file="ListSegment"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Serialization; using System.Xml.Serialization;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
/// <summary> /// <summary>
/// Part of a collection. This contains a direct reference to _origin collection, so all /// Part of a collection. This contains a direct reference to _origin collection, so all
/// change to _origin collection will be reflected in this object. /// change to _origin collection will be reflected in this object.
/// </summary> /// </summary>
/// <typeparam name="T"> /// <typeparam name="T">
/// ///
/// </typeparam> /// </typeparam>
public struct ListSegment<T> : ICollection<T> public struct ListSegment<T> : ICollection<T>
{ {
private int _begin; private int _begin;
private int _length; private int _length;
private List<T> _collection; private List<T> _collection;
public ListSegment(List<T> collection, int begin, int length) public ListSegment(List<T> collection, int begin, int length)
{ {
ArgumentNullException.ThrowIfNull(collection); ArgumentNullException.ThrowIfNull(collection);
ArgumentOutOfRangeException.ThrowIfLessThan(begin, 0); ArgumentOutOfRangeException.ThrowIfLessThan(begin, 0);
ArgumentOutOfRangeException.ThrowIfLessThan(length, 0); ArgumentOutOfRangeException.ThrowIfLessThan(length, 0);
ArgumentOutOfRangeException.ThrowIfLessThan(begin + length, collection.Count); ArgumentOutOfRangeException.ThrowIfLessThan(begin + length, collection.Count);
_collection = collection; _collection = collection;
_begin = begin; _begin = begin;
_length = length; _length = length;
} }
public T this[int indexValue] public T this[int indexValue]
{ {
get get
{ {
ArgumentOutOfRangeException.ThrowIfLessThan(indexValue, 0); ArgumentOutOfRangeException.ThrowIfLessThan(indexValue, 0);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(indexValue, _length); ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(indexValue, _length);
return _collection[indexValue + _begin]; return _collection[indexValue + _begin];
} }
} }
public T this[Index i] public T this[Index i]
{ {
get get
{ {
int offset = i.IsFromEnd ? _length - i.Value : i.Value; int offset = i.IsFromEnd ? _length - i.Value : i.Value;
ArgumentOutOfRangeException.ThrowIfLessThan(offset, 0); ArgumentOutOfRangeException.ThrowIfLessThan(offset, 0);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(offset, _length); ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(offset, _length);
return _collection[offset + _begin]; return _collection[offset + _begin];
} }
} }
public bool IsReadOnly => true; public bool IsReadOnly => true;
public int Count => _length; public int Count => _length;
public bool Contains(T item) public bool Contains(T item)
{ {
int index = _collection.IndexOf(item); int index = _collection.IndexOf(item);
return index >= _begin && index < _length + index; return index >= _begin && index < _length + index;
} }
public void CopyTo(T[] array, int arrayIndex) public void CopyTo(T[] array, int arrayIndex)
{ {
ArgumentNullException.ThrowIfNull(array); ArgumentNullException.ThrowIfNull(array);
Span<T> span = CollectionsMarshal.AsSpan<T>(_collection).Slice(_begin, _length); Span<T> span = CollectionsMarshal.AsSpan<T>(_collection).Slice(_begin, _length);
Span<T> target = new Span<T>(array, arrayIndex, _length); Span<T> target = new Span<T>(array, arrayIndex, _length);
span.CopyTo(target); span.CopyTo(target);
} }
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for (int i = _begin; i < _length; i++) { for (int i = _begin; i < _length; i++) {
yield return this[i]; yield return this[i];
} }
} }
void ICollection<T>.Add(T item) void ICollection<T>.Add(T item)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
void ICollection<T>.Clear() void ICollection<T>.Clear()
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
bool ICollection<T>.Remove(T item) bool ICollection<T>.Remove(T item)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }
} }
} }
+191 -191
View File
@@ -1,191 +1,191 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="NotEnumerableList" // file="NotEnumerableList"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
public static class LinearBagBuilder public static class LinearBagBuilder
{ {
/// <summary> /// <summary>
/// Build a <see cref="LinearBag{T}" /> from a read-only span. Capacity will exactly fit /// Build a <see cref="LinearBag{T}" /> from a read-only span. Capacity will exactly fit
/// the input. /// the input.
/// </summary> /// </summary>
public static LinearBag<T> FromSpan<T>(ReadOnlySpan<T> values) public static LinearBag<T> FromSpan<T>(ReadOnlySpan<T> values)
{ {
if (values.IsEmpty) { if (values.IsEmpty) {
return new LinearBag<T>(4); return new LinearBag<T>(4);
} }
LinearBag<T> bag = new(values.Length); LinearBag<T> bag = new(values.Length);
for (int i = 0; i < values.Length; i++) { for (int i = 0; i < values.Length; i++) {
bag.Add(values[i]); bag.Add(values[i]);
} }
return bag; return bag;
} }
} }
/// <summary> /// <summary>
/// A very lightweight contiguous storage structure: unordered, not enumerable by design. /// A very lightweight contiguous storage structure: unordered, not enumerable by design.
/// Provides O(1) Add and O(1) RemoveAt (by swapping with the tail). Intended for high- /// Provides O(1) Add and O(1) RemoveAt (by swapping with the tail). Intended for high-
/// performance scenarios where element ordering does not matter. NOT thread-safe. /// performance scenarios where element ordering does not matter. NOT thread-safe.
/// </summary> /// </summary>
/// <typeparam name="T"> /// <typeparam name="T">
/// Element type. /// Element type.
/// </typeparam> /// </typeparam>
[CollectionBuilder(typeof(LinearBagBuilder), nameof(LinearBagBuilder.FromSpan))] [CollectionBuilder(typeof(LinearBagBuilder), nameof(LinearBagBuilder.FromSpan))]
public class LinearBag<T>(int capacity = 4) public class LinearBag<T>(int capacity = 4)
{ {
// Invariant: valid elements occupy indexes [0, Count-1]. Count is the number of live elements. // Invariant: valid elements occupy indexes [0, Count-1]. Count is the number of live elements.
private T[] _items = new T[Math.Max(0, capacity)]; private T[] _items = new T[Math.Max(0, capacity)];
/// <summary> /// <summary>
/// Access element by index (0..Count-1). Throws if out of range. /// Access element by index (0..Count-1). Throws if out of range.
/// </summary> /// </summary>
public T this[int index] public T this[int index]
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (uint)index >= (uint)Count ? throw new ArgumentOutOfRangeException(nameof(index)) : _items[index]; get => (uint)index >= (uint)Count ? throw new ArgumentOutOfRangeException(nameof(index)) : _items[index];
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
set set
{ {
if ((uint)index >= (uint)Count) { if ((uint)index >= (uint)Count) {
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
} }
_items[index] = value; _items[index] = value;
} }
} }
/// <summary> /// <summary>
/// Total allocated slots. /// Total allocated slots.
/// </summary> /// </summary>
public int Capacity => _items.Length; public int Capacity => _items.Length;
/// <summary> /// <summary>
/// Number of currently stored elements (valid index range 0..Count-1). /// Number of currently stored elements (valid index range 0..Count-1).
/// </summary> /// </summary>
public int Count { get; private set; } public int Count { get; private set; }
/// <summary> /// <summary>
/// Adds an item (unordered). Expands internal array if needed. /// Adds an item (unordered). Expands internal array if needed.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(T item) public void Add(T item)
{ {
if (Count == _items.Length) { if (Count == _items.Length) {
EnsureCapacity(Count + 1); EnsureCapacity(Count + 1);
} }
_items[Count] = item; _items[Count] = item;
Count++; Count++;
} }
/// <summary> /// <summary>
/// Returns a span over the live portion of the bag (0..Count-1). /// Returns a span over the live portion of the bag (0..Count-1).
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> AsSpan() => new Span<T>(_items, 0, Count); public Span<T> AsSpan() => new Span<T>(_items, 0, Count);
/// <summary> /// <summary>
/// Clears all elements and zeroes out references to avoid retention. Count becomes 0. /// Clears all elements and zeroes out references to avoid retention. Count becomes 0.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear() public void Clear()
{ {
Array.Clear(_items, 0, Count); Array.Clear(_items, 0, Count);
Count = 0; Count = 0;
} }
/// <summary> /// <summary>
/// Fast clear: only resets Count (leaves underlying array unchanged). References are NOT /// Fast clear: only resets Count (leaves underlying array unchanged). References are NOT
/// released. Use only when you are certain old references can remain. /// released. Use only when you are certain old references can remain.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void FastClear() => Count = 0; public void FastClear() => Count = 0;
/// <summary> /// <summary>
/// Removes the first occurrence of value (unordered). Does nothing if not found. /// Removes the first occurrence of value (unordered). Does nothing if not found.
/// </summary> /// </summary>
public void Remove(T value) public void Remove(T value)
{ {
EqualityComparer<T> comparer = EqualityComparer<T>.Default; EqualityComparer<T> comparer = EqualityComparer<T>.Default;
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
if (comparer.Equals(_items[i], value)) if (comparer.Equals(_items[i], value))
{ {
RemoveAt(i); RemoveAt(i);
return; return;
} }
} }
} }
/// <summary> /// <summary>
/// Removes element at index by swapping the last element into its slot (unless already /// Removes element at index by swapping the last element into its slot (unless already
/// last). Preserves O(1) removal at cost of ordering. /// last). Preserves O(1) removal at cost of ordering.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void RemoveAt(int index) public void RemoveAt(int index)
{ {
if ((uint)index >= (uint)Count) { if ((uint)index >= (uint)Count) {
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
} }
int last = Count - 1; int last = Count - 1;
if (index != last) { if (index != last) {
_items[index] = _items[last]; _items[index] = _items[last];
} }
_items[last] = default!; // release reference / reset value _items[last] = default!; // release reference / reset value
Count = last; Count = last;
} }
/// <summary> /// <summary>
/// Ensures capacity is at least <paramref name="min" />. Doubles size when growing. /// Ensures capacity is at least <paramref name="min" />. Doubles size when growing.
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EnsureCapacity(int min) private void EnsureCapacity(int min)
{ {
if (_items.Length >= min) { if (_items.Length >= min) {
return; return;
} }
int newCapacity = _items.Length == 0 ? 4 : _items.Length * 2; int newCapacity = _items.Length == 0 ? 4 : _items.Length * 2;
if (newCapacity < min) { if (newCapacity < min) {
newCapacity = min; newCapacity = min;
} }
Array.Resize(ref _items, newCapacity); Array.Resize(ref _items, newCapacity);
} }
} }
} }
@@ -1,181 +1,181 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="RandomAccessibleStack" // file="RandomAccessibleStack"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
public class RandomAccessibleStack<T> : IEnumerable<T> public class RandomAccessibleStack<T> : IEnumerable<T>
{ {
private const int DefaultCapacity = 4; private const int DefaultCapacity = 4;
private T[] _array; private T[] _array;
private int _size; private int _size;
private int _version; private int _version;
/// <summary> /// <summary>
/// Initializes a new instance of the RandomAccessStack class that is empty and has the /// Initializes a new instance of the RandomAccessStack class that is empty and has the
/// default initial capacity. /// default initial capacity.
/// </summary> /// </summary>
public RandomAccessibleStack() public RandomAccessibleStack()
{ {
_array = new T[DefaultCapacity]; _array = new T[DefaultCapacity];
} }
/// <summary> /// <summary>
/// Initializes a new instance of the RandomAccessStack class that is empty and has the /// Initializes a new instance of the RandomAccessStack class that is empty and has the
/// specified initial capacity. /// specified initial capacity.
/// </summary> /// </summary>
public RandomAccessibleStack(int capacity) public RandomAccessibleStack(int capacity)
{ {
if (capacity < 0) { if (capacity < 0) {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(
nameof(capacity), "Capacity must be non-negative."); nameof(capacity), "Capacity must be non-negative.");
} }
_array = new T[capacity]; _array = new T[capacity];
} }
/// <summary> /// <summary>
/// Gets or sets the element at the specified index in the stack (0 = bottom, Count-1 = /// Gets or sets the element at the specified index in the stack (0 = bottom, Count-1 =
/// top). /// top).
/// </summary> /// </summary>
public T this[int index] public T this[int index]
{ {
get get
{ {
if (index < 0 || index >= _size) { if (index < 0 || index >= _size) {
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
} }
return _array[index]; return _array[index];
} }
/* /*
set set
{ {
if( index < 0 || index >= PrimSize ) { if( index < 0 || index >= PrimSize ) {
throw new ArgumentOutOfRangeException( nameof( index ) ); throw new ArgumentOutOfRangeException( nameof( index ) );
} }
_array[ index ] = value; _array[ index ] = value;
_version++; _version++;
} }
/**/ /**/
} }
/// <summary> /// <summary>
/// Gets the number of elements contained in the stack. /// Gets the number of elements contained in the stack.
/// </summary> /// </summary>
public int Count => _size; public int Count => _size;
/// <summary> /// <summary>
/// Removes all objects from the stack. /// Removes all objects from the stack.
/// </summary> /// </summary>
public void Clear() public void Clear()
{ {
Array.Clear(_array, 0, _size); Array.Clear(_array, 0, _size);
_size = 0; _size = 0;
_version++; _version++;
} }
/// <summary> /// <summary>
/// Returns an enumerator that iterates through the stack from top to bottom. Throws if /// Returns an enumerator that iterates through the stack from top to bottom. Throws if
/// the stack is modified during iteration. /// the stack is modified during iteration.
/// </summary> /// </summary>
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
int expectedVersion = _version; int expectedVersion = _version;
for (int i = _size - 1; i >= 0; i--) for (int i = _size - 1; i >= 0; i--)
{ {
if (expectedVersion != _version) { if (expectedVersion != _version) {
throw new InvalidOperationException( throw new InvalidOperationException(
"Collection was modified during enumeration."); "Collection was modified during enumeration.");
} }
yield return _array[i]; yield return _array[i];
} }
} }
/// <summary> /// <summary>
/// Returns the object at the top of the stack without removing it. /// Returns the object at the top of the stack without removing it.
/// </summary> /// </summary>
public T Peek() public T Peek()
{ {
if (_size == 0) { if (_size == 0) {
throw new InvalidOperationException("Stack is empty."); throw new InvalidOperationException("Stack is empty.");
} }
return _array[_size - 1]; return _array[_size - 1];
} }
/// <summary> /// <summary>
/// Removes and returns the object at the top of the stack. /// Removes and returns the object at the top of the stack.
/// </summary> /// </summary>
public T Pop() public T Pop()
{ {
if (_size == 0) { if (_size == 0) {
throw new InvalidOperationException("Stack is empty."); throw new InvalidOperationException("Stack is empty.");
} }
T item = _array[--_size]; T item = _array[--_size];
_array[_size] = default!; _array[_size] = default!;
_version++; _version++;
return item; return item;
} }
/// <summary> /// <summary>
/// Adds an item to the top of the stack. /// Adds an item to the top of the stack.
/// </summary> /// </summary>
public void Push(T item) public void Push(T item)
{ {
if (_size == _array.Length) { if (_size == _array.Length) {
EnsureCapacity(_size + 1); EnsureCapacity(_size + 1);
} }
_array[_size++] = item; _array[_size++] = item;
_version++; _version++;
} }
private void EnsureCapacity(int min) private void EnsureCapacity(int min)
{ {
int newCapacity = _array.Length == 0 ? DefaultCapacity : _array.Length * 2; int newCapacity = _array.Length == 0 ? DefaultCapacity : _array.Length * 2;
if (newCapacity < min) { if (newCapacity < min) {
newCapacity = min; newCapacity = min;
} }
Array.Resize(ref _array, newCapacity); Array.Resize(ref _array, newCapacity);
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }
} }
} }
@@ -1,162 +1,162 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="StringHashMultiplexer" // file="StringHashMultiplexer"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
namespace StgSharp.Collections namespace StgSharp.Collections
{ {
public sealed class StringHashMultiplexer : IHashMultiplexer<string> public sealed class StringHashMultiplexer : IHashMultiplexer<string>
{ {
private int _initCount, _remainedCount, _hashCache, _hashLast; private int _initCount, _remainedCount, _hashCache, _hashLast;
private string _source, _sourceLast; private string _source, _sourceLast;
public int RemainedMultiplexCount public int RemainedMultiplexCount
{ {
get => _remainedCount; get => _remainedCount;
set => _initCount = value; set => _initCount = value;
} }
public void CacheHash(string obj, int count) public void CacheHash(string obj, int count)
{ {
_hashCache = ForceComputeHash(obj); _hashCache = ForceComputeHash(obj);
_initCount = count; _initCount = count;
_remainedCount = _initCount; _remainedCount = _initCount;
_source = obj; _source = obj;
} }
public bool Equals(string x, string y) public bool Equals(string x, string y)
{ {
return x == y; return x == y;
} }
public void ExtendCache(int count) public void ExtendCache(int count)
{ {
_initCount += count; _initCount += count;
_remainedCount += count; _remainedCount += count;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe int ForceComputeHash([NotNull] string obj) public unsafe int ForceComputeHash([NotNull] string obj)
{ {
int hash; int hash;
fixed (char* cPtr = obj.AsSpan()) { fixed (char* cPtr = obj.AsSpan()) {
hash = NativeIntrinsic.Context.city_hash_simplify(cPtr, obj.Length); hash = NativeIntrinsic.Context.city_hash_simplify(cPtr, obj.Length);
} }
return hash; return hash;
} }
public int GetHashCode(string obj) public int GetHashCode(string obj)
{ {
if (_remainedCount > 0 && ReferenceEquals(_source, obj)) if (_remainedCount > 0 && ReferenceEquals(_source, obj))
{ {
_remainedCount--; _remainedCount--;
return _hashCache; return _hashCache;
} }
if (ReferenceEquals(_sourceLast, obj)) { if (ReferenceEquals(_sourceLast, obj)) {
return _hashLast; return _hashLast;
} }
_sourceLast = obj; _sourceLast = obj;
_hashLast = ForceComputeHash(obj); _hashLast = ForceComputeHash(obj);
return _hashLast; return _hashLast;
} }
} }
public sealed class ConcurrentStringHashMultiplexer : IHashMultiplexer<string>, IDisposable public sealed class ConcurrentStringHashMultiplexer : IHashMultiplexer<string>, IDisposable
{ {
private bool disposedValue; private bool disposedValue;
private readonly ThreadLocal<StringHashMultiplexer> _multiplexers = private readonly ThreadLocal<StringHashMultiplexer> _multiplexers =
new(() => new StringHashMultiplexer()); new(() => new StringHashMultiplexer());
public int RemainedMultiplexCount public int RemainedMultiplexCount
{ {
get => _multiplexers.Value!.RemainedMultiplexCount; get => _multiplexers.Value!.RemainedMultiplexCount;
set => _multiplexers.Value!.RemainedMultiplexCount = value; set => _multiplexers.Value!.RemainedMultiplexCount = value;
} }
public void CacheHash(string obj, int count) public void CacheHash(string obj, int count)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
// ~ConcurrentStringHashMultiplexer() // ~ConcurrentStringHashMultiplexer()
// { // {
// Dispose(disposing: false); // Dispose(disposing: false);
// } // }
public void Dispose() public void Dispose()
{ {
Dispose(disposing:true); Dispose(disposing:true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
public bool Equals(string x, string y) public bool Equals(string x, string y)
{ {
return x == y; return x == y;
} }
public void ExtendCache(int count) public void ExtendCache(int count)
{ {
_multiplexers.Value!.ExtendCache(count); _multiplexers.Value!.ExtendCache(count);
} }
public unsafe int ForceComputeHash([NotNull] string obj) public unsafe int ForceComputeHash([NotNull] string obj)
{ {
int hash; int hash;
fixed (char* cPtr = obj.AsSpan()) { fixed (char* cPtr = obj.AsSpan()) {
hash = NativeIntrinsic.Context.city_hash_simplify(cPtr, obj.Length); hash = NativeIntrinsic.Context.city_hash_simplify(cPtr, obj.Length);
} }
return hash; return hash;
} }
public int GetHashCode(string obj) public int GetHashCode(string obj)
{ {
return _multiplexers.Value!.GetHashCode(obj); return _multiplexers.Value!.GetHashCode(obj);
} }
private void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (!disposedValue) if (!disposedValue)
{ {
if (disposing) { if (disposing) {
_multiplexers.Dispose(); _multiplexers.Dispose();
} }
disposedValue = true; disposedValue = true;
} }
} }
} }
} }
@@ -1,62 +1,62 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="BattleField" // file="BattleField"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Geometries; using StgSharp.Geometries;
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
// TODO 这玩意如何加载一个渲染流程以获得各个图元还没搞清楚 // TODO 这玩意如何加载一个渲染流程以获得各个图元还没搞清楚
namespace StgSharp.Controls namespace StgSharp.Controls
{ {
public class BattleField : ControllingItem public class BattleField : ControllingItem
{ {
public bool IsEntity => true; public bool IsEntity => true;
public ReadOnlySpan<Vec4> TextureBox public ReadOnlySpan<Vec4> TextureBox
{ {
get => throw new NotImplementedException(); get => throw new NotImplementedException();
} }
public Rectangle BoundingBox { get; set; } public Rectangle BoundingBox { get; set; }
public Vec2 Position { get; set; } public Vec2 Position { get; set; }
public IEnumerator<PlainGeometryMesh> GetEnumerator() public IEnumerator<PlainGeometryMesh> GetEnumerator()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
} }
@@ -1,149 +1,149 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ButtonGroup" // file="ButtonGroup"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Geometries; using StgSharp.Geometries;
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Transactions; using System.Transactions;
namespace StgSharp.Controls namespace StgSharp.Controls
{ {
public abstract class KeyboardButtonGroup : ControllingItem public abstract class KeyboardButtonGroup : ControllingItem
{ {
private List<TriggerButton> buttonList; private List<TriggerButton> buttonList;
private TriggerButton current; private TriggerButton current;
public KeyboardButtonGroup() public KeyboardButtonGroup()
{ {
buttonList = new List<TriggerButton>(); buttonList = new List<TriggerButton>();
} }
public bool IsEntity public bool IsEntity
{ {
get => false; get => false;
} }
public ReadOnlySpan<Vec4> TextureBox public ReadOnlySpan<Vec4> TextureBox
{ {
get => throw new NotSupportedException(); get => throw new NotSupportedException();
} }
public Rectangle BoundingBox { get; set; } public Rectangle BoundingBox { get; set; }
public TriggerButton CurrentButton public TriggerButton CurrentButton
{ {
get => current; get => current;
} }
public Vec2 Position { get; set; } public Vec2 Position { get; set; }
protected List<TriggerButton> AllButton protected List<TriggerButton> AllButton
{ {
get => buttonList; get => buttonList;
} }
public void AddButton(TriggerButton button) public void AddButton(TriggerButton button)
{ {
buttonList.Add(button); buttonList.Add(button);
} }
public abstract void Confirm(); public abstract void Confirm();
public IEnumerator<PlainGeometryMesh> GetEnumerator() public IEnumerator<PlainGeometryMesh> GetEnumerator()
{ {
foreach (TriggerButton item in buttonList) { foreach (TriggerButton item in buttonList) {
yield return item.Single(); yield return item.Single();
} }
} }
public void MoveDown() public void MoveDown()
{ {
TriggerButton button = current; TriggerButton button = current;
while ((button.Down != null) && button.Down.IsDisabled) { while ((button.Down != null) && button.Down.IsDisabled) {
button = button.Right; button = button.Right;
} }
if (current == button) { if (current == button) {
return; return;
} }
current.DeHighlight(); current.DeHighlight();
button.Enable(); button.Enable();
current = button; current = button;
} }
public void MoveLeft() public void MoveLeft()
{ {
TriggerButton button = current; TriggerButton button = current;
while ((button.Left != null) && button.Left.IsDisabled) { while ((button.Left != null) && button.Left.IsDisabled) {
button = button.Left; button = button.Left;
} }
if (current == button) { if (current == button) {
return; return;
} }
current.DeHighlight(); current.DeHighlight();
button.Enable(); button.Enable();
current = button; current = button;
} }
public void MoveRight() public void MoveRight()
{ {
TriggerButton button = current; TriggerButton button = current;
while ((button.Right != null) && button.Right.IsDisabled) { while ((button.Right != null) && button.Right.IsDisabled) {
button = button.Right; button = button.Right;
} }
if (current == button) { if (current == button) {
return; return;
} }
current.DeHighlight(); current.DeHighlight();
button.Enable(); button.Enable();
current = button; current = button;
} }
public void MoveUp() public void MoveUp()
{ {
TriggerButton button = current; TriggerButton button = current;
while ((button.Up != null) && button.Up.IsDisabled) { while ((button.Up != null) && button.Up.IsDisabled) {
button = button.Right; button = button.Right;
} }
if (current == button) { if (current == button) {
return; return;
} }
current.DeHighlight(); current.DeHighlight();
button.Enable(); button.Enable();
current = button; current = button;
} }
} }
} }
@@ -1,109 +1,109 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="CharacterIndexImage" // file="CharacterIndexImage"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Geometries; using StgSharp.Geometries;
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace StgSharp.Controls namespace StgSharp.Controls
{ {
public class CharacterLineIndexImage : ControllingItem public class CharacterLineIndexImage : ControllingItem
{ {
private char[] displayIndex; private char[] displayIndex;
private char defaultChar; private char defaultChar;
private Dictionary<char, PlainGeometryMesh> texIndex; private Dictionary<char, PlainGeometryMesh> texIndex;
private int length; private int length;
private PlainGeometryMesh _tittleMesh; private PlainGeometryMesh _tittleMesh;
public CharacterLineIndexImage( public CharacterLineIndexImage(
int length, int length,
char defaultChar, char defaultChar,
PlainGeometryMesh tittleMesh, PlainGeometryMesh tittleMesh,
IEnumerable<(char, PlainGeometryMesh)> indexEnumeration) IEnumerable<(char, PlainGeometryMesh)> indexEnumeration)
{ {
this.length = length; this.length = length;
displayIndex = new char[length]; displayIndex = new char[length];
_tittleMesh = tittleMesh; _tittleMesh = tittleMesh;
texIndex = indexEnumeration.ToDictionary(item => item.Item1, item => item.Item2); texIndex = indexEnumeration.ToDictionary(item => item.Item1, item => item.Item2);
} }
public bool IsEntity public bool IsEntity
{ {
get => true; get => true;
} }
public ReadOnlySpan<Vec4> TextureBox public ReadOnlySpan<Vec4> TextureBox
{ {
get => throw new NotSupportedException(); get => throw new NotSupportedException();
} }
public Rectangle BoundingBox public Rectangle BoundingBox
{ {
get => throw new NotImplementedException(); get => throw new NotImplementedException();
set => throw new NotImplementedException(); set => throw new NotImplementedException();
} }
public Vec2 Position public Vec2 Position
{ {
get => throw new NotImplementedException(); get => throw new NotImplementedException();
set => throw new NotImplementedException(); set => throw new NotImplementedException();
} }
public void Display(string message) public void Display(string message)
{ {
if (string.IsNullOrEmpty(message)) { if (string.IsNullOrEmpty(message)) {
message = string.Empty; message = string.Empty;
} }
string result = (message.Length >= length) ? string result = (message.Length >= length) ?
message.Substring(message.Length - displayIndex.Length) : message.Substring(message.Length - displayIndex.Length) :
message.PadLeft( message.PadLeft(
length, defaultChar); length, defaultChar);
displayIndex = result.ToCharArray(); displayIndex = result.ToCharArray();
} }
public IEnumerator<PlainGeometryMesh> GetEnumerator() public IEnumerator<PlainGeometryMesh> GetEnumerator()
{ {
yield return _tittleMesh; yield return _tittleMesh;
foreach (char item in displayIndex) { foreach (char item in displayIndex) {
yield return texIndex[item]; yield return texIndex[item];
} }
} }
} }
} }
@@ -1,56 +1,56 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ControllingIntem" // file="ControllingIntem"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Geometries; using StgSharp.Geometries;
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Controls namespace StgSharp.Controls
{ {
public interface ControllingItem : IEnumerable<PlainGeometryMesh> public interface ControllingItem : IEnumerable<PlainGeometryMesh>
{ {
public abstract bool IsEntity { get; } public abstract bool IsEntity { get; }
public abstract ReadOnlySpan<Vec4> TextureBox { get; } public abstract ReadOnlySpan<Vec4> TextureBox { get; }
public abstract Rectangle BoundingBox { get; set; } public abstract Rectangle BoundingBox { get; set; }
public abstract Vec2 Position { get; set; } public abstract Vec2 Position { get; set; }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }
} }
} }
@@ -1,70 +1,70 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="DecorationBox.cs" // file="DecorationBox.cs"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload Space // AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved. // Copyright (c) Nitload Space. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction, // files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, // including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, // publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so, // and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions: // subject to the following conditions:
// //
// The above copyright notice and // The above copyright notice and
// this permission notice shall be included in all copies // this permission notice shall be included in all copies
// or substantial portions of the Software. // or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED “AS IS”, // THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH // ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Geometries; using StgSharp.Geometries;
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace StgSharp.Controls namespace StgSharp.Controls
{ {
public class DecorationBox : ControllingItem public class DecorationBox : ControllingItem
{ {
private PlainGeometryMesh renderMesh; private PlainGeometryMesh renderMesh;
public DecorationBox(Rectangle bound, Image texture, Vec2[] texCoord) public DecorationBox(Rectangle bound, Image texture, Vec2[] texCoord)
{ {
renderMesh = new PlainGeometryMesh( renderMesh = new PlainGeometryMesh(
BoundingBox, new TextureProvider(texture, texCoord)); BoundingBox, new TextureProvider(texture, texCoord));
} }
public bool IsEntity => true; public bool IsEntity => true;
public ReadOnlySpan<Vec4> TextureBox public ReadOnlySpan<Vec4> TextureBox
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => renderMesh.TextureCoord; get => renderMesh.TextureCoord;
} }
public Rectangle BoundingBox { get; set; } public Rectangle BoundingBox { get; set; }
public Vec2 Position { get; set; } public Vec2 Position { get; set; }
public IEnumerator<PlainGeometryMesh> GetEnumerator() public IEnumerator<PlainGeometryMesh> GetEnumerator()
{ {
yield return renderMesh; yield return renderMesh;
} }
} }
} }
@@ -1,83 +1,83 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="MarkingLable" // file="MarkingLable"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Controls; using StgSharp.Controls;
using StgSharp.Geometries; using StgSharp.Geometries;
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using StgSharp.Timing; using StgSharp.Timing;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
namespace StgSharp.Controls namespace StgSharp.Controls
{ {
public class MarkingLabel : ControllingItem public class MarkingLabel : ControllingItem
{ {
private PlainGeometryMesh marker; private PlainGeometryMesh marker;
private Vec2 _currentPosition, _movementVec; private Vec2 _currentPosition, _movementVec;
public MarkingLabel(PlainGeometryMesh marker) public MarkingLabel(PlainGeometryMesh marker)
{ {
this.marker = marker; this.marker = marker;
} }
public bool IsEntity => true; public bool IsEntity => true;
public ReadOnlySpan<Vec4> TextureBox public ReadOnlySpan<Vec4> TextureBox
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => marker.TextureCoord; get => marker.TextureCoord;
} }
public Rectangle BoundingBox { get; set; } public Rectangle BoundingBox { get; set; }
public Vec2 Position { get; set; } public Vec2 Position { get; set; }
public IEnumerator<PlainGeometryMesh> GetEnumerator() public IEnumerator<PlainGeometryMesh> GetEnumerator()
{ {
yield return marker; yield return marker;
} }
public void Move(Vec2 movement) public void Move(Vec2 movement)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void MoveTo(Vec2 target) public void MoveTo(Vec2 target)
{ {
Move(target - Position); Move(target - Position);
} }
} }
} }
@@ -1,213 +1,213 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="TriggerButton" // file="TriggerButton"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Controls; using StgSharp.Controls;
using StgSharp.Geometries; using StgSharp.Geometries;
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace StgSharp.Controls namespace StgSharp.Controls
{ {
public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture); public delegate void RenderButtonTextureCallback(ButtonStatus status, float beginTime, in TextureProvider texture);
public enum ButtonStatus public enum ButtonStatus
{ {
Error = 0b0, Error = 0b0,
Disable = 0b1, Disable = 0b1,
Enable = 0b10, Enable = 0b10,
Highlight = 0b100, Highlight = 0b100,
Confirm = 0b1000, Confirm = 0b1000,
DisableToEnable = Disable | Enable, DisableToEnable = Disable | Enable,
EnableToDisable = -(Enable | DisableToEnable), EnableToDisable = -(Enable | DisableToEnable),
EnableToHighlight = Enable | Highlight, EnableToHighlight = Enable | Highlight,
HighlightToEnable = -(Enable | Highlight), HighlightToEnable = -(Enable | Highlight),
HighlightToDisable = -(Highlight | Disable), HighlightToDisable = -(Highlight | Disable),
} }
public class TriggerButton : ControllingItem public class TriggerButton : ControllingItem
{ {
private Action? confirmCallback; private Action? confirmCallback;
private Action? disableCallback; private Action? disableCallback;
#nullable enable #nullable enable
private Action? enableCallback; private Action? enableCallback;
private float _statusBeginTime; private float _statusBeginTime;
private RenderButtonTextureCallback _renderButton; private RenderButtonTextureCallback _renderButton;
private TextureProvider _texture; private TextureProvider _texture;
#nullable restore #nullable restore
public TriggerButton() public TriggerButton()
{ {
CurrentStatus = ButtonStatus.Disable; CurrentStatus = ButtonStatus.Disable;
} }
public event Action ConfirmEvent public event Action ConfirmEvent
{ {
add { confirmCallback += value; } add { confirmCallback += value; }
remove { confirmCallback -= value; } remove { confirmCallback -= value; }
} }
public event Action DisableEvent public event Action DisableEvent
{ {
add { disableCallback += value; } add { disableCallback += value; }
remove { disableCallback -= value; } remove { disableCallback -= value; }
} }
public event Action EnableEvent public event Action EnableEvent
{ {
add { enableCallback += value; } add { enableCallback += value; }
remove { enableCallback -= value; } remove { enableCallback -= value; }
} }
public event RenderButtonTextureCallback RenderButtonTexture public event RenderButtonTextureCallback RenderButtonTexture
{ {
add add
{ {
if (_renderButton == null) if (_renderButton == null)
{ {
_renderButton = value; _renderButton = value;
} else } else
{ {
_renderButton += value; _renderButton += value;
} }
} }
remove remove
{ {
if (_renderButton != null) { if (_renderButton != null) {
_renderButton -= value; _renderButton -= value;
} }
} }
} }
public bool IsHighLighted { get; internal set; } public bool IsHighLighted { get; internal set; }
public bool IsDisabled { get; internal set; } public bool IsDisabled { get; internal set; }
public bool IsEntity => true; public bool IsEntity => true;
public ReadOnlySpan<Vec4> TextureBox public ReadOnlySpan<Vec4> TextureBox
{ {
get => MemoryMarshal.Cast<Vec2, Vec4>(_texture.TextureCoordinate); get => MemoryMarshal.Cast<Vec2, Vec4>(_texture.TextureCoordinate);
} }
public Rectangle BoundingBox { get; set; } public Rectangle BoundingBox { get; set; }
public TriggerButton Left { get; internal set; } public TriggerButton Left { get; internal set; }
public TriggerButton Right { get; internal set; } public TriggerButton Right { get; internal set; }
public TriggerButton Up { get; internal set; } public TriggerButton Up { get; internal set; }
public TriggerButton Down { get; internal set; } public TriggerButton Down { get; internal set; }
public Vec2 Position { get; set; } public Vec2 Position { get; set; }
internal TextureProvider Texture internal TextureProvider Texture
{ {
get => _texture; get => _texture;
set => _texture = value; set => _texture = value;
} }
protected ButtonStatus CurrentStatus { get; set; } protected ButtonStatus CurrentStatus { get; set; }
public void DeHighlight() public void DeHighlight()
{ {
if (CurrentStatus == ButtonStatus.Highlight) { if (CurrentStatus == ButtonStatus.Highlight) {
CurrentStatus = ButtonStatus.HighlightToEnable; CurrentStatus = ButtonStatus.HighlightToEnable;
} }
} }
public void Disable() public void Disable()
{ {
CurrentStatus = CurrentStatus switch CurrentStatus = CurrentStatus switch
{ {
ButtonStatus.Enable => ButtonStatus.EnableToDisable, ButtonStatus.Enable => ButtonStatus.EnableToDisable,
ButtonStatus.Highlight => ButtonStatus.HighlightToDisable, ButtonStatus.Highlight => ButtonStatus.HighlightToDisable,
_ => CurrentStatus, _ => CurrentStatus,
}; };
if (disableCallback != null) { if (disableCallback != null) {
disableCallback(); disableCallback();
} }
} }
public void Enable() public void Enable()
{ {
if (CurrentStatus == ButtonStatus.Disable) if (CurrentStatus == ButtonStatus.Disable)
{ {
CurrentStatus = ButtonStatus.DisableToEnable; CurrentStatus = ButtonStatus.DisableToEnable;
} else } else
{ {
return; return;
} }
if (enableCallback != null) { if (enableCallback != null) {
enableCallback(); enableCallback();
} }
} }
public IEnumerator<PlainGeometryMesh> GetEnumerator() public IEnumerator<PlainGeometryMesh> GetEnumerator()
{ {
_renderButton(CurrentStatus, _statusBeginTime, in _texture); _renderButton(CurrentStatus, _statusBeginTime, in _texture);
yield return new PlainGeometryMesh(this.BoundingBox, _texture); yield return new PlainGeometryMesh(this.BoundingBox, _texture);
} }
public void Highlight() public void Highlight()
{ {
if (CurrentStatus == ButtonStatus.Enable) if (CurrentStatus == ButtonStatus.Enable)
{ {
CurrentStatus |= ButtonStatus.EnableToHighlight; CurrentStatus |= ButtonStatus.EnableToHighlight;
} else } else
{ {
return; return;
} }
if (confirmCallback != null) { if (confirmCallback != null) {
confirmCallback(); confirmCallback();
} }
} }
internal void Init(ButtonStatus status) internal void Init(ButtonStatus status)
{ {
if (CurrentStatus == ButtonStatus.Error) { if (CurrentStatus == ButtonStatus.Error) {
CurrentStatus = status; CurrentStatus = status;
} }
} }
}//----------------------------------- End of class -------------------------------------------- }//----------------------------------- End of class --------------------------------------------
} }
+234 -234
View File
@@ -1,234 +1,234 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="KeyEnum" // file="KeyEnum"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL; using StgSharp.Graphics.OpenGL;
using System; using System;
namespace StgSharp namespace StgSharp
{ {
public enum KeyboardKey : int public enum KeyboardKey : int
{ {
UNKNOWN = -1, UNKNOWN = -1,
None = 0, None = 0,
Space = 32, Space = 32,
Apostrophe = 39/*'*/, Apostrophe = 39/*'*/,
Comma = 44/*,*/, Comma = 44/*,*/,
Minus = 45/*-*/, Minus = 45/*-*/,
Period = 46/*.*/, Period = 46/*.*/,
Slash = 47/*/*/, Slash = 47/*/*/,
Zero = 48, Zero = 48,
One = 49, One = 49,
Two = 50, Two = 50,
Three = 51, Three = 51,
Four = 52, Four = 52,
Five = 53, Five = 53,
Six = 54, Six = 54,
Seven = 55, Seven = 55,
Eight = 56, Eight = 56,
Nine = 57, Nine = 57,
Semicolon = 59/*,*/, Semicolon = 59/*,*/,
Equal = 61/*=*/, Equal = 61/*=*/,
A = 65, A = 65,
B = 66, B = 66,
C = 67, C = 67,
D = 68, D = 68,
E = 69, E = 69,
F = 70, F = 70,
G = 71, G = 71,
H = 72, H = 72,
I = 73, I = 73,
J = 74, J = 74,
K = 75, K = 75,
L = 76, L = 76,
M = 77, M = 77,
N = 78, N = 78,
O = 79, O = 79,
P = 80, P = 80,
Q = 81, Q = 81,
R = 82, R = 82,
S = 83, S = 83,
T = 84, T = 84,
U = 85, U = 85,
V = 86, V = 86,
W = 87, W = 87,
X = 88, X = 88,
Y = 89, Y = 89,
Z = 90, Z = 90,
LeftBracket = 91/*[*/, LeftBracket = 91/*[*/,
BACKSLASH = 92/*\*/, BACKSLASH = 92/*\*/,
RightBracket = 93/*]*/, RightBracket = 93/*]*/,
GraveAccent = 96/*`*/, GraveAccent = 96/*`*/,
World1 = 161/*non-US#1*/, World1 = 161/*non-US#1*/,
World2 = 162/*non-US#2*/, World2 = 162/*non-US#2*/,
Esc = 256, Esc = 256,
Enter = 257, Enter = 257,
Tab = 258, Tab = 258,
Backspace = 259, Backspace = 259,
Insert = 260, Insert = 260,
Delete = 261, Delete = 261,
Right = 262, Right = 262,
Left = 263, Left = 263,
Down = 264, Down = 264,
Up = 265, Up = 265,
PgUp = 266, PgUp = 266,
PgDown = 267, PgDown = 267,
Home = 268, Home = 268,
End = 269, End = 269,
CapsLock = 280, CapsLock = 280,
ScrollLock = 281, ScrollLock = 281,
NumLock = 282, NumLock = 282,
PrintScreen = 283, PrintScreen = 283,
Pause = 284, Pause = 284,
F1 = 290, F1 = 290,
F2 = 291, F2 = 291,
F3 = 292, F3 = 292,
F4 = 293, F4 = 293,
F5 = 294, F5 = 294,
F6 = 295, F6 = 295,
F7 = 296, F7 = 296,
F8 = 297, F8 = 297,
F9 = 298, F9 = 298,
F10 = 299, F10 = 299,
F11 = 300, F11 = 300,
F12 = 301, F12 = 301,
F13 = 302, F13 = 302,
F14 = 303, F14 = 303,
F15 = 304, F15 = 304,
F16 = 305, F16 = 305,
F17 = 306, F17 = 306,
F18 = 307, F18 = 307,
F19 = 308, F19 = 308,
F20 = 309, F20 = 309,
F21 = 310, F21 = 310,
F22 = 311, F22 = 311,
F23 = 312, F23 = 312,
F24 = 313, F24 = 313,
F25 = 314, F25 = 314,
NumPad0 = 320, NumPad0 = 320,
NumPad1 = 321, NumPad1 = 321,
NumPad2 = 322, NumPad2 = 322,
NumPad3 = 323, NumPad3 = 323,
NumPad4 = 324, NumPad4 = 324,
NumPad5 = 325, NumPad5 = 325,
NumPad6 = 326, NumPad6 = 326,
NumPad7 = 327, NumPad7 = 327,
NumPad8 = 328, NumPad8 = 328,
NumPad9 = 329, NumPad9 = 329,
NumPadDec = 330, NumPadDec = 330,
NumPadDiv = 331, NumPadDiv = 331,
NumPadMul = 332, NumPadMul = 332,
NumPadSub = 333, NumPadSub = 333,
NumPadAdd = 334, NumPadAdd = 334,
NumPadAnter = 335, NumPadAnter = 335,
NumPadEqual = 336, NumPadEqual = 336,
LeftShift = 340, LeftShift = 340,
LeftControl = 341, LeftControl = 341,
LeftAlt = 342, LeftAlt = 342,
LeftSuper = 343, LeftSuper = 343,
RightShift = 344, RightShift = 344,
RightControl = 345, RightControl = 345,
RightAlt = 346, RightAlt = 346,
RightSuper = 347, RightSuper = 347,
Menu = 348, Menu = 348,
First = Space, First = Space,
Last = Menu, Last = Menu,
} }
#pragma warning disable CA1707 #pragma warning disable CA1707
#pragma warning disable CA1712 #pragma warning disable CA1712
#pragma warning disable CA1008 #pragma warning disable CA1008
#pragma warning disable CA1027 #pragma warning disable CA1027
public enum Joystick : int public enum Joystick : int
#pragma warning restore CA1027 #pragma warning restore CA1027
{ {
Joystick_1 = FrameworkConstant. JOYSTICK_1, Joystick_1 = FrameworkConstant. JOYSTICK_1,
Joystick_2 = FrameworkConstant. JOYSTICK_2, Joystick_2 = FrameworkConstant. JOYSTICK_2,
Joystick_3 = FrameworkConstant. JOYSTICK_3, Joystick_3 = FrameworkConstant. JOYSTICK_3,
Joystick_4 = FrameworkConstant. JOYSTICK_4, Joystick_4 = FrameworkConstant. JOYSTICK_4,
Joystick_5 = FrameworkConstant. JOYSTICK_5, Joystick_5 = FrameworkConstant. JOYSTICK_5,
Joystick_6 = FrameworkConstant. JOYSTICK_6, Joystick_6 = FrameworkConstant. JOYSTICK_6,
Joystick_7 = FrameworkConstant. JOYSTICK_7, Joystick_7 = FrameworkConstant. JOYSTICK_7,
Joystick_8 = FrameworkConstant. JOYSTICK_8, Joystick_8 = FrameworkConstant. JOYSTICK_8,
Joystick_9 = FrameworkConstant. JOYSTICK_9, Joystick_9 = FrameworkConstant. JOYSTICK_9,
Joystick_10 = FrameworkConstant.JOYSTICK_10, Joystick_10 = FrameworkConstant.JOYSTICK_10,
Joystick_11 = FrameworkConstant.JOYSTICK_11, Joystick_11 = FrameworkConstant.JOYSTICK_11,
Joystick_12 = FrameworkConstant.JOYSTICK_12, Joystick_12 = FrameworkConstant.JOYSTICK_12,
Joystick_13 = FrameworkConstant.JOYSTICK_13, Joystick_13 = FrameworkConstant.JOYSTICK_13,
Joystick_14 = FrameworkConstant.JOYSTICK_14, Joystick_14 = FrameworkConstant.JOYSTICK_14,
Joystick_15 = FrameworkConstant.JOYSTICK_15, Joystick_15 = FrameworkConstant.JOYSTICK_15,
Joystick_16 = FrameworkConstant.JOYSTICK_16, Joystick_16 = FrameworkConstant.JOYSTICK_16,
First = Joystick_1, First = Joystick_1,
Last = Joystick_16 Last = Joystick_16
} }
[System.Flags] [System.Flags]
public enum Mouse : int public enum Mouse : int
{ {
Button1 = 0, Button1 = 0,
Button2 = 1, Button2 = 1,
Button3 = 2, Button3 = 2,
Button4 = 3, Button4 = 3,
Button5 = 4, Button5 = 4,
Button6 = 5, Button6 = 5,
Button7 = 6, Button7 = 6,
Button8 = 7, Button8 = 7,
First = Button1, First = Button1,
Last = Button8, Last = Button8,
Left = Button1, Left = Button1,
Right = Button2, Right = Button2,
Middle = Button3 Middle = Button3
} }
#pragma warning restore CA1707 #pragma warning restore CA1707
#pragma warning restore CA1712 #pragma warning restore CA1712
#pragma warning restore CA7008 #pragma warning restore CA7008
internal enum InputEquipment internal enum InputEquipment
{ {
Keyboard, Keyboard,
Mouse, Mouse,
Joystick Joystick
} }
public enum KeyStatus : int public enum KeyStatus : int
{ {
RELEASE = 0, RELEASE = 0,
PRESS = 1 PRESS = 1
} }
} }
@@ -1,66 +1,66 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="KeyEventAttribute" // file="KeyEventAttribute"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp namespace StgSharp
{ {
[AttributeUsage(AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Method)]
public class KeyEventAttribute : Attribute public class KeyEventAttribute : Attribute
{ {
internal int _equipment; internal int _equipment;
internal int _keyStat; internal int _keyStat;
internal int _keyTarget; internal int _keyTarget;
public KeyEventAttribute(KeyboardKey key, KeyStatus status) public KeyEventAttribute(KeyboardKey key, KeyStatus status)
{ {
_equipment = (int)InputEquipment.Keyboard; _equipment = (int)InputEquipment.Keyboard;
_keyTarget = (int)key; _keyTarget = (int)key;
_keyStat = (int)status; _keyStat = (int)status;
} }
public KeyEventAttribute(Joystick joystick, KeyStatus status) public KeyEventAttribute(Joystick joystick, KeyStatus status)
{ {
_equipment = (int)InputEquipment.Keyboard; _equipment = (int)InputEquipment.Keyboard;
_keyTarget = (int)joystick; _keyTarget = (int)joystick;
_keyStat = (int)status; _keyStat = (int)status;
} }
public KeyEventAttribute(Mouse mouse, KeyStatus status) public KeyEventAttribute(Mouse mouse, KeyStatus status)
{ {
_equipment = (int)InputEquipment.Keyboard; _equipment = (int)InputEquipment.Keyboard;
_keyTarget = (int)mouse; _keyTarget = (int)mouse;
_keyStat = (int)status; _keyStat = (int)status;
} }
} }
} }
@@ -1,42 +1,42 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IClickTrigger" // file="IClickTrigger"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Controlling.UsrActivity namespace StgSharp.Controlling.UsrActivity
{ {
public interface IClickTrigger public interface IClickTrigger
{ {
public int TargetKeyOrButtonID { get; } public int TargetKeyOrButtonID { get; }
public KeyStatus TriggeredStatus { get; } public KeyStatus TriggeredStatus { get; }
} }
} }
@@ -1,86 +1,86 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="JoystickTrigger" // file="JoystickTrigger"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Controlling.UsrActivity namespace StgSharp.Controlling.UsrActivity
{ {
public readonly struct JoystickTrigger : IClickTrigger, IEquatable<JoystickTrigger> public readonly struct JoystickTrigger : IClickTrigger, IEquatable<JoystickTrigger>
{ {
private readonly Joystick _stick; private readonly Joystick _stick;
private readonly KeyStatus _status; private readonly KeyStatus _status;
public JoystickTrigger(Joystick targetKey, KeyStatus status) public JoystickTrigger(Joystick targetKey, KeyStatus status)
{ {
this._stick = targetKey; this._stick = targetKey;
_status = status; _status = status;
} }
public int TargetKeyOrButtonID => (int)_stick; public int TargetKeyOrButtonID => (int)_stick;
public Joystick Stick public Joystick Stick
{ {
get => _stick; get => _stick;
} }
public KeyStatus TriggeredStatus => _status; public KeyStatus TriggeredStatus => _status;
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return base.Equals(obj); return base.Equals(obj);
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return ((int)_stick) + (17 * ((int)_status)); return ((int)_stick) + (17 * ((int)_status));
} }
public override string ToString() public override string ToString()
{ {
return $"Key {_stick} triggered when {_status}"; return $"Key {_stick} triggered when {_status}";
} }
public static bool operator !=(JoystickTrigger left, JoystickTrigger right) public static bool operator !=(JoystickTrigger left, JoystickTrigger right)
{ {
return !(left == right); return !(left == right);
} }
public static bool operator ==(JoystickTrigger left, JoystickTrigger right) public static bool operator ==(JoystickTrigger left, JoystickTrigger right)
{ {
return (left._status == right._status) && (left._stick == right._stick); return (left._status == right._status) && (left._stick == right._stick);
} }
bool IEquatable<JoystickTrigger>.Equals(JoystickTrigger other) bool IEquatable<JoystickTrigger>.Equals(JoystickTrigger other)
{ {
return other == this; return other == this;
} }
} }
} }
@@ -1,82 +1,82 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="KeyTrigger" // file="KeyTrigger"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.Common; using System.Data.Common;
using System.Text; using System.Text;
namespace StgSharp.Controlling.UsrActivity namespace StgSharp.Controlling.UsrActivity
{ {
public readonly struct KeyTrigger : IClickTrigger, IEquatable<KeyTrigger> public readonly struct KeyTrigger : IClickTrigger, IEquatable<KeyTrigger>
{ {
private readonly KeyboardKey _targetKey; private readonly KeyboardKey _targetKey;
private readonly KeyStatus _triggerStat; private readonly KeyStatus _triggerStat;
public KeyTrigger(KeyboardKey targetKey, KeyStatus targetStat) public KeyTrigger(KeyboardKey targetKey, KeyStatus targetStat)
{ {
this._targetKey = targetKey; this._targetKey = targetKey;
this._triggerStat = targetStat; this._triggerStat = targetStat;
} }
public int TargetKeyOrButtonID => (int)_targetKey; public int TargetKeyOrButtonID => (int)_targetKey;
public KeyStatus TriggeredStatus => _triggerStat; public KeyStatus TriggeredStatus => _triggerStat;
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return base.Equals(obj); return base.Equals(obj);
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return ((int)_targetKey) + (17 * ((int)_triggerStat)); return ((int)_targetKey) + (17 * ((int)_triggerStat));
} }
public override string ToString() public override string ToString()
{ {
return $"Key {_targetKey} triggered when {_triggerStat}"; return $"Key {_targetKey} triggered when {_triggerStat}";
} }
public static bool operator !=(KeyTrigger left, KeyTrigger right) public static bool operator !=(KeyTrigger left, KeyTrigger right)
{ {
return !(left == right); return !(left == right);
} }
public static bool operator ==(KeyTrigger left, KeyTrigger right) public static bool operator ==(KeyTrigger left, KeyTrigger right)
{ {
return (left._triggerStat == right._triggerStat) && (left._targetKey == right._targetKey); return (left._triggerStat == right._triggerStat) && (left._targetKey == right._targetKey);
} }
bool IEquatable<KeyTrigger>.Equals(KeyTrigger other) bool IEquatable<KeyTrigger>.Equals(KeyTrigger other)
{ {
return other == this; return other == this;
} }
} }
} }
@@ -1,69 +1,69 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="MouseTrigger" // file="MouseTrigger"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.SymbolStore; using System.Diagnostics.SymbolStore;
using System.Text; using System.Text;
namespace StgSharp.Controlling.UsrActivity namespace StgSharp.Controlling.UsrActivity
{ {
public readonly struct MouseTrigger : IClickTrigger, IEquatable<MouseTrigger> public readonly struct MouseTrigger : IClickTrigger, IEquatable<MouseTrigger>
{ {
private readonly KeyStatus _status; private readonly KeyStatus _status;
private readonly Mouse _mouse; private readonly Mouse _mouse;
public MouseTrigger(Mouse mouse, KeyStatus status) public MouseTrigger(Mouse mouse, KeyStatus status)
{ {
_mouse = mouse; _mouse = mouse;
_status = status; _status = status;
} }
public int TargetKeyOrButtonID => (int)_mouse; public int TargetKeyOrButtonID => (int)_mouse;
public KeyStatus TriggeredStatus => _status; public KeyStatus TriggeredStatus => _status;
public bool Equals(MouseTrigger other) public bool Equals(MouseTrigger other)
{ {
return this == other; return this == other;
} }
public static bool operator !=(MouseTrigger left, MouseTrigger right) public static bool operator !=(MouseTrigger left, MouseTrigger right)
{ {
return left._mouse != right._mouse || left._status != right._status; return left._mouse != right._mouse || left._status != right._status;
} }
public static bool operator ==(MouseTrigger left, MouseTrigger right) public static bool operator ==(MouseTrigger left, MouseTrigger right)
{ {
return left._mouse == right._mouse && left._status == right._status; return left._mouse == right._mouse && left._status == right._status;
} }
} }
} }
@@ -1,88 +1,88 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="TriggetFactory" // file="TriggetFactory"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Controlling.UsrActivity namespace StgSharp.Controlling.UsrActivity
{ {
public static class TriggetBuilder public static class TriggetBuilder
{ {
private const int JoystickMax = (int)Joystick.Last + 1; private const int JoystickMax = (int)Joystick.Last + 1;
private const int JoystickMin = (int)Joystick.First - 1; private const int JoystickMin = (int)Joystick.First - 1;
private const int KeyboardMax = (int)KeyboardKey.Last + 1; private const int KeyboardMax = (int)KeyboardKey.Last + 1;
private const int KeyboardMin = (int)KeyboardKey.First - 1; private const int KeyboardMin = (int)KeyboardKey.First - 1;
private const int MouseMax = (int)Mouse.Last + 1; private const int MouseMax = (int)Mouse.Last + 1;
private const int MouseMin = (int)Mouse.First - 1; private const int MouseMin = (int)Mouse.First - 1;
private static KeyTrigger keyboardtemp; private static KeyTrigger keyboardtemp;
private static MouseTrigger mousetemp; private static MouseTrigger mousetemp;
public static JoystickTrigger BuildJoystickClickTrigger(int keyCode, KeyStatus status) public static JoystickTrigger BuildJoystickClickTrigger(int keyCode, KeyStatus status)
{ {
if (keyCode > MouseMin && keyCode < MouseMax) { if (keyCode > MouseMin && keyCode < MouseMax) {
return new JoystickTrigger((Joystick)keyCode, status); return new JoystickTrigger((Joystick)keyCode, status);
} }
throw new InvalidOperationException("Known key code or key is not on joystick."); throw new InvalidOperationException("Known key code or key is not on joystick.");
} }
public static KeyTrigger BuildKeyboardClickTrigger(int keyCode, KeyStatus status) public static KeyTrigger BuildKeyboardClickTrigger(int keyCode, KeyStatus status)
{ {
if (keyCode > KeyboardMin && keyCode < KeyboardMax) { if (keyCode > KeyboardMin && keyCode < KeyboardMax) {
return new KeyTrigger((KeyboardKey)keyCode, status); return new KeyTrigger((KeyboardKey)keyCode, status);
} }
throw new InvalidOperationException("Known key code or kay is not on keyboard."); throw new InvalidOperationException("Known key code or kay is not on keyboard.");
} }
public static MouseTrigger BuildMouseClickTrigger(int keyCode, KeyStatus status) public static MouseTrigger BuildMouseClickTrigger(int keyCode, KeyStatus status)
{ {
if (keyCode >= MouseMin && keyCode <= MouseMax) { if (keyCode >= MouseMin && keyCode <= MouseMax) {
return new MouseTrigger((Mouse)keyCode, status); return new MouseTrigger((Mouse)keyCode, status);
} }
throw new InvalidOperationException("Known key code or key is not on mouse."); throw new InvalidOperationException("Known key code or key is not on mouse.");
} }
public static IClickTrigger BuildTrigger(int keyCode, KeyStatus status) public static IClickTrigger BuildTrigger(int keyCode, KeyStatus status)
{ {
if (keyCode > KeyboardMin && keyCode < KeyboardMax) { if (keyCode > KeyboardMin && keyCode < KeyboardMax) {
return new KeyTrigger((KeyboardKey)keyCode, status); return new KeyTrigger((KeyboardKey)keyCode, status);
} }
if (keyCode > JoystickMin && keyCode < JoystickMax) { if (keyCode > JoystickMin && keyCode < JoystickMax) {
return new JoystickTrigger((Joystick)keyCode, status); return new JoystickTrigger((Joystick)keyCode, status);
} }
if (keyCode >= MouseMin && keyCode <= MouseMax) { if (keyCode >= MouseMin && keyCode <= MouseMax) {
return new MouseTrigger((Mouse)keyCode, status); return new MouseTrigger((Mouse)keyCode, status);
} }
throw new InvalidOperationException("Known key code."); throw new InvalidOperationException("Known key code.");
} }
} }
} }
+124 -124
View File
@@ -1,125 +1,125 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Counter" // file="Counter"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Numerics; using System.Numerics;
namespace StgSharp namespace StgSharp
{ {
public class Counter<T> where T : unmanaged, INumber<T> public class Counter<T> where T : unmanaged, INumber<T>
{ {
internal dynamic _value; internal dynamic _value;
internal readonly T _defaultDecrement; internal readonly T _defaultDecrement;
internal readonly T _defaultIncrement; internal readonly T _defaultIncrement;
internal readonly T _defaultValue; internal readonly T _defaultValue;
public Counter( public Counter(
T defaultValue, T defaultValue,
T defaultIncrement, T defaultIncrement,
T defaultDecrement T defaultDecrement
) )
{ {
_value = defaultValue; _value = defaultValue;
_defaultValue = defaultValue; _defaultValue = defaultValue;
_defaultIncrement = defaultIncrement; _defaultIncrement = defaultIncrement;
_defaultDecrement = defaultDecrement; _defaultDecrement = defaultDecrement;
} }
public T DecrementSpan => _defaultDecrement; public T DecrementSpan => _defaultDecrement;
public T IncrementSpan => _defaultIncrement; public T IncrementSpan => _defaultIncrement;
public T CurrentSpan => _value - _defaultValue; public T CurrentSpan => _value - _defaultValue;
public T Value public T Value
{ {
get => _value; get => _value;
set => _value = value; set => _value = value;
} }
public void Add( public void Add(
T value T value
) )
{ {
_value += value; _value += value;
} }
public void QuickAdd() public void QuickAdd()
{ {
_value += _defaultIncrement; _value += _defaultIncrement;
} }
public void QuickSub() public void QuickSub()
{ {
_value -= _defaultDecrement; _value -= _defaultDecrement;
} }
public void Reset() public void Reset()
{ {
_value = _defaultValue; _value = _defaultValue;
} }
public void Sub( public void Sub(
T value T value
) )
{ {
_value -= value; _value -= value;
} }
public override string ToString() => Value.ToString(); public override string ToString() => Value.ToString();
public static Counter<T> operator --( public static Counter<T> operator --(
Counter<T> counter Counter<T> counter
) )
{ {
counter?.QuickSub(); counter?.QuickSub();
return counter; return counter;
} }
public static Counter<T> operator ++( public static Counter<T> operator ++(
Counter<T> counter Counter<T> counter
) )
{ {
counter?.QuickAdd(); counter?.QuickAdd();
return counter; return counter;
} }
public static implicit operator T( public static implicit operator T(
Counter<T> counter Counter<T> counter
) )
{ {
return counter switch return counter switch
{ {
null => T.Zero, null => T.Zero,
_ => counter.Value _ => counter.Value
}; };
} }
} }
} }
+39 -39
View File
@@ -1,39 +1,39 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="root" // file="root"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Internal; using StgSharp.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp namespace StgSharp
{ {
public static unsafe partial class World { }//------------------ end of class --------------------- public static unsafe partial class World { }//------------------ end of class ---------------------
} }
+144 -144
View File
@@ -1,144 +1,144 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="RandomGenerator" // file="RandomGenerator"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.HighPerformance; using StgSharp.HighPerformance;
using System; using System;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Xml.Serialization; using System.Xml.Serialization;
namespace StgSharp.Data namespace StgSharp.Data
{ {
public unsafe class RandomGenerator public unsafe class RandomGenerator
{ {
private byte[] currentKey; private byte[] currentKey;
private readonly byte[] originKey; private readonly byte[] originKey;
public RandomGenerator() : this(DateTime.UtcNow.ToBinary()) { } public RandomGenerator() : this(DateTime.UtcNow.ToBinary()) { }
public RandomGenerator(object source) public RandomGenerator(object source)
{ {
ArgumentNullException.ThrowIfNull(source); ArgumentNullException.ThrowIfNull(source);
XmlSerializer s = new(source.GetType()); XmlSerializer s = new(source.GetType());
using (StringWriter sw = new()) using (StringWriter sw = new())
{ {
s.Serialize(sw, source); s.Serialize(sw, source);
string data = sw.ToString(); string data = sw.ToString();
originKey = Encoding.Unicode.GetBytes(data); originKey = Encoding.Unicode.GetBytes(data);
} }
currentKey = [ currentKey = [
0, 0,
0, 0,
0, 0,
0 0
]; ];
fixed (byte* o = originKey, c = currentKey) { fixed (byte* o = originKey, c = currentKey) {
*(int*)c = UnsafeCompute.CityHashSimplify((char*)o, 0, originKey.Length / 2); *(int*)c = UnsafeCompute.CityHashSimplify((char*)o, 0, originKey.Length / 2);
} }
TotalGeneratedRandom = 0; TotalGeneratedRandom = 0;
} }
public int TotalGeneratedRandom public int TotalGeneratedRandom
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get; get;
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private set; private set;
} }
public unsafe int GenRandomInt() public unsafe int GenRandomInt()
{ {
uint source = PrivateRand(); uint source = PrivateRand();
TotalGeneratedRandom++; TotalGeneratedRandom++;
M64 m = new M64(); M64 m = new M64();
m.Member<uint>(0) = source; m.Member<uint>(0) = source;
m.Member<uint>(1) = source; m.Member<uint>(1) = source;
return (m << (TotalGeneratedRandom % 32)).Member<int>(1); return (m << (TotalGeneratedRandom % 32)).Member<int>(1);
} }
public byte GenRandomInt8() public byte GenRandomInt8()
{ {
TotalGeneratedRandom++; TotalGeneratedRandom++;
if (TotalGeneratedRandom % 4 == 0) { if (TotalGeneratedRandom % 4 == 0) {
PrivateRand(); PrivateRand();
} }
return currentKey[TotalGeneratedRandom % 4]; return currentKey[TotalGeneratedRandom % 4];
} }
public float GenRandomSingle() public float GenRandomSingle()
{ {
TotalGeneratedRandom++; TotalGeneratedRandom++;
while (true) while (true)
{ {
uint uint
temp0 = PrivateRand(), temp0 = PrivateRand(),
temp1 = PrivateRand(); temp1 = PrivateRand();
if (temp0 * temp1 != 0) if (temp0 * temp1 != 0)
{ {
float ret = temp0 % temp1 * 1.0f / temp1; float ret = temp0 % temp1 * 1.0f / temp1;
if (ret < 0.335f) if (ret < 0.335f)
{ {
ret = ret * ((ret * (-0.7811934f)) + 1.4489113f); ret = ret * ((ret * (-0.7811934f)) + 1.4489113f);
} else } else
{ {
ret = (ret * ((ret * (-0.1158368f)) + 1.0580600f)) + 0.0590584f; ret = (ret * ((ret * (-0.1158368f)) + 1.0580600f)) + 0.0590584f;
} }
if (ret > 1) if (ret > 1)
{ {
continue; continue;
} }
return ret; return ret;
} }
} }
} }
public void Reset() public void Reset()
{ {
currentKey = originKey; currentKey = originKey;
TotalGeneratedRandom = 0; TotalGeneratedRandom = 0;
} }
private unsafe uint PrivateRand() private unsafe uint PrivateRand()
{ {
uint ret; uint ret;
fixed (byte* bptr = currentKey) fixed (byte* bptr = currentKey)
{ {
*(int*)bptr = UnsafeCompute.CityHashSimplify((char*)bptr, currentKey.Length / 2); *(int*)bptr = UnsafeCompute.CityHashSimplify((char*)bptr, currentKey.Length / 2);
ret = *(uint*)bptr; ret = *(uint*)bptr;
} }
// Console.WriteLine(ret.ToString(16)); // Console.WriteLine(ret.ToString(16));
return ret; return ret;
} }
} }
} }
+44 -44
View File
@@ -1,44 +1,44 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Area" // file="Area"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Internal.FileIO; using StgSharp.Internal.FileIO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Internal namespace StgSharp.Internal
{ {
/// <summary> /// <summary>
/// An independent storage area, used as the only folder type in root folder. Contains several /// An independent storage area, used as the only folder type in root folder. Contains several
/// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see /// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see
/// cref="SSD" />s in certain RAID mode. /// cref="SSD" />s in certain RAID mode.
/// </summary> /// </summary>
public partial class Area { } public partial class Area { }
} }
+77 -77
View File
@@ -1,77 +1,77 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="DataHead" // file="DataHead"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.HighPerformance; using StgSharp.HighPerformance;
using System; using System;
using System.Numerics; using System.Numerics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace StgSharp.Internal namespace StgSharp.Internal
{ {
[StructLayout(LayoutKind.Explicit, Size = 16)] [StructLayout(LayoutKind.Explicit, Size = 16)]
public struct SSDSegmentHead public struct SSDSegmentHead
{ {
[FieldOffset(12)] internal byte size; [FieldOffset(12)] internal byte size;
[FieldOffset(0)] internal M128 data; [FieldOffset(0)] internal M128 data;
[FieldOffset(13)] public byte selfDefine_1; [FieldOffset(13)] public byte selfDefine_1;
[FieldOffset(14)] public byte selfDefine_2; [FieldOffset(14)] public byte selfDefine_2;
[FieldOffset(15)] public byte selfDefine_3; [FieldOffset(15)] public byte selfDefine_3;
[FieldOffset(0)] public int globalID; [FieldOffset(0)] public int globalID;
[FieldOffset(4)] public int nextID; [FieldOffset(4)] public int nextID;
[FieldOffset(8)] public int previousHash; [FieldOffset(8)] public int previousHash;
public int Size public int Size
{ {
get => ((int)size) + 1; get => ((int)size) + 1;
set set
{ {
if ((value > 256) || (value < 0)) { if ((value > 256) || (value < 0)) {
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
size = (byte)(value - 1); size = (byte)(value - 1);
} }
} }
public unsafe byte[] GetBytes() public unsafe byte[] GetBytes()
{ {
byte[] ret = new byte[16]; byte[] ret = new byte[16];
fixed (M128* vptr = &data) fixed (M128* vptr = &data)
{ {
byte* bptr = (byte*)vptr; byte* bptr = (byte*)vptr;
for (int i = 0; i < 15; i++) { for (int i = 0; i < 15; i++) {
ret[i] = *bptr; ret[i] = *bptr;
} }
} }
return ret; return ret;
} }
} }
} }
+186 -186
View File
@@ -1,186 +1,186 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="DataSegment" // file="DataSegment"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.HighPerformance; using StgSharp.HighPerformance;
using StgSharp.HighPerformance; using StgSharp.HighPerformance;
using StgSharp.Internal.Intrinsic; using StgSharp.Internal.Intrinsic;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Internal namespace StgSharp.Internal
{ {
[StructLayout(LayoutKind.Explicit, Size = World.ssdSegmentLength * 16)] [StructLayout(LayoutKind.Explicit, Size = World.ssdSegmentLength * 16)]
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment> public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
{ {
[FieldOffset(16)] public fixed byte Data[16 * (World.ssdSegmentLength - 1)]; [FieldOffset(16)] public fixed byte Data[16 * (World.ssdSegmentLength - 1)];
[FieldOffset(12)] public int DataHash; [FieldOffset(12)] public int DataHash;
[FieldOffset(8)] public int PreviousHash; [FieldOffset(8)] public int PreviousHash;
[FieldOffset(0 * 16)] public SSDSegmentHead Head; [FieldOffset(0 * 16)] public SSDSegmentHead Head;
public SSDSegment(int previousHash) public SSDSegment(int previousHash)
{ {
this.PreviousHash = previousHash; this.PreviousHash = previousHash;
} }
public byte this[int index] public byte this[int index]
{ {
get get
{ {
if (index > (16 * (World.ssdSegmentLength - 1)) - 1) { if (index > (16 * (World.ssdSegmentLength - 1)) - 1) {
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
} }
return Data[index]; return Data[index];
} }
set set
{ {
if (index > (16 * (World.ssdSegmentLength - 1)) - 1) { if (index > (16 * (World.ssdSegmentLength - 1)) - 1) {
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
} }
Data[index] = value; Data[index] = value;
} }
} }
public int ID public int ID
{ {
get { return Head.globalID; } get { return Head.globalID; }
set { Head.globalID = value; } set { Head.globalID = value; }
} }
public short Size => Head.size; public short Size => Head.size;
public void FillRandomBytes(int begin) public void FillRandomBytes(int begin)
{ {
if (begin > 255) { if (begin > 255) {
return; return;
} }
for (int i = begin; i < 255; i++) { for (int i = begin; i < 255; i++) {
Data[i] = Scalar.Random<byte>(); Data[i] = Scalar.Random<byte>();
} }
} }
public static SSDSegment FromStream(byte[] stream) public static SSDSegment FromStream(byte[] stream)
{ {
if (stream.Length != 16 * World.ssdSegmentLength) { if (stream.Length != 16 * World.ssdSegmentLength) {
throw new ArgumentException(); throw new ArgumentException();
} }
SSDSegment ret = new SSDSegment(); SSDSegment ret = new SSDSegment();
fixed (byte* bptr = stream) fixed (byte* bptr = stream)
{ {
ret.Head.data = *(M128*)bptr; ret.Head.data = *(M128*)bptr;
for (int i = 1; i < World.ssdSegmentLength; i++) { for (int i = 1; i < World.ssdSegmentLength; i++) {
ret.WriteData<M128>(i - 1, *(M128*)(bptr + (16 * i))); ret.WriteData<M128>(i - 1, *(M128*)(bptr + (16 * i)));
} }
} }
return ret; return ret;
} }
public byte[] GetBytes() public byte[] GetBytes()
{ {
byte[] ret = new byte[16 * World.ssdSegmentLength]; byte[] ret = new byte[16 * World.ssdSegmentLength];
fixed (M128* mptr = &Head.data) fixed (M128* mptr = &Head.data)
{ {
fixed (byte* aptr = ret) fixed (byte* aptr = ret)
{ {
Vector4* vsptr = (Vector4*)mptr; Vector4* vsptr = (Vector4*)mptr;
Vector4* vtptr = (Vector4*)aptr; Vector4* vtptr = (Vector4*)aptr;
for (int i = 0; i < 18; i++) { for (int i = 0; i < 18; i++) {
*(vtptr + i) = *(vsptr + i); *(vtptr + i) = *(vsptr + i);
} }
} }
} }
return ret; return ret;
} }
public int GetDataHash() public int GetDataHash()
{ {
Vector4 v = Vector4.One; Vector4 v = Vector4.One;
fixed (M128* mptr = &Head.data) fixed (M128* mptr = &Head.data)
{ {
Vector4* vptr = (Vector4*)mptr; Vector4* vptr = (Vector4*)mptr;
for (int i = 0; i < World.ssdSegmentLength - 1; i += 1) { for (int i = 0; i < World.ssdSegmentLength - 1; i += 1) {
v += (*vptr) * 31; v += (*vptr) * 31;
} }
} }
M128 m = new M128(v); M128 m = new M128(v);
DataHash = m.Vec.GetHashCode(); DataHash = m.Vec.GetHashCode();
return DataHash; return DataHash;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
int ret = 17; int ret = 17;
fixed (M128* mptr = &Head.data) fixed (M128* mptr = &Head.data)
{ {
Vector4* vptr = (Vector4*)mptr; Vector4* vptr = (Vector4*)mptr;
for (int i = 0; i < World.ssdSegmentLength; i++) { for (int i = 0; i < World.ssdSegmentLength; i++) {
ret = (ret + (*vptr).GetHashCode()) * 31; ret = (ret + (*vptr).GetHashCode()) * 31;
} }
} }
return ret; return ret;
} }
public unsafe T ReadData<T>(int index) where T: unmanaged public unsafe T ReadData<T>(int index) where T: unmanaged
{ {
fixed (byte* bptr = Data) fixed (byte* bptr = Data)
{ {
T* tptr = (T*)bptr; T* tptr = (T*)bptr;
return *(tptr + index); return *(tptr + index);
} }
} }
public unsafe void WriteData<T>(int index, T value) where T: unmanaged public unsafe void WriteData<T>(int index, T value) where T: unmanaged
{ {
fixed (byte* bptr = Data) fixed (byte* bptr = Data)
{ {
T* tptr = (T*)bptr; T* tptr = (T*)bptr;
*(tptr + index) = value; *(tptr + index) = value;
} }
} }
int IComparable<int>.CompareTo(int other) int IComparable<int>.CompareTo(int other)
{ {
return ID.CompareTo(other); return ID.CompareTo(other);
} }
int IComparable<SSDSegment>.CompareTo(SSDSegment other) int IComparable<SSDSegment>.CompareTo(SSDSegment other)
{ {
return ID.CompareTo(other.ID); return ID.CompareTo(other.ID);
} }
} }
} }
+64 -64
View File
@@ -1,64 +1,64 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="SSD" // file="SSD"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Internal.FileIO; using StgSharp.Internal.FileIO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
namespace StgSharp.Internal namespace StgSharp.Internal
{ {
public partial class SSD public partial class SSD
{ {
private Dictionary<string, SSDraw> fileList; private Dictionary<string, SSDraw> fileList;
private FileStream file; private FileStream file;
private SSDrawHead head; private SSDrawHead head;
public SSD() public SSD()
{ {
fileList = new Dictionary<string, SSDraw>(); fileList = new Dictionary<string, SSDraw>();
} }
public SSD(FileStream fileStream) public SSD(FileStream fileStream)
{ {
fileList = new Dictionary<string, SSDraw>(); fileList = new Dictionary<string, SSDraw>();
file = fileStream; file = fileStream;
} }
public static SSD FromFile(string fileRoute) public static SSD FromFile(string fileRoute)
{ {
return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read)) return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read))
{ {
}; };
} }
} }
} }
+77 -77
View File
@@ -1,77 +1,77 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="SSDVirtualFolder" // file="SSDVirtualFolder"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Internal.FileIO; using StgSharp.Internal.FileIO;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Internal namespace StgSharp.Internal
{ {
public class SSDFolder : ISSDSerializable public class SSDFolder : ISSDSerializable
{ {
internal Dictionary<string, SSDFolder> folders; internal Dictionary<string, SSDFolder> folders;
internal int _folderID; internal int _folderID;
internal string _name; internal string _name;
internal SSDFolder() internal SSDFolder()
{ {
folders = new Dictionary<string, SSDFolder>(); folders = new Dictionary<string, SSDFolder>();
} }
internal SSDFolder(string name) internal SSDFolder(string name)
{ {
if (name == "root") { if (name == "root") {
throw new ArgumentException( throw new ArgumentException(
"Name cannot be root," + "it is preserved for root file indexer."); "Name cannot be root," + "it is preserved for root file indexer.");
} }
if (name == "default") { if (name == "default") {
throw new ArgumentException( throw new ArgumentException(
"Name cannot be default," + "it is preserved for default file id provider."); "Name cannot be default," + "it is preserved for default file id provider.");
} }
_name = name; _name = name;
folders = new Dictionary<string, SSDFolder>(); folders = new Dictionary<string, SSDFolder>();
} }
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder; public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
public void FromBytes(byte[] stream) public void FromBytes(byte[] stream)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
// TODO TOUGH TO Get Bytes from virtual folders // TODO TOUGH TO Get Bytes from virtual folders
public byte[] GetBytes() public byte[] GetBytes()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
} }
+68 -68
View File
@@ -1,68 +1,68 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="SSDraw" // file="SSDraw"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Graphics.ShaderEdit; using StgSharp.Graphics.ShaderEdit;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Xml.Serialization; using System.Xml.Serialization;
namespace StgSharp.Internal.FileIO namespace StgSharp.Internal.FileIO
{ {
public class SSDraw public class SSDraw
{ {
private byte[] data; private byte[] data;
public SSDraw(string name, Stream streamSource) public SSDraw(string name, Stream streamSource)
{ {
if ((streamSource == null) || (streamSource.Length == 0)) { if ((streamSource == null) || (streamSource.Length == 0)) {
throw new ArgumentNullException(nameof(streamSource)); throw new ArgumentNullException(nameof(streamSource));
} }
Name = name; Name = name;
data = new byte[streamSource.Length]; data = new byte[streamSource.Length];
streamSource.Read(data.AsSpan()); streamSource.Read(data.AsSpan());
} }
public SSDrawHead Head { get; set; } public SSDrawHead Head { get; set; }
public string Name { get; set; } public string Name { get; set; }
} }
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)] [StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
public unsafe struct SSDrawHead { } public unsafe struct SSDrawHead { }
} }
+38 -38
View File
@@ -1,38 +1,38 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Define" // file="Define"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Internal namespace StgSharp.Internal
{ {
/// <summary> /// <summary>
/// A class contains a sets of methods to serialize several types /// A class contains a sets of methods to serialize several types
/// </summary> /// </summary>
public static partial class Serializer { } public static partial class Serializer { }
} }
+102 -102
View File
@@ -1,103 +1,103 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ISSDSerializable" // file="ISSDSerializable"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Internal namespace StgSharp.Internal
{ {
public interface ISSDSerializable public interface ISSDSerializable
{ {
public SerializableTypeCode SSDTypeCode { get; } public SerializableTypeCode SSDTypeCode { get; }
public byte[] GetBytes(); public byte[] GetBytes();
internal void FromBytes(byte[] stream); internal void FromBytes(byte[] stream);
} }
public enum SerializableTypeCode public enum SerializableTypeCode
{ {
Unknown = 0, Unknown = 0,
IndexTable = 1, IndexTable = 1,
PixelImage = 2, PixelImage = 2,
VectorImage = 3, VectorImage = 3,
Audio = 4, Audio = 4,
Shader = 5, Shader = 5,
Text = 6, Text = 6,
RawData = 7, RawData = 7,
VirtualFolder = int.MaxValue, VirtualFolder = int.MaxValue,
} }
public static partial class Serializer public static partial class Serializer
{ {
public static T Deserialize<T>(byte[] stream) where T: ISSDSerializable public static T Deserialize<T>(byte[] stream) where T: ISSDSerializable
{ {
T serializableObject = Activator.CreateInstance<T>(); T serializableObject = Activator.CreateInstance<T>();
serializableObject.FromBytes(stream); serializableObject.FromBytes(stream);
return serializableObject; return serializableObject;
} }
public static string GetNameTail(SerializableTypeCode typeCode) public static string GetNameTail(SerializableTypeCode typeCode)
{ {
switch (typeCode) switch (typeCode)
{ {
case SerializableTypeCode.IndexTable: case SerializableTypeCode.IndexTable:
return "_idt"; return "_idt";
case SerializableTypeCode.PixelImage: case SerializableTypeCode.PixelImage:
return "_pim"; return "_pim";
case SerializableTypeCode.VectorImage: case SerializableTypeCode.VectorImage:
return "_vim"; return "_vim";
case SerializableTypeCode.Audio: case SerializableTypeCode.Audio:
return "_wav"; return "_wav";
case SerializableTypeCode.Shader: case SerializableTypeCode.Shader:
return "_gls"; return "_gls";
case SerializableTypeCode.Text: case SerializableTypeCode.Text:
return "_txt"; return "_txt";
case SerializableTypeCode.RawData: case SerializableTypeCode.RawData:
return "_raw"; return "_raw";
case SerializableTypeCode.VirtualFolder: case SerializableTypeCode.VirtualFolder:
return "_fod"; return "_fod";
default: default:
throw new ArgumentException("Unknown file type"); throw new ArgumentException("Unknown file type");
} }
} }
public static byte[] Serialize(ISSDSerializable serializableObject) public static byte[] Serialize(ISSDSerializable serializableObject)
{ {
return serializableObject.GetBytes(); return serializableObject.GetBytes();
} }
} }
} }
+91 -91
View File
@@ -1,91 +1,91 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ValueBox" // file="ValueBox"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Data namespace StgSharp.Data
{ {
public interface IValueBox public interface IValueBox
{ {
ref object ValueReference { get; } ref object ValueReference { get; }
static virtual IValueBox<T> AsGeneric<T>(IValueBox box) where T: unmanaged static virtual IValueBox<T> AsGeneric<T>(IValueBox box) where T: unmanaged
{ {
if (box is not IValueBox<T> genericBox) { if (box is not IValueBox<T> genericBox) {
return null; return null;
} }
return genericBox; return genericBox;
} }
static virtual bool IsGeneric<T>(IValueBox box) where T: unmanaged static virtual bool IsGeneric<T>(IValueBox box) where T: unmanaged
{ {
return box is IValueBox<T>; return box is IValueBox<T>;
} }
} }
public interface IValueBox<T> where T: unmanaged public interface IValueBox<T> where T: unmanaged
{ {
T Value { get; set; } T Value { get; set; }
} }
/// <summary> /// <summary>
/// A class attempt to reduce cost of boxing, though still a bit slower than direct access to /// A class attempt to reduce cost of boxing, though still a bit slower than direct access to
/// _origin value type instance. /// _origin value type instance.
/// </summary> /// </summary>
/// <typeparam name="T"> /// <typeparam name="T">
/// Type of instance to be boxed. /// Type of instance to be boxed.
/// </typeparam> /// </typeparam>
public class ValueBox<T> : IValueBox, IValueBox<T> where T: unmanaged public class ValueBox<T> : IValueBox, IValueBox<T> where T: unmanaged
{ {
private T _value; private T _value;
public ValueBox(T value) public ValueBox(T value)
{ {
_value = value; _value = value;
} }
public ref object ValueReference => ref Unsafe.As<T, object>(ref _value); public ref object ValueReference => ref Unsafe.As<T, object>(ref _value);
public T Value public T Value
{ {
get => _value; get => _value;
set => _value = value; set => _value = value;
} }
} }
} }
+190 -190
View File
@@ -1,190 +1,190 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Dialogue" // file="Dialogue"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Pipes; using System.IO.Pipes;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
namespace StgSharp namespace StgSharp
{ {
public static class Dialogue public static class Dialogue
{ {
private static Process? _dialogueProcess; private static Process? _dialogueProcess;
private static AnonymousPipeServerStream _dialogueClientPipe,_dialogueServerPipe; private static AnonymousPipeServerStream _dialogueClientPipe,_dialogueServerPipe;
private static int _readAndWriteThreadId; private static int _readAndWriteThreadId;
private static ProcessStartInfo _dialogueProcessInfo; private static ProcessStartInfo _dialogueProcessInfo;
private static StreamReader _dr; private static StreamReader _dr;
private static StreamWriter _dw; private static StreamWriter _dw;
public static bool NeedShowWhenStartup { get; set; } public static bool NeedShowWhenStartup { get; set; }
public static void PostError( public static void PostError(
Exception ex Exception ex
) )
{ {
CreateDialogueProcessIfNotExist(); CreateDialogueProcessIfNotExist();
_dw.WriteLine($"posterror {ex.Message}"); _dw.WriteLine($"posterror {ex.Message}");
_dialogueProcess!.Exited -= DialogueProcessExitCallback; _dialogueProcess!.Exited -= DialogueProcessExitCallback;
} }
public static void SetReadAndWriteThread( public static void SetReadAndWriteThread(
Thread thread Thread thread
) )
{ {
_readAndWriteThreadId = thread.ManagedThreadId; _readAndWriteThreadId = thread.ManagedThreadId;
} }
internal static void CreateDialogueProcessIfNotExist() internal static void CreateDialogueProcessIfNotExist()
{ {
if (_dialogueProcess != null) { if (_dialogueProcess != null) {
return; return;
} }
if (!File.Exists(_dialogueProcessInfo.FileName)) { if (!File.Exists(_dialogueProcessInfo.FileName)) {
return; return;
} }
_dialogueProcess = Process.Start(_dialogueProcessInfo); _dialogueProcess = Process.Start(_dialogueProcessInfo);
_dr = new StreamReader(_dialogueClientPipe); _dr = new StreamReader(_dialogueClientPipe);
_dw = new StreamWriter(_dialogueServerPipe); _dw = new StreamWriter(_dialogueServerPipe);
_dialogueProcess!.Exited += DialogueProcessExitCallback; _dialogueProcess!.Exited += DialogueProcessExitCallback;
_dialogueServerPipe.DisposeLocalCopyOfClientHandle(); _dialogueServerPipe.DisposeLocalCopyOfClientHandle();
_dialogueClientPipe.DisposeLocalCopyOfClientHandle(); _dialogueClientPipe.DisposeLocalCopyOfClientHandle();
} }
internal static void LoadDialogue() internal static void LoadDialogue()
{ {
_dialogueServerPipe = new AnonymousPipeServerStream( _dialogueServerPipe = new AnonymousPipeServerStream(
PipeDirection.Out, HandleInheritability.Inheritable); PipeDirection.Out, HandleInheritability.Inheritable);
_dialogueClientPipe = new AnonymousPipeServerStream( _dialogueClientPipe = new AnonymousPipeServerStream(
PipeDirection.In, HandleInheritability.Inheritable); PipeDirection.In, HandleInheritability.Inheritable);
string route = Assembly.GetAssembly(typeof(World))?.Location ?? string.Empty; string route = Assembly.GetAssembly(typeof(World))?.Location ?? string.Empty;
string path = Path.GetDirectoryName(route) ?? string.Empty; string path = Path.GetDirectoryName(route) ?? string.Empty;
string exeName; string exeName;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
exeName = ".exe"; exeName = ".exe";
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{ {
exeName = string.Empty; exeName = string.Empty;
} else } else
{ {
throw new PlatformNotSupportedException("Unknown OS platform"); throw new PlatformNotSupportedException("Unknown OS platform");
} }
string consoleRoute = Path.Combine( string consoleRoute = Path.Combine(
path, @"StgSharp.TerminalDialogue", $@"StgSharp.TerminalDialogue{exeName}"); path, @"StgSharp.TerminalDialogue", $@"StgSharp.TerminalDialogue{exeName}");
_dialogueProcessInfo = new ProcessStartInfo _dialogueProcessInfo = new ProcessStartInfo
{ {
FileName = consoleRoute, FileName = consoleRoute,
Arguments = Arguments =
$"{_dialogueServerPipe.GetClientHandleAsString()} {_dialogueClientPipe.GetClientHandleAsString()}", $"{_dialogueServerPipe.GetClientHandleAsString()} {_dialogueClientPipe.GetClientHandleAsString()}",
UseShellExecute = true, UseShellExecute = true,
RedirectStandardOutput = false, RedirectStandardOutput = false,
}; };
} }
internal static void PostMessage( internal static void PostMessage(
string instruction, string instruction,
params string[] operands params string[] operands
) )
{ {
CreateDialogueProcessIfNotExist(); CreateDialogueProcessIfNotExist();
_dw.WriteLine($"{instruction} {operands}"); _dw.WriteLine($"{instruction} {operands}");
} }
internal static void UnloadDialogue() internal static void UnloadDialogue()
{ {
if (_dialogueProcess != null) { if (_dialogueProcess != null) {
_dialogueProcess.Kill(); _dialogueProcess.Kill();
} }
_dialogueProcess = null; _dialogueProcess = null;
_dialogueServerPipe.Dispose(); _dialogueServerPipe.Dispose();
_dialogueClientPipe.Dispose(); _dialogueClientPipe.Dispose();
} }
internal static string WaitCertainReturn( internal static string WaitCertainReturn(
string target string target
) )
{ {
if (_dialogueProcess == null) { if (_dialogueProcess == null) {
return string.Empty; return string.Empty;
} }
string temp = string .Empty; string temp = string .Empty;
do do
{ {
temp = _dr.ReadLine(); temp = _dr.ReadLine();
temp = temp ?? string.Empty; temp = temp ?? string.Empty;
if (!temp!.StartsWith(target)) if (!temp!.StartsWith(target))
{ {
break; break;
} }
} while (true); } while (true);
int index = temp.IndexOf(' '); int index = temp.IndexOf(' ');
return index != -1 ? temp.Substring(index + 1) : string.Empty; return index != -1 ? temp.Substring(index + 1) : string.Empty;
} }
private static void AssertThread() private static void AssertThread()
{ {
if (_readAndWriteThreadId != Environment.CurrentManagedThreadId) { if (_readAndWriteThreadId != Environment.CurrentManagedThreadId) {
throw new InvalidOperationException( throw new InvalidOperationException(
"Communication with dialogue can only call from certain thread."); "Communication with dialogue can only call from certain thread.");
} }
} }
private static void DialogueProcessExitCallback( private static void DialogueProcessExitCallback(
object? sender, object? sender,
EventArgs e EventArgs e
) )
{ {
_dialogueProcess = null; _dialogueProcess = null;
_dr.Close(); _dr.Close();
_dw.Close(); _dw.Close();
} }
} }
} }
+44 -44
View File
@@ -1,44 +1,44 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ErrorDefine" // file="ErrorDefine"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp namespace StgSharp
{ {
public class UniformEmptyReferenceException : Exception public class UniformEmptyReferenceException : Exception
{ {
public UniformEmptyReferenceException(string program, string name) public UniformEmptyReferenceException(string program, string name)
: base( : base(
$"Location -1 returned when trying to find uniform {name} in shader program {program}") { } $"Location -1 returned when trying to find uniform {name} in shader program {program}") { }
} }
} }
+109 -109
View File
@@ -1,110 +1,110 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="GlobalSetting" // file="GlobalSetting"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp namespace StgSharp
{ {
public static unsafe partial class World public static unsafe partial class World
{ {
internal const int ssdSegmentLength = 16; internal const int ssdSegmentLength = 16;
private static byte[] _currentHash = []; private static byte[] _currentHash = [];
private static bool _inited; private static bool _inited;
public static byte[] CurrentAssemblyHash public static byte[] CurrentAssemblyHash
{ {
get get
{ {
if (_currentHash == null) if (_currentHash == null)
{ {
string route = Assembly.GetExecutingAssembly().Location; string route = Assembly.GetExecutingAssembly().Location;
string time = DateTime.UtcNow.ToString(); string time = DateTime.UtcNow.ToString();
using (SHA256 sh = SHA256.Create()) using (SHA256 sh = SHA256.Create())
{ {
byte[] bytes = Encoding.UTF8.GetBytes(route); byte[] bytes = Encoding.UTF8.GetBytes(route);
_currentHash = sh.ComputeHash(bytes); _currentHash = sh.ComputeHash(bytes);
} }
} }
return _currentHash; return _currentHash;
} }
} }
public static int MainThreadID public static int MainThreadID
{ {
get => (_mainThreadID == -1) ? get => (_mainThreadID == -1) ?
throw new InvalidOperationException( throw new InvalidOperationException(
"StgSharp environment is not inited. Main thread id is not available") : "StgSharp environment is not inited. Main thread id is not available") :
_mainThreadID; _mainThreadID;
internal set => _mainThreadID = value; internal set => _mainThreadID = value;
} }
private static int _mainThreadID { get; set; } = -1; private static int _mainThreadID { get; set; } = -1;
/// <summary> /// <summary>
/// CustomizeInit an instance of OpenGL program, This method should be called before any /// CustomizeInit an instance of OpenGL program, This method should be called before any
/// other World api. /// other World api.
/// </summary> /// </summary>
public static void InitGL(int majorVersion, int minorVersion) public static void InitGL(int majorVersion, int minorVersion)
{ {
if (API == default) { if (API == default) {
API = GraphicAPI.GL; API = GraphicAPI.GL;
} }
if (API != GraphicAPI.GL) { if (API != GraphicAPI.GL) {
return; return;
} }
GraphicFramework.InternalInitGL(majorVersion, minorVersion); GraphicFramework.InternalInitGL(majorVersion, minorVersion);
} }
public static class GlobalSetting public static class GlobalSetting
{ {
private static bool vSyncActivated; private static bool vSyncActivated;
public static bool VSyncActivated public static bool VSyncActivated
{ {
get => vsyncActivated; get => vsyncActivated;
set set
{ {
GraphicFramework.glfwSwapInterval(value ? 1 : 0); GraphicFramework.glfwSwapInterval(value ? 1 : 0);
vsyncActivated = value; vsyncActivated = value;
} }
} }
} }
}//-------------------------------------- End of Class ---------------------------------------// }//-------------------------------------- End of Class ---------------------------------------//
} }
+84 -84
View File
@@ -1,84 +1,84 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IStaticModule" // file="IStaticModule"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace StgSharp namespace StgSharp
{ {
public interface IStaticModule public interface IStaticModule
{ {
string ModuleName { get; } string ModuleName { get; }
void InitializeModule(); void InitializeModule();
} }
public class ModuleToInitializeCollection : IEnumerable<IStaticModule>, IStaticModule public class ModuleToInitializeCollection : IEnumerable<IStaticModule>, IStaticModule
{ {
private readonly List<IStaticModule> _modules = []; private readonly List<IStaticModule> _modules = [];
internal ModuleToInitializeCollection(World.Initializer i) internal ModuleToInitializeCollection(World.Initializer i)
{ {
_modules.Add(i); _modules.Add(i);
} }
public IEnumerator<IStaticModule> GetEnumerator() public IEnumerator<IStaticModule> GetEnumerator()
{ {
return ((IEnumerable<IStaticModule>)_modules).GetEnumerator(); return ((IEnumerable<IStaticModule>)_modules).GetEnumerator();
} }
public void InitializeModule() public void InitializeModule()
{ {
foreach (IStaticModule module in _modules) { foreach (IStaticModule module in _modules) {
module.InitializeModule(); module.InitializeModule();
} }
} }
public ModuleToInitializeCollection UseModule<T>() where T: IStaticModule, new() public ModuleToInitializeCollection UseModule<T>() where T: IStaticModule, new()
{ {
_modules.Add(new T()); _modules.Add(new T());
return this; return this;
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return ((IEnumerable)_modules).GetEnumerator(); return ((IEnumerable)_modules).GetEnumerator();
} }
void IStaticModule.InitializeModule() void IStaticModule.InitializeModule()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
string IStaticModule.ModuleName => "Module Initializer"; string IStaticModule.ModuleName => "Module Initializer";
} }
} }
+57 -57
View File
@@ -1,57 +1,57 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Monitors" // file="Monitors"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace StgSharp namespace StgSharp
{ {
public static partial class World public static partial class World
{ {
public static unsafe IntPtr[] MonitorsHandleArray public static unsafe IntPtr[] MonitorsHandleArray
{ {
get get
{ {
if (MonitorsArray == null) if (MonitorsArray == null)
{ {
int count = 0; int count = 0;
IntPtr* arrayHandle = GraphicFramework.glfwGetMonitors(&count); IntPtr* arrayHandle = GraphicFramework.glfwGetMonitors(&count);
MonitorsArray = new IntPtr[count]; MonitorsArray = new IntPtr[count];
Marshal.Copy((IntPtr)arrayHandle, MonitorsArray, 0, count); Marshal.Copy((IntPtr)arrayHandle, MonitorsArray, 0, count);
Marshal.FreeHGlobal((IntPtr)arrayHandle); Marshal.FreeHGlobal((IntPtr)arrayHandle);
} }
return MonitorsArray; return MonitorsArray;
} }
} }
public static nint[] MonitorsArray { get; set; } = []; public static nint[] MonitorsArray { get; set; } = [];
public static IntPtr DefaultMonitor => MonitorsHandleArray[0]; public static IntPtr DefaultMonitor => MonitorsHandleArray[0];
} }
} }
+257 -257
View File
@@ -1,258 +1,258 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Platform" // file="Platform"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using System; using System;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace StgSharp namespace StgSharp
{ {
internal enum GraphicAPI : byte internal enum GraphicAPI : byte
{ {
GL, GL,
VK VK
} }
public static partial class World public static partial class World
{ {
/// <summary> /// <summary>
/// Version of current World platform. Main version represent in hundred's digit, and sub /// Version of current World platform. Main version represent in hundred's digit, and sub
/// version represent in ten's digit. /// version represent in ten's digit.
/// </summary> /// </summary>
public const long version = 430; public const long version = 430;
private static bool vsyncActivated; private static bool vsyncActivated;
private static uint markCount = 0; private static uint markCount = 0;
internal static GraphicAPI API = default; internal static GraphicAPI API = default;
public static unsafe int DefaultSIMDAlignment public static unsafe int DefaultSIMDAlignment
{ {
get get
{ {
SIMDID id = NativeIntrinsic.IntrinsicMask; SIMDID id = NativeIntrinsic.IntrinsicMask;
switch (id.MaskByte[0] & 0b_00001111) switch (id.MaskByte[0] & 0b_00001111)
{ {
case 1: case 1:
return id.MaskByte[1] switch return id.MaskByte[1] switch
{ {
1 => 16, 1 => 16,
2 => 32, 2 => 32,
3 => 64, 3 => 64,
4 => 64, 4 => 64,
5 => 64, 5 => 64,
_ => 8, _ => 8,
}; };
default: default:
return 8; return 8;
} }
} }
} }
public static ModuleToInitializeCollection Initialize() public static ModuleToInitializeCollection Initialize()
{ {
return new ModuleToInitializeCollection(new Initializer()); return new ModuleToInitializeCollection(new Initializer());
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogError( public static void LogError(
Exception ex Exception ex
) )
{ {
DefaultLog.InternalWriteLog(ex.Message, LogType.Error); DefaultLog.InternalWriteLog(ex.Message, LogType.Error);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogInfo( public static void LogInfo(
string log string log
) )
{ {
DefaultLog.InternalWriteLog(log, LogType.Info); DefaultLog.InternalWriteLog(log, LogType.Info);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogWarning( public static void LogWarning(
string log string log
) )
{ {
DefaultLog.InternalWriteLog(log, LogType.Warning); DefaultLog.InternalWriteLog(log, LogType.Warning);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogWarning( public static void LogWarning(
Exception notVerySeriesException Exception notVerySeriesException
) )
{ {
DefaultLog.InternalWriteLog(notVerySeriesException.Message, LogType.Warning); DefaultLog.InternalWriteLog(notVerySeriesException.Message, LogType.Warning);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Mark( public static void Mark(
bool needConsole bool needConsole
) )
{ {
markCount++; markCount++;
if (needConsole) { if (needConsole) {
Console.WriteLine(markCount); Console.WriteLine(markCount);
} }
} }
public static void Terminate( public static void Terminate(
int exitCode int exitCode
) )
{ {
MainTimeProvider.StopProvidingTime(); MainTimeProvider.StopProvidingTime();
GraphicFramework.glfwTerminate(); GraphicFramework.glfwTerminate();
Environment.Exit(exitCode); Environment.Exit(exitCode);
} }
public static void Track( public static void Track(
object target, object target,
string message, string message,
bool isConsole, bool isConsole,
[CallerFilePath] string filePath = "", [CallerFilePath] string filePath = "",
[CallerMemberName] string callerName = "", [CallerMemberName] string callerName = "",
[CallerLineNumber] int lineNumber = 0 [CallerLineNumber] int lineNumber = 0
) )
{ {
Type t = target.GetType(); Type t = target.GetType();
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n"; string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
FieldInfo[] fieldInfo = t.GetFields( FieldInfo[] fieldInfo = t.GetFields(
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n"; log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n";
foreach (FieldInfo field in fieldInfo) { foreach (FieldInfo field in fieldInfo) {
log += $"|{field.Name}\t\t|{field.FieldType}\t\t|{field.GetValue(target)}\t\t|\n"; log += $"|{field.Name}\t\t|{field.FieldType}\t\t|{field.GetValue(target)}\t\t|\n";
} }
log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n"; log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n";
log += $"Additional information:\n{message}\n"; log += $"Additional information:\n{message}\n";
if (isConsole) if (isConsole)
{ {
Console.WriteLine(log); Console.WriteLine(log);
} else } else
{ {
DefaultLog.InternalWriteLog(log, LogType.Info); DefaultLog.InternalWriteLog(log, LogType.Info);
} }
} }
/// <summary> /// <summary>
/// Write a log message to log file, and mark the _level of this message. /// Write a log message to log file, and mark the _level of this message.
/// </summary> /// </summary>
/// <param _label="message"> /// <param _label="message">
/// A string contains information of how current evironment runs. /// A string contains information of how current evironment runs.
/// </param> /// </param>
/// <param _label="logType"> /// <param _label="logType">
/// The severity of current message. /// The severity of current message.
/// </param> /// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteLog( public static void WriteLog(
string message, string message,
LogType logType LogType logType
) )
{ {
DefaultLog.InternalWriteLog(message, logType); DefaultLog.InternalWriteLog(message, logType);
} }
internal static TDele ConvertAPI<TDele>( internal static TDele ConvertAPI<TDele>(
IntPtr funcPtr IntPtr funcPtr
) )
{ {
if (funcPtr == IntPtr.Zero) { if (funcPtr == IntPtr.Zero) {
throw new InvalidCastException( throw new InvalidCastException(
"Failed to convert api, the function pointer is zero."); "Failed to convert api, the function pointer is zero.");
} }
try try
{ {
return Marshal.GetDelegateForFunctionPointer<TDele>(funcPtr); return Marshal.GetDelegateForFunctionPointer<TDele>(funcPtr);
} }
catch (Exception) catch (Exception)
{ {
throw; throw;
} }
} }
internal static Delegate ConvertAPI( internal static Delegate ConvertAPI(
IntPtr funcPtr, IntPtr funcPtr,
Type T Type T
) )
{ {
if (funcPtr == IntPtr.Zero) { if (funcPtr == IntPtr.Zero) {
throw new InvalidCastException( throw new InvalidCastException(
"Failed to convert api, the function pointer is zero."); "Failed to convert api, the function pointer is zero.");
} }
try try
{ {
return Marshal.GetDelegateForFunctionPointer(funcPtr, T); return Marshal.GetDelegateForFunctionPointer(funcPtr, T);
} }
catch (Exception) catch (Exception)
{ {
throw; throw;
} }
} }
internal static unsafe void InternalInitialize() internal static unsafe void InternalInitialize()
{ {
// Initialize time provider and start providing time // Initialize time provider and start providing time
MainTimeProvider.StartProvidingTime(); MainTimeProvider.StartProvidingTime();
GraphicFramework.LoadGlfw(); GraphicFramework.LoadGlfw();
if (GraphicFramework.glfwInit() == 0) { if (GraphicFramework.glfwInit() == 0) {
throw new Exception("Failed to init system graphic environment."); throw new Exception("Failed to init system graphic environment.");
} }
DefaultLog.InternalAppendLog("\n\n\n"); DefaultLog.InternalAppendLog("\n\n\n");
DefaultLog.InternalWriteLog( DefaultLog.InternalWriteLog(
$"Program {Assembly.GetEntryAssembly()!.FullName} on {Environment.MachineName} Started.", LogType.Info); $"Program {Assembly.GetEntryAssembly()!.FullName} on {Environment.MachineName} Started.", LogType.Info);
MainThreadID = System.Environment.CurrentManagedThreadId; MainThreadID = System.Environment.CurrentManagedThreadId;
/**/ /**/
Dialogue.NeedShowWhenStartup = false; Dialogue.NeedShowWhenStartup = false;
Dialogue.LoadDialogue(); Dialogue.LoadDialogue();
if (Dialogue.NeedShowWhenStartup) { if (Dialogue.NeedShowWhenStartup) {
Dialogue.CreateDialogueProcessIfNotExist(); Dialogue.CreateDialogueProcessIfNotExist();
} }
/**/ /**/
NativeIntrinsic.InitIntrinsicContext(); NativeIntrinsic.InitIntrinsicContext();
} }
internal class Initializer : IStaticModule internal class Initializer : IStaticModule
{ {
public string ModuleName => "StgSharp"; public string ModuleName => "StgSharp";
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void InitializeModule() public void InitializeModule()
{ {
World.InternalInitialize(); World.InternalInitialize();
} }
} }
} }
} }
+49 -49
View File
@@ -1,49 +1,49 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="globalKeyStat" // file="globalKeyStat"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp namespace StgSharp
{ {
public static partial class World public static partial class World
{ {
private static ConcurrentDictionary<int, KeyStatus> keyListener private static ConcurrentDictionary<int, KeyStatus> keyListener
= new ConcurrentDictionary<int, KeyStatus>(); = new ConcurrentDictionary<int, KeyStatus>();
public static KeyStatus CheckKey(KeyboardKey key) public static KeyStatus CheckKey(KeyboardKey key)
{ {
return keyListener.GetOrAdd((int)key, KeyStatus.RELEASE); return keyListener.GetOrAdd((int)key, KeyStatus.RELEASE);
} }
} }
} }
@@ -1,78 +1,78 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="CoordinationBase" // file="CoordinationBase"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public abstract class CoordinationBase public abstract class CoordinationBase
{ {
private bool globalCoordAvailable; private bool globalCoordAvailable;
private CoordinationBase localCoordination; private CoordinationBase localCoordination;
private Matrix44 coordMat; private Matrix44 coordMat;
public CoordinationBase(CoordinationBase localCoordination) public CoordinationBase(CoordinationBase localCoordination)
{ {
this.localCoordination = localCoordination; this.localCoordination = localCoordination;
coordMat = new Matrix44(); coordMat = new Matrix44();
} }
public virtual Point LocalOrigin public virtual Point LocalOrigin
{ {
get => new Point(coordMat.column[3].XYZ); get => new Point(coordMat.column[3].XYZ);
internal set => coordMat.column[3].XYZ = value.Coord; internal set => coordMat.column[3].XYZ = value.Coord;
} }
public virtual Vec3 LocalX public virtual Vec3 LocalX
{ {
get => coordMat.column[3].XYZ; get => coordMat.column[3].XYZ;
internal set => coordMat.column[3].XYZ = value; internal set => coordMat.column[3].XYZ = value;
} }
public virtual Vec3 LocalY public virtual Vec3 LocalY
{ {
get => coordMat.column[3].XYZ; get => coordMat.column[3].XYZ;
internal set => coordMat.column[3].XYZ = value; internal set => coordMat.column[3].XYZ = value;
} }
public virtual Vec3 LocalZ public virtual Vec3 LocalZ
{ {
get => coordMat.column[3].XYZ; get => coordMat.column[3].XYZ;
set => coordMat.column[3].XYZ = value; set => coordMat.column[3].XYZ = value;
} }
protected ref Matrix44 CoordMat protected ref Matrix44 CoordMat
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref coordMat; get => ref coordMat;
} }
} }
} }
@@ -1,57 +1,57 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="PlainCoordinate" // file="PlainCoordinate"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Text; using System.Text;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class PlainCoordinate : CoordinationBase public class PlainCoordinate : CoordinationBase
{ {
public PlainCoordinate(CoordinationBase local, Point origin, Vec3 xAxis, Vec3 yAxis) public PlainCoordinate(CoordinationBase local, Point origin, Vec3 xAxis, Vec3 yAxis)
: base(local) : base(local)
{ {
CoordMat = Matrix44.Unit; CoordMat = Matrix44.Unit;
CoordMat.column[0] = new Vec4(xAxis, 0); CoordMat.column[0] = new Vec4(xAxis, 0);
CoordMat.column[1] = new Vec4(yAxis, 0); CoordMat.column[1] = new Vec4(yAxis, 0);
CoordMat.column[2] = new Vec4(Linear.Normalize(Vec3.Cross(xAxis, yAxis)), 0); CoordMat.column[2] = new Vec4(Linear.Normalize(Vec3.Cross(xAxis, yAxis)), 0);
LocalOrigin = origin; LocalOrigin = origin;
} }
public static PlainCoordinate StandardPlainCoordination { get; } = new(null, new Point(0, 0, 0), public static PlainCoordinate StandardPlainCoordination { get; } = new(null, new Point(0, 0, 0),
new Vec3(1, 0, 0), new Vec3(0, 1, 0)); new Vec3(1, 0, 0), new Vec3(0, 1, 0));
} }
} }
@@ -1,44 +1,44 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="SpaceCoordinate" // file="SpaceCoordinate"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class SpaceCoordinate : CoordinationBase public class SpaceCoordinate : CoordinationBase
{ {
public SpaceCoordinate(CoordinationBase localCoordination, Point origin, Vec3 xAxis, Vec3 yAxis, Vec3 zAxis) public SpaceCoordinate(CoordinationBase localCoordination, Point origin, Vec3 xAxis, Vec3 yAxis, Vec3 zAxis)
: base(localCoordination) { } : base(localCoordination) { }
} }
} }
@@ -1,43 +1,43 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="StreamLocalCoordinate" // file="StreamLocalCoordinate"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
/* /*
public class StreamLocalCoordinate : CoordinationBase public class StreamLocalCoordinate : CoordinationBase
{ {
} }
/**/ /**/
} }
+61 -61
View File
@@ -1,61 +1,61 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="GemoryException" // file="GemoryException"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public unsafe class ToUpperDimensionException : Exception public unsafe class ToUpperDimensionException : Exception
{ {
protected ToUpperDimensionException(SerializationInfo info, StreamingContext context) : base(info, context) { } protected ToUpperDimensionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
public ToUpperDimensionException() { } public ToUpperDimensionException() { }
public ToUpperDimensionException(string message) : base(message) { } public ToUpperDimensionException(string message) : base(message) { }
public ToUpperDimensionException(string message, Exception innerException) : base(message, innerException) { } public ToUpperDimensionException(string message, Exception innerException) : base(message, innerException) { }
} }
/// <summary> /// <summary>
/// 当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常 /// 当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常
/// </summary> /// </summary>
public class UnusedVertexException : Exception public class UnusedVertexException : Exception
{ {
protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context) { } protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context) { }
public UnusedVertexException() { } public UnusedVertexException() { }
public UnusedVertexException(string message) : base(message) { } public UnusedVertexException(string message) : base(message) { }
public UnusedVertexException(string message, Exception innerException) : base(message, innerException) { } public UnusedVertexException(string message, Exception innerException) : base(message, innerException) { }
} }
} }
@@ -1,113 +1,113 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="GeometryOperation" // file="GeometryOperation"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using StgSharp.Timing; using StgSharp.Timing;
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate Vec3 GeometryMotionDelegate(TimeSpanProvider timeSource, out float rotation); public delegate Vec3 GeometryMotionDelegate(TimeSpanProvider timeSource, out float rotation);
public class GeometryMotion public class GeometryMotion
{ {
private bool isIncrementMode; private bool isIncrementMode;
private bool sourceIsStatic; private bool sourceIsStatic;
private GeometryMotionDelegate movement; private GeometryMotionDelegate movement;
private IntPtr handle; private IntPtr handle;
private TimeSpanProvider time; private TimeSpanProvider time;
public unsafe GeometryMotion( public unsafe GeometryMotion(
bool isIncreament, bool isIncreament,
TimeSpanProvider timeSource, TimeSpanProvider timeSource,
GeometryMotionDelegate motionDelegate) GeometryMotionDelegate motionDelegate)
{ {
isIncrementMode = isIncreament; isIncrementMode = isIncreament;
time = timeSource; time = timeSource;
if (motionDelegate == null) if (motionDelegate == null)
{ {
handle = (IntPtr)(delegate*<TimeSpanProvider, out float, Vec3>)&defaultMotion; handle = (IntPtr)(delegate*<TimeSpanProvider, out float, Vec3>)&defaultMotion;
movement = defaultMotion; movement = defaultMotion;
} else if (motionDelegate.Method.IsStatic) } else if (motionDelegate.Method.IsStatic)
{ {
sourceIsStatic = true; sourceIsStatic = true;
handle = Marshal.GetFunctionPointerForDelegate(motionDelegate); handle = Marshal.GetFunctionPointerForDelegate(motionDelegate);
movement = motionDelegate; movement = motionDelegate;
} else } else
{ {
movement = motionDelegate; movement = motionDelegate;
} }
// sourceIsStatic = false; // sourceIsStatic = false;
} }
public bool IsIncrement public bool IsIncrement
{ {
get => isIncrementMode; get => isIncrementMode;
} }
public static GeometryMotion DefaultMotion public static GeometryMotion DefaultMotion
{ {
get => new GeometryMotion(true, null, null); get => new GeometryMotion(true, null, null);
} }
public unsafe void RunMotion(ref Vec3 coord, ref float rotation) public unsafe void RunMotion(ref Vec3 coord, ref float rotation)
{ {
float rot; float rot;
Vec3 vec; Vec3 vec;
if (sourceIsStatic) if (sourceIsStatic)
{ {
vec = ((delegate* unmanaged[Cdecl]<TimeSpanProvider, out float, Vec3>)handle)( vec = ((delegate* unmanaged[Cdecl]<TimeSpanProvider, out float, Vec3>)handle)(
time, out rot); time, out rot);
} else } else
{ {
vec = movement(time, out rot); vec = movement(time, out rot);
} }
if (isIncrementMode) if (isIncrementMode)
{ {
coord += vec; coord += vec;
rotation += rot; rotation += rot;
} else } else
{ {
coord = vec; coord = vec;
rotation = rot; rotation = rot;
} }
} }
private static Vec3 defaultMotion(TimeSpanProvider provider, out float rotation) private static Vec3 defaultMotion(TimeSpanProvider provider, out float rotation)
{ {
rotation = 0; rotation = 0;
return Vec3.Zero; return Vec3.Zero;
} }
}//------------------------------- End of Class ------------------------------- }//------------------------------- End of Class -------------------------------
} }
+175 -175
View File
@@ -1,175 +1,175 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Angle" // file="Angle"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Mathematics namespace StgSharp.Mathematics
{ {
public static partial class GeometryScaler public static partial class GeometryScaler
{ {
internal const float DegToRad = 180 / Scalar.Pi; internal const float DegToRad = 180 / Scalar.Pi;
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Cos(Radius r) public static float Cos(Radius r)
{ {
return MathF.Cos(r._radius); return MathF.Cos(r._radius);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Cos(Degree r) public static float Cos(Degree r)
{ {
return MathF.Cos(r._degree / DegToRad); return MathF.Cos(r._degree / DegToRad);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Sin(Radius r) public static float Sin(Radius r)
{ {
return MathF.Sin(r._radius); return MathF.Sin(r._radius);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Sin(Degree r) public static float Sin(Degree r)
{ {
return MathF.Sin(r._degree / DegToRad); return MathF.Sin(r._degree / DegToRad);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Tan(Radius r) public static float Tan(Radius r)
{ {
return MathF.Tan(r._radius); return MathF.Tan(r._radius);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Tan(Degree r) public static float Tan(Degree r)
{ {
return MathF.Tan(r._degree / DegToRad); return MathF.Tan(r._degree / DegToRad);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Degree ToDegree(float value) public static Degree ToDegree(float value)
{ {
return new Degree(value); return new Degree(value);
} }
} }
public struct Degree public struct Degree
{ {
internal float _degree; internal float _degree;
public Degree(float dgree) public Degree(float dgree)
{ {
_degree = dgree; _degree = dgree;
} }
public static implicit operator Radius(Degree d) public static implicit operator Radius(Degree d)
{ {
return new Radius(d._degree / GeometryScaler.DegToRad); return new Radius(d._degree / GeometryScaler.DegToRad);
} }
} }
public struct Radius public struct Radius
{ {
internal float _radius; internal float _radius;
[Obsolete("Unsafe, you may forget this is radius.", true)] [Obsolete("Unsafe, you may forget this is radius.", true)]
public Radius() { } public Radius() { }
public Radius(float radius) public Radius(float radius)
{ {
_radius = radius; _radius = radius;
} }
public static Radius Zero public static Radius Zero
{ {
get => new Radius(0); get => new Radius(0);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator -(Radius r) public static Radius operator -(Radius r)
{ {
return new Radius(-r._radius); return new Radius(-r._radius);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator -(Radius left, Radius Right) public static Radius operator -(Radius left, Radius Right)
{ {
return new Radius(left._radius - Right._radius); return new Radius(left._radius - Right._radius);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Radius left, Radius right) public static bool operator !=(Radius left, Radius right)
{ {
return left._radius != right._radius; return left._radius != right._radius;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator *(Radius left, float right) public static Radius operator *(Radius left, float right)
{ {
return new Radius(left._radius * right); return new Radius(left._radius * right);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator /(Radius left, float right) public static Radius operator /(Radius left, float right)
{ {
return new Radius(left._radius / right); return new Radius(left._radius / right);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float operator /(Radius left, Radius right) public static float operator /(Radius left, Radius right)
{ {
return left._radius / right._radius; return left._radius / right._radius;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator +(Radius left, Radius Right) public static Radius operator +(Radius left, Radius Right)
{ {
return new Radius(left._radius + Right._radius); return new Radius(left._radius + Right._radius);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Radius left, Radius right) public static bool operator ==(Radius left, Radius right)
{ {
return left._radius == right._radius; return left._radius == right._radius;
} }
public static implicit operator Degree(Radius r) public static implicit operator Degree(Radius r)
{ {
return new Degree((r._radius * 180) / Scalar.Pi); return new Degree((r._radius * 180) / Scalar.Pi);
} }
} }
} }
+57 -57
View File
@@ -1,57 +1,57 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IGeometry" // file="IGeometry"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public interface IGeometry public interface IGeometry
{ {
public Point this[int index] { get; set; } public Point this[int index] { get; set; }
#pragma warning disable CA1819 #pragma warning disable CA1819
public Vec4[] VertexStream public Vec4[] VertexStream
#pragma warning restore CA1819 #pragma warning restore CA1819
{ get; } { get; }
public CoordinationBase Coordination { get; } public CoordinationBase Coordination { get; }
public int VertexCount { get; } public int VertexCount { get; }
public ReadOnlySpan<int> VertexIndices { get; } public ReadOnlySpan<int> VertexIndices { get; }
} }
} }
+37 -37
View File
@@ -1,37 +1,37 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IGeomtryBuffer" // file="IGeomtryBuffer"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public interface IGeomtryBuffer { } public interface IGeomtryBuffer { }
} }
+73 -73
View File
@@ -1,73 +1,73 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IInstancing" // file="IInstancing"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public interface IInstancing public interface IInstancing
{ {
public float Rotation { get { return GlobalBuffer.CoordAndRotationList[BufferId].W; } set public float Rotation { get { return GlobalBuffer.CoordAndRotationList[BufferId].W; } set
{ {
Vec4 temp = GlobalBuffer.CoordAndRotationList[ Vec4 temp = GlobalBuffer.CoordAndRotationList[
BufferId]; BufferId];
temp.W = value; temp.W = value;
GlobalBuffer.CoordAndRotationList[ GlobalBuffer.CoordAndRotationList[
BufferId] = temp; BufferId] = temp;
} } } }
public float Scale { get { return GlobalBuffer.ScalingList[BufferId]; } set { GlobalBuffer.ScalingList[BufferId] = value; } } public float Scale { get { return GlobalBuffer.ScalingList[BufferId]; } set { GlobalBuffer.ScalingList[BufferId] = value; } }
public GeometryMotion Motion { get; set; } public GeometryMotion Motion { get; set; }
public IInstancingBuffer GlobalBuffer { get; internal set; } public IInstancingBuffer GlobalBuffer { get; internal set; }
public int BufferId { get; internal set; } public int BufferId { get; internal set; }
public Vec3 CenterPositionGlobal { get; internal set; } public Vec3 CenterPositionGlobal { get; internal set; }
public Vec3 Coord { get { return GlobalBuffer.CoordAndRotationList[BufferId].XYZ; } set { GlobalBuffer.CoordAndRotationList[BufferId] = new Vec4(value.reg); } } public Vec3 Coord { get { return GlobalBuffer.CoordAndRotationList[BufferId].XYZ; } set { GlobalBuffer.CoordAndRotationList[BufferId] = new Vec4(value.reg); } }
public void Move() public void Move()
{ {
(Vec3 coord, float rotation) = (Coord, Rotation); (Vec3 coord, float rotation) = (Coord, Rotation);
Motion.RunMotion(ref coord, ref rotation); Motion.RunMotion(ref coord, ref rotation);
(Coord, Rotation) = (coord, rotation); (Coord, Rotation) = (coord, rotation);
} }
} }
} }
+53 -53
View File
@@ -1,53 +1,53 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IInstancingBuffer" // file="IInstancingBuffer"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public interface IInstancingBuffer public interface IInstancingBuffer
{ {
public Span<Vec4> CoordAndRotationSpan { get; } public Span<Vec4> CoordAndRotationSpan { get; }
public Span<float> ScalingSpan { get; } public Span<float> ScalingSpan { get; }
internal IGeometry TypicalShape { get; } internal IGeometry TypicalShape { get; }
internal List<IInstancing> InstanceList { get; } internal List<IInstancing> InstanceList { get; }
internal List<Vec4> CoordAndRotationList { get; } internal List<Vec4> CoordAndRotationList { get; }
internal List<float> ScalingList { get; } internal List<float> ScalingList { get; }
} }
} }
@@ -1,78 +1,78 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Cordinate" // file="Cordinate"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct PartialPlainCoordinate public struct PartialPlainCoordinate
{ {
/* /*
internal Matrix32 axis; internal Matrix32 axis;
/// <summary> /// <summary>
/// The _origin of this coordinate. /// The _origin of this coordinate.
/// </summary> /// </summary>
public Vec3 origin; public Vec3 origin;
public PartialPlainCoordinate( Vec3 origin, Vec3 horiziontial, Vec3 vertical ) public PartialPlainCoordinate( Vec3 origin, Vec3 horiziontial, Vec3 vertical )
{ {
this.origin = origin; this.origin = origin;
axis = new Matrix32(); axis = new Matrix32();
Unsafe.SkipInit( out axis.mat ); Unsafe.SkipInit( out axis.mat );
axis.colum0 = horiziontial; axis.colum0 = horiziontial;
axis.colum1 = vertical; axis.colum1 = vertical;
} }
/// <summary> /// <summary>
/// The horizontial axis of the coordinate. Point to the right direction. /// The horizontial axis of the coordinate. Point to the right direction.
/// </summary> /// </summary>
public Vec3 axis_H => axis.colum0; public Vec3 axis_H => axis.colum0;
/// <summary> /// <summary>
/// The vertical axis of the coordinate. Point to the top direction. /// The vertical axis of the coordinate. Point to the top direction.
/// </summary> /// </summary>
public Vec3 axis_V => axis.colum1; public Vec3 axis_V => axis.colum1;
[MethodImpl( MethodImplOptions.AggressiveInlining )] [MethodImpl( MethodImplOptions.AggressiveInlining )]
public Vec3 GetRealLocate( Vec2 raletiveLocation ) public Vec3 GetRealLocate( Vec2 raletiveLocation )
{ {
return origin + axis.VerticalVecMultiply( raletiveLocation ); return origin + axis.VerticalVecMultiply( raletiveLocation );
} }
*/ */
} }
} }
@@ -1,45 +1,45 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="GeometryOperation" // file="GeometryOperation"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public static unsafe class GeometryOperation public static unsafe class GeometryOperation
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec3 DefaultMotion(int tick) public static Vec3 DefaultMotion(int tick)
{ {
return default(Vec3); return default(Vec3);
} }
} }
} }
@@ -1,70 +1,70 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IPlainEntity" // file="IPlainEntity"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public interface IPlainEntity public interface IPlainEntity
{ {
public Vec2 CenterPosition { get; set; } public Vec2 CenterPosition { get; set; }
public bool CollideWith(IPlainEntity entity); public bool CollideWith(IPlainEntity entity);
} }
public class PlainEntity : IPlainEntity public class PlainEntity : IPlainEntity
{ {
private PlainGeometry _shape; private PlainGeometry _shape;
public PlainEntity(PlainGeometry shape) public PlainEntity(PlainGeometry shape)
{ {
_shape = shape; _shape = shape;
} }
bool IPlainEntity.CollideWith(IPlainEntity entity) bool IPlainEntity.CollideWith(IPlainEntity entity)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
Vec2 IPlainEntity.CenterPosition Vec2 IPlainEntity.CenterPosition
{ {
get => _shape.Coordination.LocalOrigin.Coord.XY; get => _shape.Coordination.LocalOrigin.Coord.XY;
set => throw new InvalidOperationException(); set => throw new InvalidOperationException();
} }
} }
} }
@@ -1,74 +1,74 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ParticleOnPlain" // file="ParticleOnPlain"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class ParticleOnPlain : IInstancing, IPlainEntity public class ParticleOnPlain : IInstancing, IPlainEntity
{ {
public ParticleOnPlain(PlainInstancingBuffer<ParticleOnPlain> buffer) public ParticleOnPlain(PlainInstancingBuffer<ParticleOnPlain> buffer)
{ {
if (buffer == null) { if (buffer == null) {
throw new ArgumentNullException(paramName:nameof(buffer)); throw new ArgumentNullException(paramName:nameof(buffer));
} }
GlobalBuffer = buffer; GlobalBuffer = buffer;
BufferId = buffer.CreateInstanceID(); BufferId = buffer.CreateInstanceID();
((IInstancingBuffer)buffer).InstanceList.Add(this); ((IInstancingBuffer)buffer).InstanceList.Add(this);
} }
public GeometryMotion Motion { get; set; } public GeometryMotion Motion { get; set; }
public IInstancingBuffer GlobalBuffer { get; set; } public IInstancingBuffer GlobalBuffer { get; set; }
public int BufferId { get; set; } public int BufferId { get; set; }
Vec3 IInstancing.CenterPositionGlobal { get; set; } Vec3 IInstancing.CenterPositionGlobal { get; set; }
bool IPlainEntity.CollideWith(IPlainEntity entity) bool IPlainEntity.CollideWith(IPlainEntity entity)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
Vec2 IPlainEntity.CenterPosition Vec2 IPlainEntity.CenterPosition
{ {
get => GlobalBuffer.CoordAndRotationList[BufferId].XY; get => GlobalBuffer.CoordAndRotationList[BufferId].XY;
set => throw new NotImplementedException(); set => throw new NotImplementedException();
} }
} }
} }
@@ -1,67 +1,67 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="PlainGeometry" // file="PlainGeometry"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
/// <summary> /// <summary>
/// Plain geometry only contains straight sides. /// Plain geometry only contains straight sides.
/// </summary> /// </summary>
public abstract class PlainGeometry : IGeometry public abstract class PlainGeometry : IGeometry
{ {
protected Vec4[] vertexMat; protected Vec4[] vertexMat;
internal CoordinationBase coordinate; internal CoordinationBase coordinate;
internal PlainGeometry(CoordinationBase coordination) internal PlainGeometry(CoordinationBase coordination)
{ {
coordinate = coordination; coordinate = coordination;
} }
public Point this[int index] public Point this[int index]
{ {
get => new Point(vertexMat[index]); get => new Point(vertexMat[index]);
set => vertexMat[index].vec = value.coordVec; set => vertexMat[index].vec = value.coordVec;
} }
public int VertexCount => this.vertexMat.Length; public int VertexCount => this.vertexMat.Length;
public abstract ReadOnlySpan<int> VertexIndices { get; } public abstract ReadOnlySpan<int> VertexIndices { get; }
#pragma warning disable CA1819 #pragma warning disable CA1819
public Vec4[] VertexStream => vertexMat; public Vec4[] VertexStream => vertexMat;
public CoordinationBase Coordination => this.coordinate; public CoordinationBase Coordination => this.coordinate;
#pragma warning restore CA1819 #pragma warning restore CA1819
} }
} }
@@ -1,187 +1,187 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="PlainInstancingBuffer" // file="PlainInstancingBuffer"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using StgSharp.Mathematics.Numeric; using StgSharp.Mathematics.Numeric;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class PlainInstancingBuffer<T> : IDisposable, IEnumerable<T>, IInstancingBuffer where T: IInstancing public class PlainInstancingBuffer<T> : IDisposable, IEnumerable<T>, IInstancingBuffer where T: IInstancing
{ {
private bool disposedValue; private bool disposedValue;
private CoordinatePlain globalCoordinate; private CoordinatePlain globalCoordinate;
private List<Vec4> coordList; private List<Vec4> coordList;
private List<IInstancing> instanceList; private List<IInstancing> instanceList;
private List<float> scalingList; private List<float> scalingList;
private Mutex mutex; private Mutex mutex;
public PlainInstancingBuffer() public PlainInstancingBuffer()
{ {
coordList = new List<Vec4>(capacity:100); coordList = new List<Vec4>(capacity:100);
instanceList = new List<IInstancing>(capacity:100); instanceList = new List<IInstancing>(capacity:100);
scalingList = new List<float>(capacity:100); scalingList = new List<float>(capacity:100);
coordArray = Array.Empty<Vec4>(); coordArray = Array.Empty<Vec4>();
scaleArray = Array.Empty<float>(); scaleArray = Array.Empty<float>();
mutex = new Mutex(); mutex = new Mutex();
} }
public List<IInstancing> InstanceList public List<IInstancing> InstanceList
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => instanceList; get => instanceList;
} }
public List<Vec4> CoordAndRotationList public List<Vec4> CoordAndRotationList
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => coordList; get => coordList;
} }
public List<float> ScalingList public List<float> ScalingList
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => scalingList; get => scalingList;
} }
public Span<Vec4> CoordAndRotationSpan public Span<Vec4> CoordAndRotationSpan
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => CollectionsMarshal.AsSpan(coordList); get => CollectionsMarshal.AsSpan(coordList);
} }
public Span<float> ScalingSpan public Span<float> ScalingSpan
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => CollectionsMarshal.AsSpan(scalingList); get => CollectionsMarshal.AsSpan(scalingList);
} }
public int CreateInstanceID() public int CreateInstanceID()
{ {
mutex.WaitOne(); mutex.WaitOne();
int ret = instanceList.Count; int ret = instanceList.Count;
coordList.Add(new Vec4()); coordList.Add(new Vec4());
scalingList.Add(0); scalingList.Add(0);
mutex.ReleaseMutex(); mutex.ReleaseMutex();
return ret; return ret;
} }
// ~PlainInstancingBuffer() // ~PlainInstancingBuffer()
// { // {
// Dispose(disposing: false); // Dispose(disposing: false);
// } // }
public void Dispose() public void Dispose()
{ {
Dispose(disposing:true); Dispose(disposing:true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
foreach (IInstancing item in instanceList) { foreach (IInstancing item in instanceList) {
yield return (T)item; yield return (T)item;
} }
} }
public void Remove(T instance) public void Remove(T instance)
{ {
mutex.WaitOne(); mutex.WaitOne();
if (instance.GlobalBuffer != this) { if (instance.GlobalBuffer != this) {
throw new ArgumentException( throw new ArgumentException(
message:"instance does not belong to current Particle Buffer", message:"instance does not belong to current Particle Buffer",
paramName:nameof(instance)); paramName:nameof(instance));
} }
int index = instance.BufferId; int index = instance.BufferId;
IInstancing temp = instanceList[^1]; IInstancing temp = instanceList[^1];
instanceList[instance.BufferId] = temp; instanceList[instance.BufferId] = temp;
temp.BufferId = instance.BufferId; temp.BufferId = instance.BufferId;
coordList[instance.BufferId] = coordList[^1]; coordList[instance.BufferId] = coordList[^1];
scalingList[instance.BufferId] = scalingList[^1]; scalingList[instance.BufferId] = scalingList[^1];
instanceList.RemoveAt(instanceList.Count - 1); instanceList.RemoveAt(instanceList.Count - 1);
coordList.RemoveAt(coordList.Count - 1); coordList.RemoveAt(coordList.Count - 1);
scalingList.RemoveAt(scalingList.Count - 1); scalingList.RemoveAt(scalingList.Count - 1);
mutex.ReleaseMutex(); mutex.ReleaseMutex();
} }
public void UpdateAllParticles() public void UpdateAllParticles()
{ {
foreach (IInstancing particle in instanceList) { foreach (IInstancing particle in instanceList) {
particle.Move(); particle.Move();
} }
} }
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (!disposedValue) if (!disposedValue)
{ {
if (disposing) { if (disposing) {
mutex.Dispose(); mutex.Dispose();
} }
coordList.Clear(); coordList.Clear();
instanceList.Clear(); instanceList.Clear();
scalingList.Clear(); scalingList.Clear();
disposedValue = true; disposedValue = true;
} }
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
foreach (IInstancing item in instanceList) { foreach (IInstancing item in instanceList) {
yield return (T)item; yield return (T)item;
} }
} }
IGeometry IInstancingBuffer.TypicalShape => throw new NotImplementedException(); IGeometry IInstancingBuffer.TypicalShape => throw new NotImplementedException();
#region field of mem opt #region field of mem opt
private Vec4[] coordArray; private Vec4[] coordArray;
private float[] scaleArray; private float[] scaleArray;
#endregion #endregion
} }
} }
@@ -1,78 +1,78 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Parallelogram" // file="Parallelogram"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class Parallelogram : Polygon4 public class Parallelogram : Polygon4
{ {
internal readonly Func<int, Vec3> movCenterOperation = GeometryOperation.DefaultMotion; internal readonly Func<int, Vec3> movCenterOperation = GeometryOperation.DefaultMotion;
internal Point center; internal Point center;
public Parallelogram(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y) public Parallelogram(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y) : base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
{ {
#if DEBUG #if DEBUG
if (this[0].Coord + this[2].Coord != this[1].Coord + this[3].Coord) if (this[0].Coord + this[2].Coord != this[1].Coord + this[3].Coord)
{ {
DefaultLog.InternalWriteLog( DefaultLog.InternalWriteLog(
"Init of geometry item failed, because four vertices cannot form a rectangle.", "Init of geometry item failed, because four vertices cannot form a rectangle.",
LogType.Warning); LogType.Warning);
} }
#endif #endif
} }
public Parallelogram( public Parallelogram(
PlainCoordinate coordination, PlainCoordinate coordination,
float v0x, float v0x,
float v0y, float v0y,
float v1x, float v1x,
float v1y, float v1y,
float v2x, float v2x,
float v2y, float v2y,
float v3x, float v3x,
float v3y) float v3y)
: base(coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y) : base(coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
{ {
#if DEBUG #if DEBUG
if (this[0].Coord + this[2].Coord != this[1].Coord + this[3].Coord) if (this[0].Coord + this[2].Coord != this[1].Coord + this[3].Coord)
{ {
DefaultLog.InternalWriteLog( DefaultLog.InternalWriteLog(
"Init of geometry item failed, because four vertices cannot form a rectangle.", "Init of geometry item failed, because four vertices cannot form a rectangle.",
LogType.Warning); LogType.Warning);
} }
#endif #endif
} }
} }
} }
@@ -1,86 +1,86 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Plain" // file="Plain"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System.Numerics; using System.Numerics;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public unsafe class Plain public unsafe class Plain
{ {
internal readonly float d = -1; internal readonly float d = -1;
internal Vec3 _origin; internal Vec3 _origin;
internal Vec3 plainParameter; internal Vec3 plainParameter;
internal Vec3 vec1; internal Vec3 vec1;
internal Vec3 vec2; internal Vec3 vec2;
public Plain(Vec3 o, Vec3 v1, Vec3 v2) public Plain(Vec3 o, Vec3 v1, Vec3 v2)
{ {
this._origin = o; this._origin = o;
this.vec1 = v1 - (v2 * (v1.Y / v2.Y)); //xz this.vec1 = v1 - (v2 * (v1.Y / v2.Y)); //xz
this.vec2 = v2 - (vec1 * (v2.X / v1.X)); //yz this.vec2 = v2 - (vec1 * (v2.X / v1.X)); //yz
// |_origin|-k1*|vec1|-k2*|vec2| --> plainParameter.Z; // |_origin|-k1*|vec1|-k2*|vec2| --> plainParameter.Z;
plainParameter.Z = _origin.Z - (vec1.Z * (_origin.X / vec1.X)) - (vec2.Z * (_origin.Y / vec2.Y)); plainParameter.Z = _origin.Z - (vec1.Z * (_origin.X / vec1.X)) - (vec2.Z * (_origin.Y / vec2.Y));
// plainParameter.Z -> plainParameter.X, plainParameter.Y // plainParameter.Z -> plainParameter.X, plainParameter.Y
plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z); plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z);
plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z); plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z);
plainParameter.X = 1 / plainParameter.X; plainParameter.X = 1 / plainParameter.X;
plainParameter.Y = 1 / plainParameter.Y; plainParameter.Y = 1 / plainParameter.Y;
plainParameter.Z = 1 / plainParameter.Z; plainParameter.Z = 1 / plainParameter.Z;
} }
public Plain(Point p1, Point p2, Point p3) public Plain(Point p1, Point p2, Point p3)
{ {
Vec3 origin = p1.Coord; Vec3 origin = p1.Coord;
Vec3 v1 = p2.Coord - origin; Vec3 v1 = p2.Coord - origin;
Vec3 v2 = p3.Coord - origin; Vec3 v2 = p3.Coord - origin;
vec1 = v1 - (v2 * (v1.Y / v2.Y)); //xz vec1 = v1 - (v2 * (v1.Y / v2.Y)); //xz
vec2 = v2 - (vec1 * (v2.X / v1.X)); //yz vec2 = v2 - (vec1 * (v2.X / v1.X)); //yz
// |_origin|-k1*|vec1|-k2*|vec2| --> plainParameter.Z; // |_origin|-k1*|vec1|-k2*|vec2| --> plainParameter.Z;
plainParameter.Z = origin.Z - (vec1.Z * (origin.X / vec1.X)) - (vec2.Z * (origin.Y / vec2.Y)); plainParameter.Z = origin.Z - (vec1.Z * (origin.X / vec1.X)) - (vec2.Z * (origin.Y / vec2.Y));
// plainParameter.Z --> plainParameter.X, plainParameter.Y // plainParameter.Z --> plainParameter.X, plainParameter.Y
plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z); plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z);
plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z); plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z);
plainParameter.X = 1 / plainParameter.X; plainParameter.X = 1 / plainParameter.X;
plainParameter.Y = 1 / plainParameter.Y; plainParameter.Y = 1 / plainParameter.Y;
plainParameter.Z = 1 / plainParameter.Z; plainParameter.Z = 1 / plainParameter.Z;
} }
} }
} }
@@ -1,121 +1,121 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Polygon4" // file="Polygon4"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Numerics; using System.Numerics;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class Polygon4 : PlainGeometry public class Polygon4 : PlainGeometry
{ {
protected static int[] Indices = [ protected static int[] Indices = [
0, 0,
1, 1,
2, 2,
0, 0,
2, 2,
3 3
]; ];
internal Polygon4() internal Polygon4()
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
vertexMat = new Vec4[4]; vertexMat = new Vec4[4];
} }
internal Polygon4(Vec4[] rawCoord) internal Polygon4(Vec4[] rawCoord)
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
if (rawCoord.Length != 4) { if (rawCoord.Length != 4) {
throw new ArgumentOutOfRangeException(nameof(rawCoord)); throw new ArgumentOutOfRangeException(nameof(rawCoord));
} }
vertexMat = rawCoord; vertexMat = rawCoord;
} }
public Polygon4(Point topLeft, Point topRight, Point bottomRight, Point bottomLeft) public Polygon4(Point topLeft, Point topRight, Point bottomRight, Point bottomLeft)
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
this[0] = topLeft; this[0] = topLeft;
this[1] = topRight; this[1] = topRight;
this[2] = bottomRight; this[2] = bottomRight;
this[3] = bottomLeft; this[3] = bottomLeft;
} }
public Polygon4( public Polygon4(
CoordinationBase coordinate, CoordinationBase coordinate,
PlainCoordinate coordination, PlainCoordinate coordination,
Point topLeft, Point topLeft,
Point topRight, Point topRight,
Point bottomRight, Point bottomRight,
Point bottomLeft) Point bottomLeft)
: base(coordinate) : base(coordinate)
{ {
this[0] = topLeft; this[0] = topLeft;
this[1] = topRight; this[1] = topRight;
this[2] = bottomRight; this[2] = bottomRight;
this[3] = bottomLeft; this[3] = bottomLeft;
} }
public Polygon4(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y) public Polygon4(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
vertexMat = new Vec4[4]; vertexMat = new Vec4[4];
this[0] = new Point(v0x, v0y, 0); this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0); this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0); this[2] = new Point(v2x, v2y, 0);
this[3] = new Point(v3x, v3y, 0); this[3] = new Point(v3x, v3y, 0);
} }
public Polygon4( public Polygon4(
PlainCoordinate coordination, PlainCoordinate coordination,
float v0x, float v0x,
float v0y, float v0y,
float v1x, float v1x,
float v1y, float v1y,
float v2x, float v2x,
float v2y, float v2y,
float v3x, float v3x,
float v3y) float v3y)
: base(coordination) : base(coordination)
{ {
vertexMat = new Vec4[4]; vertexMat = new Vec4[4];
this[0] = new Point(v0x, v0y, 0); this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0); this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0); this[2] = new Point(v2x, v2y, 0);
this[3] = new Point(v3x, v3y, 0); this[3] = new Point(v3x, v3y, 0);
} }
public override ReadOnlySpan<int> VertexIndices => Indices; public override ReadOnlySpan<int> VertexIndices => Indices;
} }
} }
@@ -1,103 +1,103 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Polygon5" // file="Polygon5"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Numerics; using System.Numerics;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public unsafe class Polygon5 : PlainGeometry public unsafe class Polygon5 : PlainGeometry
{ {
internal static int[] Indices = [ internal static int[] Indices = [
0, 0,
1, 1,
2, 2,
0, 0,
2, 2,
3, 3,
0, 0,
3, 3,
4 4
]; ];
public unsafe Polygon5() public unsafe Polygon5()
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
vertexMat = new Vec4[5]; vertexMat = new Vec4[5];
} }
public Polygon5( public Polygon5(
float v0x, float v0x,
float v0y, float v0y,
float v1x, float v1x,
float v1y, float v1y,
float v2x, float v2x,
float v2y, float v2y,
float v3x, float v3x,
float v3y, float v3y,
float v4x, float v4x,
float v4y) float v4y)
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
vertexMat = new Vec4[5]; vertexMat = new Vec4[5];
this[0] = new Point(v0x, v0y, 0); this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0); this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0); this[2] = new Point(v2x, v2y, 0);
this[3] = new Point(v3x, v3y, 0); this[3] = new Point(v3x, v3y, 0);
this[4] = new Point(v4x, v4y, 0); this[4] = new Point(v4x, v4y, 0);
} }
public Polygon5( public Polygon5(
PlainCoordinate coordination, PlainCoordinate coordination,
float v0x, float v0x,
float v0y, float v0y,
float v1x, float v1x,
float v1y, float v1y,
float v2x, float v2x,
float v2y, float v2y,
float v3x, float v3x,
float v3y, float v3y,
float v4x, float v4x,
float v4y) float v4y)
: base(coordination) : base(coordination)
{ {
vertexMat = new Vec4[5]; vertexMat = new Vec4[5];
this[0] = new Point(v0x, v0y, 0); this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0); this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0); this[2] = new Point(v2x, v2y, 0);
this[3] = new Point(v3x, v3y, 0); this[3] = new Point(v3x, v3y, 0);
this[4] = new Point(v4x, v4y, 0); this[4] = new Point(v4x, v4y, 0);
} }
public override ReadOnlySpan<int> VertexIndices => Indices; public override ReadOnlySpan<int> VertexIndices => Indices;
} }
} }
@@ -1,84 +1,84 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Polygon6" // file="Polygon6"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Numerics; using System.Numerics;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class Polygon6 : PlainGeometry public class Polygon6 : PlainGeometry
{ {
internal static int[] Indices = [ internal static int[] Indices = [
0, 0,
1, 1,
2, 2,
0, 0,
2, 2,
3, 3,
0, 0,
3, 3,
4, 4,
0, 0,
4, 4,
5 5
]; ];
public Polygon6() public Polygon6()
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
vertexMat = new Vec4[6]; vertexMat = new Vec4[6];
} }
public Polygon6( public Polygon6(
PlainCoordinate coordination, PlainCoordinate coordination,
Vec2 vert0, Vec2 vert0,
Vec2 vert1, Vec2 vert1,
Vec2 vert2, Vec2 vert2,
Vec2 vert3, Vec2 vert3,
Vec2 vert4, Vec2 vert4,
Vec2 vert5, Vec2 vert5,
Vec2 vert6) Vec2 vert6)
: base(coordination) : base(coordination)
{ {
vertexMat = new Vec4[6]; vertexMat = new Vec4[6];
vertexMat[0].reg = vert0.reg; vertexMat[0].reg = vert0.reg;
vertexMat[1].reg = vert1.reg; vertexMat[1].reg = vert1.reg;
vertexMat[2].reg = vert2.reg; vertexMat[2].reg = vert2.reg;
vertexMat[3].reg = vert3.reg; vertexMat[3].reg = vert3.reg;
vertexMat[4].reg = vert4.reg; vertexMat[4].reg = vert4.reg;
vertexMat[5].reg = vert5.reg; vertexMat[5].reg = vert5.reg;
vertexMat[6].reg = vert6.reg; vertexMat[6].reg = vert6.reg;
} }
public override ReadOnlySpan<int> VertexIndices => Indices; public override ReadOnlySpan<int> VertexIndices => Indices;
} }
} }
@@ -1,87 +1,87 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Rectangle" // file="Rectangle"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Numerics; using System.Numerics;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class Rectangle : Parallelogram public class Rectangle : Parallelogram
{ {
public Rectangle(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y) public Rectangle(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y) : base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
{ {
#if DEBUG #if DEBUG
Vec2 side0 = (this[0].Coord - this[1].Coord).XY; Vec2 side0 = (this[0].Coord - this[1].Coord).XY;
Vec2 side1 = (this[2].Coord - this[1].Coord).XY; Vec2 side1 = (this[2].Coord - this[1].Coord).XY;
if (side0.Cross(side1) == 0) { if (side0.Cross(side1) == 0) {
throw new ArgumentException(); throw new ArgumentException();
} }
#endif #endif
} }
public Rectangle( public Rectangle(
PlainCoordinate coordination, PlainCoordinate coordination,
float v0x, float v0x,
float v0y, float v0y,
float v1x, float v1x,
float v1y, float v1y,
float v2x, float v2x,
float v2y, float v2y,
float v3x, float v3x,
float v3y) float v3y)
: base(coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y) : base(coordination, v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
{ {
#if DEBUG #if DEBUG
Vec2 side0 = (this[0].Coord - this[1].Coord).XY; Vec2 side0 = (this[0].Coord - this[1].Coord).XY;
Vec2 side1 = (this[2].Coord - this[1].Coord).XY; Vec2 side1 = (this[2].Coord - this[1].Coord).XY;
if (side0.Cross(side1) == 0) { if (side0.Cross(side1) == 0) {
throw new ArgumentException(); throw new ArgumentException();
} }
#endif #endif
} }
/// <summary> /// <summary>
/// Calculate movement to center /// Calculate movement to center
/// </summary> /// </summary>
/// <param _label="tick"> /// <param _label="tick">
/// CurrentPipeline time tick /// CurrentPipeline time tick
/// </param> /// </param>
/// <returns> /// <returns>
/// ///
/// </returns> /// </returns>
public virtual Vec3 MovCenter(uint tick) public virtual Vec3 MovCenter(uint tick)
{ {
return default(Vec3); return default(Vec3);
} }
} }
} }
@@ -1,47 +1,47 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Square" // file="Square"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using System.Numerics; using System.Numerics;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
/// <summary> /// <summary>
/// A square /// A square
/// </summary> /// </summary>
public class Square : Rectangle public class Square : Rectangle
{ {
public Square(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y) public Square(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y, float v3x, float v3y)
: base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y) : base(v0x, v0y, v1x, v1y, v2x, v2y, v3x, v3y)
{ {
if (true) { } if (true) { }
} }
} }
} }
@@ -1,87 +1,87 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Triangle" // file="Triangle"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Numerics; using System.Numerics;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public unsafe class Triangle : PlainGeometry public unsafe class Triangle : PlainGeometry
{ {
internal static int[] Indices = [ internal static int[] Indices = [
0, 0,
1, 1,
2 2
]; ];
public Triangle() public Triangle()
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
vertexMat = new Vec4[3]; vertexMat = new Vec4[3];
} }
public Triangle(Point vertex01, Point vertex02, Point vertex03) public Triangle(Point vertex01, Point vertex02, Point vertex03)
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
this[0] = vertex01; this[0] = vertex01;
this[1] = vertex02; this[1] = vertex02;
this[2] = vertex03; this[2] = vertex03;
} }
public Triangle(PlainCoordinate coordination, Point vertex01, Point vertex02, Point vertex03) public Triangle(PlainCoordinate coordination, Point vertex01, Point vertex02, Point vertex03)
: base(coordination) : base(coordination)
{ {
this[0] = vertex01; this[0] = vertex01;
this[1] = vertex02; this[1] = vertex02;
this[2] = vertex03; this[2] = vertex03;
} }
public Triangle(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y) public Triangle(float v0x, float v0y, float v1x, float v1y, float v2x, float v2y)
: base(PlainCoordinate.StandardPlainCoordination) : base(PlainCoordinate.StandardPlainCoordination)
{ {
this[0] = new Point(v0x, v0y, 0); this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0); this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0); this[2] = new Point(v2x, v2y, 0);
} }
public Triangle(PlainCoordinate coordination, float v0x, float v0y, float v1x, float v1y, float v2x, float v2y) public Triangle(PlainCoordinate coordination, float v0x, float v0y, float v1x, float v1y, float v2x, float v2y)
: base(coordination) : base(coordination)
{ {
this[0] = new Point(v0x, v0y, 0); this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0); this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0); this[2] = new Point(v2x, v2y, 0);
} }
public override ReadOnlySpan<int> VertexIndices => Indices; public override ReadOnlySpan<int> VertexIndices => Indices;
} }
} }
+70 -70
View File
@@ -1,70 +1,70 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Point" // file="Point"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
[StructLayout(LayoutKind.Explicit, Size = 16)] [StructLayout(LayoutKind.Explicit, Size = 16)]
public struct Point public struct Point
{ {
[FieldOffset(0)] private Vec3 coord; [FieldOffset(0)] private Vec3 coord;
[FieldOffset(0)] internal Vector4 coordVec; [FieldOffset(0)] internal Vector4 coordVec;
internal Point(Vec4 vector) internal Point(Vec4 vector)
{ {
coordVec = vector.vec; coordVec = vector.vec;
coordVec.W = 1; coordVec.W = 1;
} }
public Point(Vec3 coord) public Point(Vec3 coord)
{ {
Coord = coord; Coord = coord;
coordVec.W = 1; coordVec.W = 1;
} }
public Point(float x, float y, float z) public Point(float x, float y, float z)
{ {
coordVec = new Vector4(x, y, z, 1); coordVec = new Vector4(x, y, z, 1);
} }
public Vec3 Coord public Vec3 Coord
{ {
get => coord; get => coord;
set { coord = value; } set { coord = value; }
} }
} }
} }
@@ -1,35 +1,35 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Class1" // file="Class1"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Geometries.SpaceGeometry namespace StgSharp.Geometries.SpaceGeometry
{ {
internal class Class1 { } internal class Class1 { }
} }
@@ -1,146 +1,146 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="TriangulatedSurface" // file="TriangulatedSurface"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.HighPerformance; using StgSharp.HighPerformance;
using StgSharp.Mathematics; using StgSharp.Mathematics;
using StgSharp.Mathematics.Graphic; using StgSharp.Mathematics.Graphic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Intrinsics; using System.Runtime.Intrinsics;
using System.Text; using System.Text;
namespace StgSharp.Geometries namespace StgSharp.Geometries
{ {
public class TriangulatedSurface public class TriangulatedSurface
{ {
private HashSet<(int begin,int end)> _sides; private HashSet<(int begin,int end)> _sides;
private List<List<int>> _sideIndices; private List<List<int>> _sideIndices;
private List<int> _triangleIndices; private List<int> _triangleIndices;
private List<Vec3> _vertices; private List<Vec3> _vertices;
public TriangulatedSurface() public TriangulatedSurface()
{ {
_triangleIndices = new List<int>(); _triangleIndices = new List<int>();
_vertices = new List<Vec3>(); _vertices = new List<Vec3>();
_sides = new HashSet<(int,int)>(); _sides = new HashSet<(int,int)>();
_sideIndices = new List<List<int>>(); _sideIndices = new List<List<int>>();
} }
/**/ /**/
public IEnumerable<List<int>> SideIndicesEnumeratble public IEnumerable<List<int>> SideIndicesEnumeratble
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _sideIndices ; get => _sideIndices ;
} }
/* /*
public Triangle GetTriangle( int index ) public Triangle GetTriangle( int index )
{ {
Vec3HP v1,v2,v3; Vec3HP v1,v2,v3;
int t = index * 3; int t = index * 3;
v1 = _vertices[ t + 0 ]; v1 = _vertices[ t + 0 ];
v2 = _vertices[ t + 1 ]; v2 = _vertices[ t + 1 ];
v3 = _vertices[ t + 2 ]; v3 = _vertices[ t + 2 ];
return new Triangle( v1, v2, v3 ); return new Triangle( v1, v2, v3 );
} }
/**/ /**/
public Span<Vec3> VertexSpan public Span<Vec3> VertexSpan
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => CollectionsMarshal.AsSpan(_vertices); get => CollectionsMarshal.AsSpan(_vertices);
} }
public Span<int> TriangleIndicesSpan public Span<int> TriangleIndicesSpan
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => CollectionsMarshal.AsSpan(_triangleIndices); get => CollectionsMarshal.AsSpan(_triangleIndices);
} }
/**/ /**/
public void AddIndicesByOrder(int v1, int v2, int v3) public void AddIndicesByOrder(int v1, int v2, int v3)
{ {
_triangleIndices.Add(v1); _triangleIndices.Add(v1);
_triangleIndices.Add(v2); _triangleIndices.Add(v2);
_triangleIndices.Add(v3); _triangleIndices.Add(v3);
if (!(_sides.Remove((v1,v2)) || _sides.Remove((v2, v1)))) { if (!(_sides.Remove((v1,v2)) || _sides.Remove((v2, v1)))) {
_ = _sides.Add((v1, v2)); _ = _sides.Add((v1, v2));
} }
if (!(_sides.Remove((v2, v3)) || _sides.Remove((v3, v2)))) { if (!(_sides.Remove((v2, v3)) || _sides.Remove((v3, v2)))) {
_ = _sides.Add((v2, v3)); _ = _sides.Add((v2, v3));
} }
if (!(_sides.Remove((v3, v1)) || _sides.Remove((v1, v3)))) { if (!(_sides.Remove((v3, v1)) || _sides.Remove((v1, v3)))) {
_ = _sides.Add((v3, v1)); _ = _sides.Add((v3, v1));
} }
} }
public void AddVertexByOrder(Vec3 vertex) public void AddVertexByOrder(Vec3 vertex)
{ {
_vertices.Add(vertex); _vertices.Add(vertex);
} }
public int TriangleCount() public int TriangleCount()
{ {
return _triangleIndices.Count / 3; return _triangleIndices.Count / 3;
} }
public void TrimExcess() public void TrimExcess()
{ {
_triangleIndices.TrimExcess(); _triangleIndices.TrimExcess();
_vertices.TrimExcess(); _vertices.TrimExcess();
Dictionary<int, int> side_dictionary = _sides.ToDictionary(x => x.begin, x => x.end); Dictionary<int, int> side_dictionary = _sides.ToDictionary(x => x.begin, x => x.end);
int begin = side_dictionary.First().Key; int begin = side_dictionary.First().Key;
List<int> sideLoop = new(begin); List<int> sideLoop = new(begin);
_sideIndices.Add(sideLoop); _sideIndices.Add(sideLoop);
while (side_dictionary.Count > 0) while (side_dictionary.Count > 0)
{ {
if (side_dictionary.Remove(begin, out begin)) if (side_dictionary.Remove(begin, out begin))
{ {
sideLoop.Add(begin); sideLoop.Add(begin);
} else } else
{ {
begin = side_dictionary.First().Key; begin = side_dictionary.First().Key;
sideLoop = new List<int>(begin); sideLoop = new List<int>(begin);
_sideIndices.Add(sideLoop); _sideIndices.Add(sideLoop);
} }
} }
_sideIndices.TrimExcess(); _sideIndices.TrimExcess();
} }
public int VertexCount() public int VertexCount()
{ {
return _vertices.Count; return _vertices.Count;
} }
} }
} }
+98 -98
View File
@@ -1,98 +1,98 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Global" // file="Global"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
global using StgSharp.Internal; global using StgSharp.Internal;
global using StgSharp.Internal.Intrinsic; global using StgSharp.Internal.Intrinsic;
global global
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("StgSharp.Mathematics")] [assembly: InternalsVisibleTo("StgSharp.Mathematics")]
[assembly: InternalsVisibleTo("StgSharp.RegularAnalysis")] [assembly: InternalsVisibleTo("StgSharp.RegularAnalysis")]
[assembly: InternalsVisibleTo("StgSharpDebug")] [assembly: InternalsVisibleTo("StgSharpDebug")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Design", "Design",
"CA1008:枚举应具有零值", "CA1008:枚举应具有零值",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "type", Scope = "type",
Target = "~T:StgSharp.Graphics.OpenGL.ShaderStatus")] Target = "~T:StgSharp.Graphics.OpenGL.ShaderStatus")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Naming", "Naming",
"CA1715:标识符应具有正确的前缀", "CA1715:标识符应具有正确的前缀",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "member", Scope = "member",
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``2(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1}")] Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``2(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1}")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Naming", "Naming",
"CA1715:标识符应具有正确的前缀", "CA1715:标识符应具有正确的前缀",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "member", Scope = "member",
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``3(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2}")] Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``3(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2}")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Naming", "Naming",
"CA1715:标识符应具有正确的前缀", "CA1715:标识符应具有正确的前缀",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "member", Scope = "member",
Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``4(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2,``3}")] Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``4(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1,``2,``3}")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Naming", "Naming",
"CA1715:标识符应具有正确的前缀", "CA1715:标识符应具有正确的前缀",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "type", Scope = "type",
Target = "~T:StgSharp.Graphics.OpenGL.Uniform`4")] Target = "~T:StgSharp.Graphics.OpenGL.Uniform`4")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Design", "Design",
"CA1043:将整型或字符串参数用于索引器", "CA1043:将整型或字符串参数用于索引器",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "member", Scope = "member",
Target = "~P:StgSharp.MVVM.ViewBase.IViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")] Target = "~P:StgSharp.MVVM.ViewBase.IViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Design", "Design",
"CA1043:将整型或字符串参数用于索引器", "CA1043:将整型或字符串参数用于索引器",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "member", Scope = "member",
Target = "~P:StgSharp.MVVM.ViewBase.ViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")] Target = "~P:StgSharp.MVVM.ViewBase.ViewResponder`1.Item(StgSharp.Controlling.UsrActivity.ITrigger)")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Performance", "Performance",
"CA1864:首选 \"IDictionary.TryAdd(TKey, TValue)\" 方法", "CA1864:首选 \"IDictionary.TryAdd(TKey, TValue)\" 方法",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "member", Scope = "member",
Target = "~P:StgSharp.MVVM.ViewBase.ViewRender`1.Item(System.String)")] Target = "~P:StgSharp.MVVM.ViewBase.ViewRender`1.Item(System.String)")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Design", "Design",
"CA1033:接口方法应可由子类型调用", "CA1033:接口方法应可由子类型调用",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "member", Scope = "member",
Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Keys")] Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Keys")]
[assembly: SuppressMessage( [assembly: SuppressMessage(
"Design", "Design",
"CA1033:接口方法应可由子类型调用", "CA1033:接口方法应可由子类型调用",
Justification = "<挂起>", Justification = "<挂起>",
Scope = "member", Scope = "member",
Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Values")] Target = "~P:StgSharp.Collections.IBidirectionalDictionary`2.System#Collections#Generic#IDictionary<TFirst,TSecond>#Values")]
@@ -1,40 +1,40 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IImageProvider" // file="IImageProvider"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
public interface IImageProvider public interface IImageProvider
{ {
Image ProvideImage(); Image ProvideImage();
} }
} }
@@ -1,83 +1,83 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ImageHelper" // file="ImageHelper"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Text; using System.Text;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
public static class ImageHelper public static class ImageHelper
{ {
public static void Resize(Image i, int width, int height, ImageMovement move) public static void Resize(Image i, int width, int height, ImageMovement move)
{ {
if (i == null) { if (i == null) {
throw new ArgumentNullException(nameof(i)); throw new ArgumentNullException(nameof(i));
} }
if (i.Size == (width, height)) { if (i.Size == (width, height)) {
return; return;
} }
if (!Enum.IsDefined(typeof(ImageMovement), move)) { if (!Enum.IsDefined(typeof(ImageMovement), move)) {
throw new InvalidEnumArgumentException(nameof(move)); throw new InvalidEnumArgumentException(nameof(move));
} }
byte[] oldData = i.Data; byte[] oldData = i.Data;
i.Data = new byte[width * height * i.PixelSize]; i.Data = new byte[width * height * i.PixelSize];
i.Height = height; i.Height = height;
i.Width = width; i.Width = width;
i.PixelUpdateCount++; i.PixelUpdateCount++;
switch (move) switch (move)
{ {
case ImageMovement.Discard: case ImageMovement.Discard:
break; break;
case ImageMovement.Top: case ImageMovement.Top:
break; break;
default: default:
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
} }
[Flags] [Flags]
public enum ImageMovement public enum ImageMovement
{ {
#pragma warning disable CA1008 #pragma warning disable CA1008
Discard = 0, Discard = 0,
#pragma warning restore CA1008 #pragma warning restore CA1008
Top = 1, Top = 1,
Bottom = 2, Bottom = 2,
Left = 4, Left = 4,
Right = 8, Right = 8,
TopLeft = Top | Left, TopLeft = Top | Left,
BottomLeft = Bottom | Left, BottomLeft = Bottom | Left,
TopRight = Top | Right, TopRight = Top | Right,
BottomRight = Bottom | Right, BottomRight = Bottom | Right,
} }
} }
@@ -1,86 +1,86 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="BufferObjectBase" // file="BufferObjectBase"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Graphics; using StgSharp.Graphics;
using StgSharp.Graphics.OpenGL; using StgSharp.Graphics.OpenGL;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
/// <summary> /// <summary>
/// Interface of all kinds OpenGL BufferHandle objects /// Interface of all kinds OpenGL BufferHandle objects
/// </summary> /// </summary>
public abstract class BufferObjectBase : IDisposable public abstract class BufferObjectBase : IDisposable
{ {
protected GlHandle[] _bufferHandle; protected GlHandle[] _bufferHandle;
protected RenderStream binding; protected RenderStream binding;
/// <summary> /// <summary>
/// Get the only handle to one of the Object instance /// Get the only handle to one of the Object instance
/// </summary> /// </summary>
/// <param _label="index"> /// <param _label="index">
/// ///
/// </param> /// </param>
/// <returns> /// <returns>
/// ///
/// </returns> /// </returns>
public GlHandle this[int index] => _bufferHandle[index]; public GlHandle this[int index] => _bufferHandle[index];
/// <summary> /// <summary>
/// Bind a BufferHandle instance to OpenGL /// Bind a BufferHandle instance to OpenGL
/// </summary> /// </summary>
/// <param _label="index"> /// <param _label="index">
/// Index of handle of the object in this instance to be bind /// Index of handle of the object in this instance to be bind
/// </param> /// </param>
public abstract void Bind(int index); public abstract void Bind(int index);
public void Dispose() public void Dispose()
{ {
Dispose(disposing:true); Dispose(disposing:true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
/// <inheritdoc /> /// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}."; return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}.";
} }
protected abstract void Dispose(bool disposing); protected abstract void Dispose(bool disposing);
~BufferObjectBase() ~BufferObjectBase()
{ {
Dispose(disposing:false); Dispose(disposing:false);
} }
} }
} }
+336 -336
View File
@@ -1,336 +1,336 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="FrameworkConstant" // file="FrameworkConstant"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
public static class FrameworkConstant public static class FrameworkConstant
{ {
#region glfw #region glfw
public const int VERSION_MAJOR = 3; public const int VERSION_MAJOR = 3;
public const int VERSION_MINOR = 3; public const int VERSION_MINOR = 3;
public const int VERSION_REVISION = 8; public const int VERSION_REVISION = 8;
public const int TRUE = 1; public const int TRUE = 1;
public const int FALSE = 0; public const int FALSE = 0;
public const int RELEASE = 0; public const int RELEASE = 0;
public const int PRESS = 1; public const int PRESS = 1;
public const int REPEAT = 2; public const int REPEAT = 2;
public const int HAT_CENTERED = 0; public const int HAT_CENTERED = 0;
public const int HAT_UP = 1; public const int HAT_UP = 1;
public const int HAT_RIGHT = 2; public const int HAT_RIGHT = 2;
public const int HAT_DOWN = 4; public const int HAT_DOWN = 4;
public const int HAT_LEFT = 8; public const int HAT_LEFT = 8;
public const int HAT_RIGHT_UP = HAT_RIGHT | HAT_UP; public const int HAT_RIGHT_UP = HAT_RIGHT | HAT_UP;
public const int HAT_RIGHT_DOWN = HAT_RIGHT | HAT_DOWN; public const int HAT_RIGHT_DOWN = HAT_RIGHT | HAT_DOWN;
public const int HAT_LEFT_UP = HAT_LEFT | HAT_UP; public const int HAT_LEFT_UP = HAT_LEFT | HAT_UP;
public const int HAT_LEFT_DOWN = HAT_LEFT | HAT_DOWN; public const int HAT_LEFT_DOWN = HAT_LEFT | HAT_DOWN;
public const int KEY_UNKNOWN = -1; public const int KEY_UNKNOWN = -1;
public const int KEY_SPACE = 32; public const int KEY_SPACE = 32;
public const int KEY_APOSTROPHE = 39; public const int KEY_APOSTROPHE = 39;
public const int KEY_COMMA = 44; public const int KEY_COMMA = 44;
public const int KEY_MINUS = 45; public const int KEY_MINUS = 45;
public const int KEY_PERIOD = 46; public const int KEY_PERIOD = 46;
public const int KEY_SLASH = 47; public const int KEY_SLASH = 47;
public const int KEY_0 = 48; public const int KEY_0 = 48;
public const int KEY_1 = 49; public const int KEY_1 = 49;
public const int KEY_2 = 50; public const int KEY_2 = 50;
public const int KEY_3 = 51; public const int KEY_3 = 51;
public const int KEY_4 = 52; public const int KEY_4 = 52;
public const int KEY_5 = 53; public const int KEY_5 = 53;
public const int KEY_6 = 54; public const int KEY_6 = 54;
public const int KEY_7 = 55; public const int KEY_7 = 55;
public const int KEY_8 = 56; public const int KEY_8 = 56;
public const int KEY_9 = 57; public const int KEY_9 = 57;
public const int KEY_SEMICOLON = 59; public const int KEY_SEMICOLON = 59;
public const int KEY_EQUAL = 61; public const int KEY_EQUAL = 61;
public const int KEY_A = 65; public const int KEY_A = 65;
public const int KEY_B = 66; public const int KEY_B = 66;
public const int KEY_C = 67; public const int KEY_C = 67;
public const int KEY_D = 68; public const int KEY_D = 68;
public const int KEY_E = 69; public const int KEY_E = 69;
public const int KEY_F = 70; public const int KEY_F = 70;
public const int KEY_G = 71; public const int KEY_G = 71;
public const int KEY_H = 72; public const int KEY_H = 72;
public const int KEY_I = 73; public const int KEY_I = 73;
public const int KEY_J = 74; public const int KEY_J = 74;
public const int KEY_K = 75; public const int KEY_K = 75;
public const int KEY_L = 76; public const int KEY_L = 76;
public const int KEY_M = 77; public const int KEY_M = 77;
public const int KEY_N = 78; public const int KEY_N = 78;
public const int KEY_O = 79; public const int KEY_O = 79;
public const int KEY_P = 80; public const int KEY_P = 80;
public const int KEY_Q = 81; public const int KEY_Q = 81;
public const int KEY_R = 82; public const int KEY_R = 82;
public const int KEY_S = 83; public const int KEY_S = 83;
public const int KEY_T = 84; public const int KEY_T = 84;
public const int KEY_U = 85; public const int KEY_U = 85;
public const int KEY_V = 86; public const int KEY_V = 86;
public const int KEY_W = 87; public const int KEY_W = 87;
public const int KEY_X = 88; public const int KEY_X = 88;
public const int KEY_Y = 89; public const int KEY_Y = 89;
public const int KEY_Z = 90; public const int KEY_Z = 90;
public const int KEY_LEFT_BRACKET = 91; public const int KEY_LEFT_BRACKET = 91;
public const int KEY_BACKSLASH = 92; public const int KEY_BACKSLASH = 92;
public const int KEY_RIGHT_BRACKET = 93; public const int KEY_RIGHT_BRACKET = 93;
public const int KEY_GRAVE_ACCENT = 96; public const int KEY_GRAVE_ACCENT = 96;
public const int KEY_WORLD_1 = 161; public const int KEY_WORLD_1 = 161;
public const int KEY_WORLD_2 = 162; public const int KEY_WORLD_2 = 162;
public const int KEY_ESCAPE = 256; public const int KEY_ESCAPE = 256;
public const int KEY_ENTER = 257; public const int KEY_ENTER = 257;
public const int KEY_TAB = 258; public const int KEY_TAB = 258;
public const int KEY_BACKSPACE = 259; public const int KEY_BACKSPACE = 259;
public const int KEY_INSERT = 260; public const int KEY_INSERT = 260;
public const int KEY_DELETE = 261; public const int KEY_DELETE = 261;
public const int KEY_RIGHT = 262; public const int KEY_RIGHT = 262;
public const int KEY_LEFT = 263; public const int KEY_LEFT = 263;
public const int KEY_DOWN = 264; public const int KEY_DOWN = 264;
public const int KEY_UP = 265; public const int KEY_UP = 265;
public const int KEY_PAGE_UP = 266; public const int KEY_PAGE_UP = 266;
public const int KEY_PAGE_DOWN = 267; public const int KEY_PAGE_DOWN = 267;
public const int KEY_HOME = 268; public const int KEY_HOME = 268;
public const int KEY_END = 269; public const int KEY_END = 269;
public const int KEY_CAPS_LOCK = 280; public const int KEY_CAPS_LOCK = 280;
public const int KEY_SCROLL_LOCK = 281; public const int KEY_SCROLL_LOCK = 281;
public const int KEY_NUM_LOCK = 282; public const int KEY_NUM_LOCK = 282;
public const int KEY_PRINT_SCREEN = 283; public const int KEY_PRINT_SCREEN = 283;
public const int KEY_PAUSE = 284; public const int KEY_PAUSE = 284;
public const int KEY_F1 = 290; public const int KEY_F1 = 290;
public const int KEY_F2 = 291; public const int KEY_F2 = 291;
public const int KEY_F3 = 292; public const int KEY_F3 = 292;
public const int KEY_F4 = 293; public const int KEY_F4 = 293;
public const int KEY_F5 = 294; public const int KEY_F5 = 294;
public const int KEY_F6 = 295; public const int KEY_F6 = 295;
public const int KEY_F7 = 296; public const int KEY_F7 = 296;
public const int KEY_F8 = 297; public const int KEY_F8 = 297;
public const int KEY_F9 = 298; public const int KEY_F9 = 298;
public const int KEY_F10 = 299; public const int KEY_F10 = 299;
public const int KEY_F11 = 300; public const int KEY_F11 = 300;
public const int KEY_F12 = 301; public const int KEY_F12 = 301;
public const int KEY_F13 = 302; public const int KEY_F13 = 302;
public const int KEY_F14 = 303; public const int KEY_F14 = 303;
public const int KEY_F15 = 304; public const int KEY_F15 = 304;
public const int KEY_F16 = 305; public const int KEY_F16 = 305;
public const int KEY_F17 = 306; public const int KEY_F17 = 306;
public const int KEY_F18 = 307; public const int KEY_F18 = 307;
public const int KEY_F19 = 308; public const int KEY_F19 = 308;
public const int KEY_F20 = 309; public const int KEY_F20 = 309;
public const int KEY_F21 = 310; public const int KEY_F21 = 310;
public const int KEY_F22 = 311; public const int KEY_F22 = 311;
public const int KEY_F23 = 312; public const int KEY_F23 = 312;
public const int KEY_F24 = 313; public const int KEY_F24 = 313;
public const int KEY_F25 = 314; public const int KEY_F25 = 314;
public const int KEY_KP_0 = 320; public const int KEY_KP_0 = 320;
public const int KEY_KP_1 = 321; public const int KEY_KP_1 = 321;
public const int KEY_KP_2 = 322; public const int KEY_KP_2 = 322;
public const int KEY_KP_3 = 323; public const int KEY_KP_3 = 323;
public const int KEY_KP_4 = 324; public const int KEY_KP_4 = 324;
public const int KEY_KP_5 = 325; public const int KEY_KP_5 = 325;
public const int KEY_KP_6 = 326; public const int KEY_KP_6 = 326;
public const int KEY_KP_7 = 327; public const int KEY_KP_7 = 327;
public const int KEY_KP_8 = 328; public const int KEY_KP_8 = 328;
public const int KEY_KP_9 = 329; public const int KEY_KP_9 = 329;
public const int KEY_KP_DECIMAL = 330; public const int KEY_KP_DECIMAL = 330;
public const int KEY_KP_DIVIDE = 331; public const int KEY_KP_DIVIDE = 331;
public const int KEY_KP_MULTIPLY = 332; public const int KEY_KP_MULTIPLY = 332;
public const int KEY_KP_SUBTRACT = 333; public const int KEY_KP_SUBTRACT = 333;
public const int KEY_KP_ADD = 334; public const int KEY_KP_ADD = 334;
public const int KEY_KP_ENTER = 335; public const int KEY_KP_ENTER = 335;
public const int KEY_KP_EQUAL = 336; public const int KEY_KP_EQUAL = 336;
public const int KEY_LEFT_SHIFT = 340; public const int KEY_LEFT_SHIFT = 340;
public const int KEY_LEFT_CONTROL = 341; public const int KEY_LEFT_CONTROL = 341;
public const int KEY_LEFT_ALT = 342; public const int KEY_LEFT_ALT = 342;
public const int KEY_LEFT_SUPER = 343; public const int KEY_LEFT_SUPER = 343;
public const int KEY_RIGHT_SHIFT = 344; public const int KEY_RIGHT_SHIFT = 344;
public const int KEY_RIGHT_CONTROL = 345; public const int KEY_RIGHT_CONTROL = 345;
public const int KEY_RIGHT_ALT = 346; public const int KEY_RIGHT_ALT = 346;
public const int KEY_RIGHT_SUPER = 347; public const int KEY_RIGHT_SUPER = 347;
public const int KEY_MENU = 348; public const int KEY_MENU = 348;
public const int KEY_LAST = KEY_MENU; public const int KEY_LAST = KEY_MENU;
public const int MOD_SHIFT = 0x0001; public const int MOD_SHIFT = 0x0001;
public const int MOD_CONTROL = 0x0002; public const int MOD_CONTROL = 0x0002;
public const int MOD_ALT = 0x0004; public const int MOD_ALT = 0x0004;
public const int MOD_SUPER = 0x0008; public const int MOD_SUPER = 0x0008;
public const int MOD_CAPS_LOCK = 0x0010; public const int MOD_CAPS_LOCK = 0x0010;
public const int MOD_NUM_LOCK = 0x0020; public const int MOD_NUM_LOCK = 0x0020;
public const int MOUSE_BUTTON_1 = 0; public const int MOUSE_BUTTON_1 = 0;
public const int MOUSE_BUTTON_2 = 1; public const int MOUSE_BUTTON_2 = 1;
public const int MOUSE_BUTTON_3 = 2; public const int MOUSE_BUTTON_3 = 2;
public const int MOUSE_BUTTON_4 = 3; public const int MOUSE_BUTTON_4 = 3;
public const int MOUSE_BUTTON_5 = 4; public const int MOUSE_BUTTON_5 = 4;
public const int MOUSE_BUTTON_6 = 5; public const int MOUSE_BUTTON_6 = 5;
public const int MOUSE_BUTTON_7 = 6; public const int MOUSE_BUTTON_7 = 6;
public const int MOUSE_BUTTON_8 = 7; public const int MOUSE_BUTTON_8 = 7;
public const int MOUSE_BUTTON_LAST = MOUSE_BUTTON_8; public const int MOUSE_BUTTON_LAST = MOUSE_BUTTON_8;
public const int MOUSE_BUTTON_LEFT = MOUSE_BUTTON_1; public const int MOUSE_BUTTON_LEFT = MOUSE_BUTTON_1;
public const int MOUSE_BUTTON_RIGHT = MOUSE_BUTTON_2; public const int MOUSE_BUTTON_RIGHT = MOUSE_BUTTON_2;
public const int MOUSE_BUTTON_MIDDLE = MOUSE_BUTTON_3; public const int MOUSE_BUTTON_MIDDLE = MOUSE_BUTTON_3;
public const int JOYSTICK_1 = 0; public const int JOYSTICK_1 = 0;
public const int JOYSTICK_2 = 1; public const int JOYSTICK_2 = 1;
public const int JOYSTICK_3 = 2; public const int JOYSTICK_3 = 2;
public const int JOYSTICK_4 = 3; public const int JOYSTICK_4 = 3;
public const int JOYSTICK_5 = 4; public const int JOYSTICK_5 = 4;
public const int JOYSTICK_6 = 5; public const int JOYSTICK_6 = 5;
public const int JOYSTICK_7 = 6; public const int JOYSTICK_7 = 6;
public const int JOYSTICK_8 = 7; public const int JOYSTICK_8 = 7;
public const int JOYSTICK_9 = 8; public const int JOYSTICK_9 = 8;
public const int JOYSTICK_10 = 9; public const int JOYSTICK_10 = 9;
public const int JOYSTICK_11 = 10; public const int JOYSTICK_11 = 10;
public const int JOYSTICK_12 = 11; public const int JOYSTICK_12 = 11;
public const int JOYSTICK_13 = 12; public const int JOYSTICK_13 = 12;
public const int JOYSTICK_14 = 13; public const int JOYSTICK_14 = 13;
public const int JOYSTICK_15 = 14; public const int JOYSTICK_15 = 14;
public const int JOYSTICK_16 = 15; public const int JOYSTICK_16 = 15;
public const int JOYSTICK_LAST = JOYSTICK_16; public const int JOYSTICK_LAST = JOYSTICK_16;
public const int GAMEPAD_BUTTON_A = 0; public const int GAMEPAD_BUTTON_A = 0;
public const int GAMEPAD_BUTTON_B = 1; public const int GAMEPAD_BUTTON_B = 1;
public const int GAMEPAD_BUTTON_X = 2; public const int GAMEPAD_BUTTON_X = 2;
public const int GAMEPAD_BUTTON_Y = 3; public const int GAMEPAD_BUTTON_Y = 3;
public const int GAMEPAD_BUTTON_LEFT_BUMPER = 4; public const int GAMEPAD_BUTTON_LEFT_BUMPER = 4;
public const int GAMEPAD_BUTTON_RIGHT_BUMPER = 5; public const int GAMEPAD_BUTTON_RIGHT_BUMPER = 5;
public const int GAMEPAD_BUTTON_BACK = 6; public const int GAMEPAD_BUTTON_BACK = 6;
public const int GAMEPAD_BUTTON_START = 7; public const int GAMEPAD_BUTTON_START = 7;
public const int GAMEPAD_BUTTON_GUIDE = 8; public const int GAMEPAD_BUTTON_GUIDE = 8;
public const int GAMEPAD_BUTTON_LEFT_THUMB = 9; public const int GAMEPAD_BUTTON_LEFT_THUMB = 9;
public const int GAMEPAD_BUTTON_RIGHT_THUMB = 10; public const int GAMEPAD_BUTTON_RIGHT_THUMB = 10;
public const int GAMEPAD_BUTTON_DPAD_UP = 11; public const int GAMEPAD_BUTTON_DPAD_UP = 11;
public const int GAMEPAD_BUTTON_DPAD_RIGHT = 12; public const int GAMEPAD_BUTTON_DPAD_RIGHT = 12;
public const int GAMEPAD_BUTTON_DPAD_DOWN = 13; public const int GAMEPAD_BUTTON_DPAD_DOWN = 13;
public const int GAMEPAD_BUTTON_DPAD_LEFT = 14; public const int GAMEPAD_BUTTON_DPAD_LEFT = 14;
public const int GAMEPAD_BUTTON_LAST = GAMEPAD_BUTTON_DPAD_LEFT; public const int GAMEPAD_BUTTON_LAST = GAMEPAD_BUTTON_DPAD_LEFT;
public const int GAMEPAD_BUTTON_CROSS = GAMEPAD_BUTTON_A; public const int GAMEPAD_BUTTON_CROSS = GAMEPAD_BUTTON_A;
public const int GAMEPAD_BUTTON_CIRCLE = GAMEPAD_BUTTON_B; public const int GAMEPAD_BUTTON_CIRCLE = GAMEPAD_BUTTON_B;
public const int GAMEPAD_BUTTON_SQUARE = GAMEPAD_BUTTON_X; public const int GAMEPAD_BUTTON_SQUARE = GAMEPAD_BUTTON_X;
public const int GAMEPAD_BUTTON_TRIANGLE = GAMEPAD_BUTTON_Y; public const int GAMEPAD_BUTTON_TRIANGLE = GAMEPAD_BUTTON_Y;
public const int GAMEPAD_AXIS_LEFT_X = 0; public const int GAMEPAD_AXIS_LEFT_X = 0;
public const int GAMEPAD_AXIS_LEFT_Y = 1; public const int GAMEPAD_AXIS_LEFT_Y = 1;
public const int GAMEPAD_AXIS_RIGHT_X = 2; public const int GAMEPAD_AXIS_RIGHT_X = 2;
public const int GAMEPAD_AXIS_RIGHT_Y = 3; public const int GAMEPAD_AXIS_RIGHT_Y = 3;
public const int GAMEPAD_AXIS_LEFT_TRIGGER = 4; public const int GAMEPAD_AXIS_LEFT_TRIGGER = 4;
public const int GAMEPAD_AXIS_RIGHT_TRIGGER = 5; public const int GAMEPAD_AXIS_RIGHT_TRIGGER = 5;
public const int GAMEPAD_AXIS_LAST = GAMEPAD_AXIS_RIGHT_TRIGGER; public const int GAMEPAD_AXIS_LAST = GAMEPAD_AXIS_RIGHT_TRIGGER;
public const int NO_ERROR = 0; public const int NO_ERROR = 0;
public const int NOT_INITIALIZED = 0x00010001; public const int NOT_INITIALIZED = 0x00010001;
public const int NO_CURRENT_CONTEXT = 0x00010002; public const int NO_CURRENT_CONTEXT = 0x00010002;
public const int INVALID_ENUM = 0x00010003; public const int INVALID_ENUM = 0x00010003;
public const int INVALID_VALUE = 0x00010004; public const int INVALID_VALUE = 0x00010004;
public const int OUT_OF_MEMORY = 0x00010005; public const int OUT_OF_MEMORY = 0x00010005;
public const int API_UNAVAILABLE = 0x00010006; public const int API_UNAVAILABLE = 0x00010006;
public const int VERSION_UNAVAILABLE = 0x00010007; public const int VERSION_UNAVAILABLE = 0x00010007;
public const int PLATFORM_ERROR = 0x00010008; public const int PLATFORM_ERROR = 0x00010008;
public const int FORMAT_UNAVAILABLE = 0x00010009; public const int FORMAT_UNAVAILABLE = 0x00010009;
public const int NO_WINDOW_CONTEXT = 0x0001000A; public const int NO_WINDOW_CONTEXT = 0x0001000A;
public const int FOCUSED = 0x00020001; public const int FOCUSED = 0x00020001;
public const int ICONIFIED = 0x00020002; public const int ICONIFIED = 0x00020002;
public const int RESIZABLE = 0x00020003; public const int RESIZABLE = 0x00020003;
public const int VISIBLE = 0x00020004; public const int VISIBLE = 0x00020004;
public const int DECORATED = 0x00020005; public const int DECORATED = 0x00020005;
public const int AUTO_ICONIFY = 0x00020006; public const int AUTO_ICONIFY = 0x00020006;
public const int FLOATING = 0x00020007; public const int FLOATING = 0x00020007;
public const int MAXIMIZED = 0x00020008; public const int MAXIMIZED = 0x00020008;
public const int CENTER_CURSOR = 0x00020009; public const int CENTER_CURSOR = 0x00020009;
public const int TRANSPARENT_FRAMEBUFFER = 0x0002000A; public const int TRANSPARENT_FRAMEBUFFER = 0x0002000A;
public const int HOVERED = 0x0002000B; public const int HOVERED = 0x0002000B;
public const int FOCUS_ON_SHOW = 0x0002000C; public const int FOCUS_ON_SHOW = 0x0002000C;
public const int RED_BITS = 0x00021001; public const int RED_BITS = 0x00021001;
public const int GREEN_BITS = 0x00021002; public const int GREEN_BITS = 0x00021002;
public const int BLUE_BITS = 0x00021003; public const int BLUE_BITS = 0x00021003;
public const int ALPHA_BITS = 0x00021004; public const int ALPHA_BITS = 0x00021004;
public const int DEPTH_BITS = 0x00021005; public const int DEPTH_BITS = 0x00021005;
public const int STENCIL_BITS = 0x00021006; public const int STENCIL_BITS = 0x00021006;
public const int ACCUM_RED_BITS = 0x00021007; public const int ACCUM_RED_BITS = 0x00021007;
public const int ACCUM_GREEN_BITS = 0x00021008; public const int ACCUM_GREEN_BITS = 0x00021008;
public const int ACCUM_BLUE_BITS = 0x00021009; public const int ACCUM_BLUE_BITS = 0x00021009;
public const int ACCUM_ALPHA_BITS = 0x0002100A; public const int ACCUM_ALPHA_BITS = 0x0002100A;
public const int AUX_BUFFERS = 0x0002100B; public const int AUX_BUFFERS = 0x0002100B;
public const int STEREO = 0x0002100C; public const int STEREO = 0x0002100C;
public const int SAMPLES = 0x0002100D; public const int SAMPLES = 0x0002100D;
public const int SRGB_CAPABLE = 0x0002100E; public const int SRGB_CAPABLE = 0x0002100E;
public const int REFRESH_RATE = 0x0002100F; public const int REFRESH_RATE = 0x0002100F;
public const int DOUBLEBUFFER = 0x00021010; public const int DOUBLEBUFFER = 0x00021010;
public const int CLIENT_API = 0x00022001; public const int CLIENT_API = 0x00022001;
public const int CONTEXT_VERSION_MAJOR = 0x00022002; public const int CONTEXT_VERSION_MAJOR = 0x00022002;
public const int CONTEXT_VERSION_MINOR = 0x00022003; public const int CONTEXT_VERSION_MINOR = 0x00022003;
public const int CONTEXT_REVISION = 0x00022004; public const int CONTEXT_REVISION = 0x00022004;
public const int CONTEXT_ROBUSTNESS = 0x00022005; public const int CONTEXT_ROBUSTNESS = 0x00022005;
public const int OPENGL_FORWARD_COMPAT = 0x00022006; public const int OPENGL_FORWARD_COMPAT = 0x00022006;
public const int OPENGL_DEBUG_CONTEXT = 0x00022007; public const int OPENGL_DEBUG_CONTEXT = 0x00022007;
public const int OPENGL_PROFILE = 0x00022008; public const int OPENGL_PROFILE = 0x00022008;
public const int CONTEXT_RELEASE_BEHAVIOR = 0x00022009; public const int CONTEXT_RELEASE_BEHAVIOR = 0x00022009;
public const int CONTEXT_NO_ERROR = 0x0002200A; public const int CONTEXT_NO_ERROR = 0x0002200A;
public const int CONTEXT_CREATION_API = 0x0002200B; public const int CONTEXT_CREATION_API = 0x0002200B;
public const int SCALE_TO_MONITOR = 0x0002200C; public const int SCALE_TO_MONITOR = 0x0002200C;
public const int COCOA_RETINA_FRAMEBUFFER = 0x00023001; public const int COCOA_RETINA_FRAMEBUFFER = 0x00023001;
public const int COCOA_FRAME_NAME = 0x00023002; public const int COCOA_FRAME_NAME = 0x00023002;
public const int COCOA_GRAPHICS_SWITCHING = 0x00023003; public const int COCOA_GRAPHICS_SWITCHING = 0x00023003;
public const int X11_CLASS_NAME = 0x00024001; public const int X11_CLASS_NAME = 0x00024001;
public const int X11_INSTANCE_NAME = 0x00024002; public const int X11_INSTANCE_NAME = 0x00024002;
public const int NO_API = 0; public const int NO_API = 0;
public const int OPENGL_API = 0x00030001; public const int OPENGL_API = 0x00030001;
public const int OPENGL_ES_API = 0x00030002; public const int OPENGL_ES_API = 0x00030002;
public const int NO_ROBUSTNESS = 0; public const int NO_ROBUSTNESS = 0;
public const int NO_RESET_NOTIFICATION = 0x00031001; public const int NO_RESET_NOTIFICATION = 0x00031001;
public const int LOSE_CONTEXT_ON_RESET = 0x00031002; public const int LOSE_CONTEXT_ON_RESET = 0x00031002;
public const int OPENGL_ANY_PROFILE = 0; public const int OPENGL_ANY_PROFILE = 0;
public const int OPENGL_CORE_PROFILE = 0x00032001; public const int OPENGL_CORE_PROFILE = 0x00032001;
public const int OPENGL_COMPAT_PROFILE = 0x00032002; public const int OPENGL_COMPAT_PROFILE = 0x00032002;
public const int CURSOR = 0x00033001; public const int CURSOR = 0x00033001;
public const int STICKY_KEYS = 0x00033002; public const int STICKY_KEYS = 0x00033002;
public const int STICKY_MOUSE_BUTTONS = 0x00033003; public const int STICKY_MOUSE_BUTTONS = 0x00033003;
public const int LOCK_KEY_MODS = 0x00033004; public const int LOCK_KEY_MODS = 0x00033004;
public const int RAW_MOUSE_MOTION = 0x00033005; public const int RAW_MOUSE_MOTION = 0x00033005;
public const int CURSOR_NORMAL = 0x00034001; public const int CURSOR_NORMAL = 0x00034001;
public const int CURSOR_HIDDEN = 0x00034002; public const int CURSOR_HIDDEN = 0x00034002;
public const int CURSOR_DISABLED = 0x00034003; public const int CURSOR_DISABLED = 0x00034003;
public const int ANY_RELEASE_BEHAVIOR = 0; public const int ANY_RELEASE_BEHAVIOR = 0;
public const int RELEASE_BEHAVIOR_FLUSH = 0x00035001; public const int RELEASE_BEHAVIOR_FLUSH = 0x00035001;
public const int RELEASE_BEHAVIOR_NONE = 0x00035002; public const int RELEASE_BEHAVIOR_NONE = 0x00035002;
public const int NATIVE_CONTEXT_API = 0x00036001; public const int NATIVE_CONTEXT_API = 0x00036001;
public const int EGL_CONTEXT_API = 0x00036002; public const int EGL_CONTEXT_API = 0x00036002;
public const int OSMESA_CONTEXT_API = 0x00036003; public const int OSMESA_CONTEXT_API = 0x00036003;
public const int ARROW_CURSOR = 0x00036001; public const int ARROW_CURSOR = 0x00036001;
public const int IBEAM_CURSOR = 0x00036002; public const int IBEAM_CURSOR = 0x00036002;
public const int CROSSHAIR_CURSOR = 0x00036003; public const int CROSSHAIR_CURSOR = 0x00036003;
public const int HAND_CURSOR = 0x00036004; public const int HAND_CURSOR = 0x00036004;
public const int HRESIZE_CURSOR = 0x00036005; public const int HRESIZE_CURSOR = 0x00036005;
public const int VRESIZE_CURSOR = 0x00036006; public const int VRESIZE_CURSOR = 0x00036006;
public const int CONNECTED = 0x00040001; public const int CONNECTED = 0x00040001;
public const int DISCONNECTED = 0x00040002; public const int DISCONNECTED = 0x00040002;
public const int JOYSTICK_HAT_BUTTONS = 0x00050001; public const int JOYSTICK_HAT_BUTTONS = 0x00050001;
public const int COCOA_CHDIR_RESOURCES = 0x00051001; public const int COCOA_CHDIR_RESOURCES = 0x00051001;
public const int COCOA_MENUBAR = 0x00051002; public const int COCOA_MENUBAR = 0x00051002;
public const int DONT_CARE = -1; public const int DONT_CARE = -1;
#endregion #endregion
} }
} }
+40 -40
View File
@@ -1,40 +1,40 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="IGraphicAPIs" // file="IGraphicAPIs"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
public interface IGraphicAPIs public interface IGraphicAPIs
{ {
public IntPtr GraphicApiPackageHandle { get; } public IntPtr GraphicApiPackageHandle { get; }
} }
} }
+190 -190
View File
@@ -1,191 +1,191 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="Image" // file="Image"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Graphics.OpenGL; using StgSharp.Graphics.OpenGL;
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
public class Image : ISSDSerializable, IImageProvider public class Image : ISSDSerializable, IImageProvider
{ {
private byte[] _data; private byte[] _data;
private ImageInfo _rawInfo; private ImageInfo _rawInfo;
private int _pixelUpdateCount = 0; private int _pixelUpdateCount = 0;
internal unsafe Image() internal unsafe Image()
{ {
_rawInfo = new ImageInfo(); _rawInfo = new ImageInfo();
} }
internal Image(ImageInfo information) internal Image(ImageInfo information)
{ {
_rawInfo = information; _rawInfo = information;
_data = []; _data = [];
// int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel; // int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
} }
public (int width, int height) Size public (int width, int height) Size
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (_rawInfo.Width, _rawInfo.Height); get => (_rawInfo.Width, _rawInfo.Height);
} }
public byte[] PixelBuffer public byte[] PixelBuffer
{ {
get get
{ {
if ((_data.Length == 0) || (_data == null)) if ((_data.Length == 0) || (_data == null))
{ {
GetBytes(); GetBytes();
return _data!; return _data!;
} }
return _data; return _data;
} }
} }
public ImageChannel Channel => _rawInfo.Channel; public ImageChannel Channel => _rawInfo.Channel;
/// <summary> /// <summary>
/// Hash code of time pixels updated last time. /// Hash code of time pixels updated last time.
/// </summary> /// </summary>
public int PixelUpdateCount public int PixelUpdateCount
{ {
get => _pixelUpdateCount; get => _pixelUpdateCount;
internal set => _pixelUpdateCount = value; internal set => _pixelUpdateCount = value;
} }
public int ChannelCount => _rawInfo.ChannelCount; public int ChannelCount => _rawInfo.ChannelCount;
public int Height public int Height
{ {
get => _rawInfo.Height; get => _rawInfo.Height;
internal set => _rawInfo.Height = value; internal set => _rawInfo.Height = value;
} }
public int Width public int Width
{ {
get => _rawInfo.Width; get => _rawInfo.Width;
internal set => _rawInfo.Width = value; internal set => _rawInfo.Width = value;
} }
public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel); public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel);
public PixelChannelLayout PixelLayout public PixelChannelLayout PixelLayout
{ {
get => _rawInfo.pixelLayout; get => _rawInfo.pixelLayout;
private set => _rawInfo.pixelLayout = value; private set => _rawInfo.pixelLayout = value;
} }
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage; public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
internal ref byte[] Data => ref _data; internal ref byte[] Data => ref _data;
public void FromBytes(byte[] stream) { } public void FromBytes(byte[] stream) { }
public static unsafe Image FromFile(string route, ImageLoader loader) public static unsafe Image FromFile(string route, ImageLoader loader)
{ {
Image ret = new Image(); Image ret = new Image();
fixed (ImageInfo* iptr = &ret._rawInfo) { fixed (ImageInfo* iptr = &ret._rawInfo) {
GraphicFramework.InternalLoadImage(route, iptr, loader); GraphicFramework.InternalLoadImage(route, iptr, loader);
} }
return ret; return ret;
} }
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream) public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
{ {
ImageInfo _info = new ImageInfo ImageInfo _info = new ImageInfo
{ {
Height = size.height, Height = size.height,
Width = size.width, Width = size.width,
Channel = channel, Channel = channel,
StreamPtr = IntPtr.Zero StreamPtr = IntPtr.Zero
}; };
Image ret = new Image(_info); Image ret = new Image(_info);
ret.PixelLayout = PixelChannelLayout.Byte; ret.PixelLayout = PixelChannelLayout.Byte;
ret._data = stream; ret._data = stream;
return ret; return ret;
} }
public static Image FromMemory( public static Image FromMemory(
(int width, int height) size, (int width, int height) size,
ImageChannel channel, ImageChannel channel,
PixelChannelLayout layout, PixelChannelLayout layout,
byte[] stream) byte[] stream)
{ {
ImageInfo _info = new ImageInfo ImageInfo _info = new ImageInfo
{ {
Height = size.height, Height = size.height,
Width = size.width, Width = size.width,
Channel = channel, Channel = channel,
StreamPtr = IntPtr.Zero StreamPtr = IntPtr.Zero
}; };
Image ret = new Image(_info); Image ret = new Image(_info);
ret.PixelLayout = layout; ret.PixelLayout = layout;
ret._data = stream; ret._data = stream;
return ret; return ret;
} }
public unsafe byte[] GetBytes() public unsafe byte[] GetBytes()
{ {
if (_data.Length == 0) if (_data.Length == 0)
{ {
int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel); int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel);
_data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray(); _data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray();
fixed (ImageInfo* pptr = &_rawInfo) { fixed (ImageInfo* pptr = &_rawInfo) {
GraphicFramework.InternalUnloadImage(pptr); GraphicFramework.InternalUnloadImage(pptr);
} }
_rawInfo.StreamPtr = IntPtr.Zero; _rawInfo.StreamPtr = IntPtr.Zero;
} }
return _data; return _data;
} }
public Image ProvideImage() public Image ProvideImage()
{ {
return this; return this;
} }
internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount) internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount)
{ {
return new Image return new Image
{ {
_rawInfo = info, _rawInfo = info,
_data = data, _data = data,
_pixelUpdateCount = operationCount _pixelUpdateCount = operationCount
}; };
} }
byte[] ISSDSerializable.GetBytes() byte[] ISSDSerializable.GetBytes()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
} }
+162 -162
View File
@@ -1,162 +1,162 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="ImageInfo" // file="ImageInfo"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in all // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// //
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.Graphics.OpenGL; using StgSharp.Graphics.OpenGL;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace StgSharp.Graphics namespace StgSharp.Graphics
{ {
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public delegate IntPtr ImageLoader( public delegate IntPtr ImageLoader(
string name, string name,
ref int width, ref int width,
ref int height, ref int height,
ref int definedChannel, ref int definedChannel,
int desiredChannel); int desiredChannel);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct ImageInfo internal struct ImageInfo
{ {
private ImageChannel channel; private ImageChannel channel;
private int height; private int height;
private int width; private int width;
private IntPtr pixelPtr; private IntPtr pixelPtr;
internal PixelChannelLayout pixelLayout; internal PixelChannelLayout pixelLayout;
public ImageChannel Channel public ImageChannel Channel
{ {
get => channel; get => channel;
set { channel = value; } set { channel = value; }
} }
public int ChannelCount public int ChannelCount
{ {
get => GetChannelCount(channel); get => GetChannelCount(channel);
} }
public int Height public int Height
{ {
get => height; get => height;
set => height = value; set => height = value;
} }
public int StreamSize public int StreamSize
{ {
get => width * height * GetPixelSize( get => width * height * GetPixelSize(
pixelLayout, channel); pixelLayout, channel);
} }
public int Width public int Width
{ {
get => width; get => width;
set => width = value; set => width = value;
} }
public IntPtr StreamPtr public IntPtr StreamPtr
{ {
get => pixelPtr; get => pixelPtr;
internal set => pixelPtr = value; internal set => pixelPtr = value;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
int hash = 17; int hash = 17;
hash = (hash * 17) + width; hash = (hash * 17) + width;
hash = (hash * 17) + height; hash = (hash * 17) + height;
hash = (hash * 17) + (int)channel; hash = (hash * 17) + (int)channel;
return hash; return hash;
} }
public override string ToString() public override string ToString()
{ {
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}"; return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
} }
internal static int GetChannelCount(ImageChannel channel) internal static int GetChannelCount(ImageChannel channel)
{ {
return channel switch return channel switch
{ {
ImageChannel.SingleColor => 1, ImageChannel.SingleColor => 1,
ImageChannel.DoubleColor => 2, ImageChannel.DoubleColor => 2,
ImageChannel.TripleColor => 3, ImageChannel.TripleColor => 3,
ImageChannel.WithAlphaChannel => 4, ImageChannel.WithAlphaChannel => 4,
_ => throw new InvalidCastException( _ => throw new InvalidCastException(
"Unknown color channel decoding setting.") "Unknown color channel decoding setting.")
}; };
} }
internal static int GetPixelSize(PixelChannelLayout layout, ImageChannel channel) internal static int GetPixelSize(PixelChannelLayout layout, ImageChannel channel)
{ {
return layout switch return layout switch
{ {
PixelChannelLayout.UByte => sizeof(byte) * GetChannelCount( PixelChannelLayout.UByte => sizeof(byte) * GetChannelCount(
channel), channel),
PixelChannelLayout.Byte => sizeof(byte) * GetChannelCount( PixelChannelLayout.Byte => sizeof(byte) * GetChannelCount(
channel), channel),
PixelChannelLayout.UShort => sizeof(short) * GetChannelCount( PixelChannelLayout.UShort => sizeof(short) * GetChannelCount(
channel), channel),
PixelChannelLayout.Short => sizeof(short) * GetChannelCount( PixelChannelLayout.Short => sizeof(short) * GetChannelCount(
channel), channel),
PixelChannelLayout.UInt => sizeof(int) * GetChannelCount( PixelChannelLayout.UInt => sizeof(int) * GetChannelCount(
channel), channel),
PixelChannelLayout.Int => sizeof(int) * GetChannelCount( PixelChannelLayout.Int => sizeof(int) * GetChannelCount(
channel), channel),
PixelChannelLayout.Float => sizeof(float) * GetChannelCount( PixelChannelLayout.Float => sizeof(float) * GetChannelCount(
channel), channel),
PixelChannelLayout.UByte332 => sizeof(byte), PixelChannelLayout.UByte332 => sizeof(byte),
PixelChannelLayout.UByte233Rev => sizeof(byte), PixelChannelLayout.UByte233Rev => sizeof(byte),
PixelChannelLayout.UShort565 => sizeof(short), PixelChannelLayout.UShort565 => sizeof(short),
PixelChannelLayout.UShort565Rev => sizeof(short), PixelChannelLayout.UShort565Rev => sizeof(short),
PixelChannelLayout.UShort4444 => sizeof(short), PixelChannelLayout.UShort4444 => sizeof(short),
PixelChannelLayout.UShort4444Rev => sizeof(short), PixelChannelLayout.UShort4444Rev => sizeof(short),
PixelChannelLayout.UShort5551 => sizeof(short), PixelChannelLayout.UShort5551 => sizeof(short),
PixelChannelLayout.UShort1555Rev => sizeof(short), PixelChannelLayout.UShort1555Rev => sizeof(short),
PixelChannelLayout.UInt8888 => sizeof(int), PixelChannelLayout.UInt8888 => sizeof(int),
PixelChannelLayout.UInt8888Rev => sizeof(int), PixelChannelLayout.UInt8888Rev => sizeof(int),
PixelChannelLayout.UInt1010102 => sizeof(int), PixelChannelLayout.UInt1010102 => sizeof(int),
PixelChannelLayout.UInt2101010Rev => sizeof(int), PixelChannelLayout.UInt2101010Rev => sizeof(int),
_ => throw new ArgumentException("Unknown layout type"), _ => throw new ArgumentException("Unknown layout type"),
}; };
} }
} }
public enum ImageChannel : uint public enum ImageChannel : uint
{ {
SingleColor = glConst.RED, SingleColor = glConst.RED,
DoubleColor = glConst.RG, DoubleColor = glConst.RG,
TripleColor = glConst.RGB, TripleColor = glConst.RGB,
WithAlphaChannel = glConst.RGBA, WithAlphaChannel = glConst.RGBA,
} }
} }

Some files were not shown because too many files have changed in this diff Show More