Reformatting code style
This commit is contained in:
parent
b94a44c7a4
commit
9e6c5ab38b
24
.idea/codeStyles/Project.xml
generated
Normal file
24
.idea/codeStyles/Project.xml
generated
Normal file
@ -0,0 +1,24 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<option name="AUTODETECT_INDENTS" value="false" />
|
||||
<RiderCodeStyleSettings>
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=0B82708A1BA7774EB13D27F245698A56/@EntryIndexedValue" value="<NamingElement Priority="1" Title="Classes and structs"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="__interface" /><type Name="class" /><type Name="struct" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=A42D627FA43B054F91D1E1C4281D8896/@EntryIndexedValue" value="<NamingElement Priority="2" Title="Concepts"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="concept" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=A7EBF16DA3BDCB42A0B710704BC8A053/@EntryIndexedValue" value="<NamingElement Priority="3" Title="Enums"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="enum" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=2229A2BE1AA9214483A51F028530E042/@EntryIndexedValue" value="<NamingElement Priority="4" Title="Unions"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="union" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=1350D079A82E0740947E85445B5AF47C/@EntryIndexedValue" value="<NamingElement Priority="6" Title="Parameters"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="function parameter" /><type Name="lambda parameter" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=0AFB7787612DF743B09AD9412E48D4CC/@EntryIndexedValue" value="<NamingElement Priority="7" Title="Local variables"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="local variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=72514D5DF422D442B71A277F97B72887/@EntryIndexedValue" value="<NamingElement Priority="8" Title="Global variables"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=8F69F48E2532F54CBAA0039D4557825E/@EntryIndexedValue" value="<NamingElement Priority="10" Title="Global functions"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global function" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=B6E900853D6D05429D8C57765B2E546A/@EntryIndexedValue" value="<NamingElement Priority="11" Title="Class and struct methods"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="member function" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=B82A063F0DDD98498A70D8D7EBB97F8D/@EntryIndexedValue" value="<NamingElement Priority="12" Title="Class and struct fields"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="class field" /><type Name="struct field" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="_" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=BBE8AA08E662BF409B2CB08EC597C493/@EntryIndexedValue" value="<NamingElement Priority="13" Title="Class and struct public fields"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="PUBLIC"><type Name="class field" /><type Name="struct field" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=5653BA7B6222F349B94149A2A53C35B8/@EntryIndexedValue" value="<NamingElement Priority="14" Title="Union members"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="union member" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=4203BE6F332C5149B409B4D5F7197E54/@EntryIndexedValue" value="<NamingElement Priority="15" Title="Enumerators"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="scoped enumerator" /><type Name="unscoped enumerator" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=2B232F1067F0324F8FF4B9D63ACECDB2/@EntryIndexedValue" value="<NamingElement Priority="16" Title="Other constants"><Descriptor Static="True" Constexpr="Indeterminate" Const="True" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="class field" /><type Name="local variable" /><type Name="struct field" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=BF0D1AE66D64FE4FAF613448A12051A0/@EntryIndexedValue" value="<NamingElement Priority="17" Title="Global constants"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="True" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
|
||||
</RiderCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
2
.idea/codeStyles/codeStyleConfig.xml
generated
2
.idea/codeStyles/codeStyleConfig.xml
generated
@ -1,5 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="EtrediaEmpires" />
|
||||
</state>
|
||||
</component>
|
||||
108
.idea/editor.xml
generated
108
.idea/editor.xml
generated
@ -245,101 +245,31 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALLOW_COMMENT_AFTER_LBRACE/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/EMPTY_BLOCK_STYLE/@EntryValue" value="TOGETHER_SAME_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/REQUIRES_EXPRESSION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_METHOD/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_METHOD/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_METHOD/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_METHOD/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BETWEEN_CLOSING_ANGLE_BRACKETS_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
|
||||
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=0AFB7787612DF743B09AD9412E48D4CC/@EntryIndexedValue" value="<NamingElement Priority="7" Title="Local variables"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="local variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=0B82708A1BA7774EB13D27F245698A56/@EntryIndexedValue" value="<NamingElement Priority="1" Title="Classes and structs"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="__interface" /><type Name="class" /><type Name="struct" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=1350D079A82E0740947E85445B5AF47C/@EntryIndexedValue" value="<NamingElement Priority="6" Title="Parameters"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="function parameter" /><type Name="lambda parameter" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=2229A2BE1AA9214483A51F028530E042/@EntryIndexedValue" value="<NamingElement Priority="4" Title="Unions"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="union" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=2B232F1067F0324F8FF4B9D63ACECDB2/@EntryIndexedValue" value="<NamingElement Priority="16" Title="Other constants"><Descriptor Static="True" Constexpr="Indeterminate" Const="True" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="class field" /><type Name="local variable" /><type Name="struct field" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=4203BE6F332C5149B409B4D5F7197E54/@EntryIndexedValue" value="<NamingElement Priority="15" Title="Enumerators"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="scoped enumerator" /><type Name="unscoped enumerator" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=5653BA7B6222F349B94149A2A53C35B8/@EntryIndexedValue" value="<NamingElement Priority="14" Title="Union members"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="union member" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=72514D5DF422D442B71A277F97B72887/@EntryIndexedValue" value="<NamingElement Priority="8" Title="Global variables"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=8F69F48E2532F54CBAA0039D4557825E/@EntryIndexedValue" value="<NamingElement Priority="10" Title="Global functions"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global function" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=A42D627FA43B054F91D1E1C4281D8896/@EntryIndexedValue" value="<NamingElement Priority="2" Title="Concepts"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="concept" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=A7EBF16DA3BDCB42A0B710704BC8A053/@EntryIndexedValue" value="<NamingElement Priority="3" Title="Enums"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="enum" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=B6E900853D6D05429D8C57765B2E546A/@EntryIndexedValue" value="<NamingElement Priority="11" Title="Class and struct methods"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="member function" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=B82A063F0DDD98498A70D8D7EBB97F8D/@EntryIndexedValue" value="<NamingElement Priority="12" Title="Class and struct fields"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="class field" /><type Name="struct field" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="_" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=BBE8AA08E662BF409B2CB08EC597C493/@EntryIndexedValue" value="<NamingElement Priority="13" Title="Class and struct public fields"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="PUBLIC"><type Name="class field" /><type Name="struct field" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="aaBb" /></NamingElement>" type="string" />
|
||||
<option name="/Default/CodeStyle/Naming/CppNamingOptions/Rules/=BF0D1AE66D64FE4FAF613448A12051A0/@EntryIndexedValue" value="<NamingElement Priority="17" Title="Global constants"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="True" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="global variable" /></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></NamingElement>" type="string" />
|
||||
</component>
|
||||
</project>
|
||||
@ -3,13 +3,12 @@ import GameData;
|
||||
import views;
|
||||
import std;
|
||||
|
||||
export namespace ee_assets
|
||||
{
|
||||
export namespace ee_assets {
|
||||
struct AssetData {};
|
||||
template<typename T> concept Asset = std::is_base_of_v<AssetData, T>;
|
||||
|
||||
enum AssetType
|
||||
{
|
||||
template <typename T> concept Asset = std::is_base_of_v<AssetData, T>;
|
||||
|
||||
enum AssetType {
|
||||
BINARY,
|
||||
|
||||
MAP_MESH,
|
||||
@ -20,38 +19,34 @@ export namespace ee_assets
|
||||
IMAGE
|
||||
};
|
||||
|
||||
struct AssetBinary : public AssetData
|
||||
{
|
||||
std::uint8_t* content = nullptr;
|
||||
struct AssetBinary : public AssetData {
|
||||
std::uint8_t *content = nullptr;
|
||||
std::size_t size = 0;
|
||||
|
||||
AssetBinary(std::uint8_t* &source, const std::size_t sourceSize);
|
||||
AssetBinary(std::uint8_t * & source, const std::size_t sourceSize);
|
||||
~AssetBinary();
|
||||
};
|
||||
|
||||
struct AssetMapMesh : public AssetData
|
||||
{
|
||||
struct AssetMapMesh : public AssetData {
|
||||
ee_engine::MapMesh content;
|
||||
|
||||
std::uint8_t* Serialize(std::size_t &size);
|
||||
std::uint8_t* Serialize(std::size_t& size);
|
||||
AssetMapMesh() {};
|
||||
AssetMapMesh(std::uint8_t* &source, const std::size_t sourceSize);
|
||||
AssetMapMesh(std::uint8_t * & source, const std::size_t sourceSize);
|
||||
};
|
||||
|
||||
struct AssetSave : public AssetData
|
||||
{
|
||||
struct AssetSave : public AssetData {
|
||||
ee_data::GameState content;
|
||||
|
||||
std::uint8_t* Serialize(std::size_t &size);
|
||||
std::uint8_t* Serialize(std::size_t& size);
|
||||
AssetSave() {};
|
||||
AssetSave(std::uint8_t* &source, const std::size_t sourceSize);
|
||||
AssetSave(std::uint8_t * & source, const std::size_t sourceSize);
|
||||
};
|
||||
|
||||
using AssetShader = AssetBinary;
|
||||
|
||||
struct AssetMaterial : public AssetData
|
||||
{
|
||||
struct AssetMaterial : public AssetData {
|
||||
std::uint32_t vertexShaderAssetID;
|
||||
std::uint32_t fragmentShaderAssetID;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,13 @@
|
||||
export module Input;
|
||||
import std;
|
||||
|
||||
export namespace ee_engine
|
||||
{
|
||||
struct InputHandlers
|
||||
{
|
||||
export namespace ee_engine {
|
||||
struct InputHandlers {
|
||||
std::function<void(float dx, float dy)> zooming;
|
||||
std::function<void(float x, float y, float lastX, float lastY)> mapScroll;
|
||||
};
|
||||
|
||||
class IInput
|
||||
{
|
||||
class IInput {
|
||||
public:
|
||||
virtual ~IInput() {};
|
||||
virtual void Poll() = 0;
|
||||
@ -21,6 +18,6 @@ export namespace ee_engine
|
||||
float mouseX = 0.0f, mouseY = 0.0f;
|
||||
float lastMouseX = 0.0f, lastMouseY = 0.0f;
|
||||
|
||||
explicit IInput(const InputHandlers &handlers) {this->handlers = handlers;};
|
||||
explicit IInput(const InputHandlers& handlers) { this->handlers = handlers; };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,31 +9,25 @@ import views;
|
||||
import AssetData;
|
||||
import std;
|
||||
|
||||
export namespace ee_engine
|
||||
{
|
||||
struct ShaderRefs
|
||||
{
|
||||
export namespace ee_engine {
|
||||
struct ShaderRefs {
|
||||
ee_assets::AssetShader *vertProvinces;
|
||||
ee_assets::AssetShader *fragProvinces;
|
||||
};
|
||||
|
||||
struct CameraTransform
|
||||
{
|
||||
glm::vec2 position {0.0f, 0.0f};
|
||||
struct CameraTransform {
|
||||
glm::vec2 position{0.0f, 0.0f};
|
||||
float zoom = 1.0f;
|
||||
};
|
||||
|
||||
struct MeshTransform
|
||||
{
|
||||
glm::vec2 position {0.0f, 0.0f};
|
||||
glm::vec2 scale {1.0f, 1.0f};
|
||||
struct MeshTransform {
|
||||
glm::vec2 position{0.0f, 0.0f};
|
||||
glm::vec2 scale{1.0f, 1.0f};
|
||||
float rotation;
|
||||
};
|
||||
|
||||
struct RendererCommand : public ee_utils::WorkerCommand
|
||||
{
|
||||
enum Type : std::uint8_t
|
||||
{
|
||||
struct RendererCommand : public ee_utils::WorkerCommand {
|
||||
enum Type : std::uint8_t {
|
||||
NONE,
|
||||
|
||||
UPDATE_REGION,
|
||||
@ -41,21 +35,23 @@ export namespace ee_engine
|
||||
COMPLETED
|
||||
};
|
||||
|
||||
struct RegionPayload { std::uint32_t id; ProvinceSSBO data; };
|
||||
struct RegionPayload {
|
||||
std::uint32_t id;
|
||||
ProvinceSSBO data;
|
||||
};
|
||||
|
||||
union {
|
||||
RegionPayload region;
|
||||
};
|
||||
};
|
||||
|
||||
class IRenderer : public ee_utils::Worker<RendererCommand, RendererCommand::COMPLETED>
|
||||
{
|
||||
class IRenderer : public ee_utils::Worker<RendererCommand, RendererCommand::COMPLETED> {
|
||||
public:
|
||||
virtual ~IRenderer();
|
||||
|
||||
constexpr bool isReady() const noexcept {return _isReady;}
|
||||
constexpr bool isReady() const noexcept { return _isReady; }
|
||||
|
||||
void RegisterMaterials(const ShaderRefs &shaders);
|
||||
void RegisterMaterials(const ShaderRefs& shaders);
|
||||
void RegisterMapMesh(MapMesh *mapMesh);
|
||||
|
||||
virtual void Init() = 0;
|
||||
@ -63,12 +59,11 @@ export namespace ee_engine
|
||||
void Draw();
|
||||
|
||||
virtual void ResizeWindow(int width, int height);
|
||||
void SetCamera(const CameraTransform &camera);
|
||||
void SetCamera(const CameraTransform& camera);
|
||||
|
||||
constexpr CameraTransform getCamera() const noexcept {return camera;};
|
||||
constexpr CameraTransform getCamera() const noexcept { return camera; };
|
||||
glm::vec2 ScreenToWorld(const float screenx, const float screenY);
|
||||
glm::vec2 ScreenToWorld(const glm::vec2 &screenPos);
|
||||
|
||||
glm::vec2 ScreenToWorld(const glm::vec2& screenPos);
|
||||
|
||||
protected:
|
||||
bool _isReady;
|
||||
@ -82,7 +77,11 @@ export namespace ee_engine
|
||||
MapMesh *mapMesh;
|
||||
ShaderRefs shaders;
|
||||
|
||||
struct RegionIndecies {std::size_t startIndex; std::size_t provincesCount;};
|
||||
struct RegionIndecies {
|
||||
std::size_t startIndex;
|
||||
std::size_t provincesCount;
|
||||
};
|
||||
|
||||
std::unordered_map<std::uint32_t /*id*/, RegionIndecies> regionsMapping;
|
||||
|
||||
explicit IRenderer(GLFWwindow *window);
|
||||
@ -93,9 +92,9 @@ export namespace ee_engine
|
||||
|
||||
virtual void ApplyCamera() = 0;
|
||||
|
||||
virtual void UpdateProvinces(const std::size_t index, const std::vector<ee_engine::ProvinceSSBO> &data) = 0;
|
||||
virtual void UpdateProvinces(const std::size_t index, const std::vector<ee_engine::ProvinceSSBO>& data) = 0;
|
||||
|
||||
private:
|
||||
void UpdateRegionCmd(RendererCommand &command);
|
||||
void UpdateRegionCmd(RendererCommand& command);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,21 +5,18 @@ module;
|
||||
export module views:MapView;
|
||||
import std;
|
||||
|
||||
export namespace ee_engine
|
||||
{
|
||||
struct MapMesh
|
||||
{
|
||||
struct Province
|
||||
{
|
||||
export namespace ee_engine {
|
||||
struct MapMesh {
|
||||
struct Province {
|
||||
std::vector<glm::vec2> vertices;
|
||||
std::vector<std::uint16_t> indices;
|
||||
};
|
||||
|
||||
std::unordered_map<std::uint32_t, std::vector<Province>> regions;
|
||||
};
|
||||
|
||||
struct ProvinceSSBO
|
||||
{
|
||||
struct ProvinceSSBO {
|
||||
std::uint32_t regionId;
|
||||
std::uint32_t color;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
export module views;
|
||||
export import :MapView;
|
||||
export import :MapView;
|
||||
|
||||
@ -14,46 +14,40 @@ TODO: make universal binary format, think about flatbuffers or msgpacks
|
||||
|
||||
*/
|
||||
|
||||
ee_assets::AssetBinary::AssetBinary(std::uint8_t* &source, const std::size_t sourceSize)
|
||||
{
|
||||
ee_assets::AssetBinary::AssetBinary(std::uint8_t * & source, const std::size_t sourceSize) {
|
||||
content = source;
|
||||
size = sourceSize;
|
||||
source = nullptr;
|
||||
}
|
||||
|
||||
ee_assets::AssetBinary::~AssetBinary()
|
||||
{
|
||||
ee_assets::AssetBinary::~AssetBinary() {
|
||||
if (content != nullptr)
|
||||
DeallocateArray(content);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ee_assets::AssetMapMesh::AssetMapMesh(std::uint8_t* &source, const std::size_t sourceSize)
|
||||
{
|
||||
std::uint8_t* buffer = source;
|
||||
std::uint8_t* pointer = source;
|
||||
ee_assets::AssetMapMesh::AssetMapMesh(std::uint8_t * & source, const std::size_t sourceSize) {
|
||||
std::uint8_t *buffer = source;
|
||||
std::uint8_t *pointer = source;
|
||||
std::size_t leftoverSize = sourceSize;
|
||||
source = nullptr;
|
||||
|
||||
std::uint32_t regionsCount = 0;
|
||||
ee_utils::readNext(®ionsCount, pointer, leftoverSize, sizeof(std::uint32_t));
|
||||
|
||||
for (std::uint32_t region = 0; region < regionsCount; region++)
|
||||
{
|
||||
for (std::uint32_t region = 0; region < regionsCount; region++) {
|
||||
std::uint32_t id = 0;
|
||||
glm::u8vec3 color {};
|
||||
glm::u8vec3 color{};
|
||||
if (!ee_utils::readNext(&color, pointer, leftoverSize, sizeof(glm::u8vec3)))
|
||||
break;
|
||||
id = static_cast<std::uint32_t>(color.r) << 16 |
|
||||
static_cast<std::uint32_t>(color.g) << 8 |
|
||||
static_cast<std::uint32_t>(color.b);
|
||||
static_cast<std::uint32_t>(color.g) << 8 |
|
||||
static_cast<std::uint32_t>(color.b);
|
||||
|
||||
std::uint32_t provincesCount = 0;
|
||||
ee_utils::readNext(&provincesCount, pointer, leftoverSize, sizeof(std::uint32_t));
|
||||
|
||||
for (std::uint32_t pi = 0; pi < provincesCount; pi++)
|
||||
{
|
||||
for (std::uint32_t pi = 0; pi < provincesCount; pi++) {
|
||||
ee_engine::MapMesh::Province prov;
|
||||
|
||||
std::uint32_t verticesCount = 0;
|
||||
@ -61,8 +55,7 @@ ee_assets::AssetMapMesh::AssetMapMesh(std::uint8_t* &source, const std::size_t s
|
||||
break;
|
||||
|
||||
prov.vertices.reserve(verticesCount);
|
||||
for (std::uint32_t vi = 0; vi < verticesCount; vi++)
|
||||
{
|
||||
for (std::uint32_t vi = 0; vi < verticesCount; vi++) {
|
||||
glm::vec2 vertex;
|
||||
if (!ee_utils::readNext(&vertex, pointer, leftoverSize, sizeof(glm::vec2)))
|
||||
break;
|
||||
@ -75,8 +68,7 @@ ee_assets::AssetMapMesh::AssetMapMesh(std::uint8_t* &source, const std::size_t s
|
||||
break;
|
||||
|
||||
prov.indices.reserve(indicesCount);
|
||||
for(std::uint32_t ii = 0; ii < indicesCount; ii++)
|
||||
{
|
||||
for (std::uint32_t ii = 0; ii < indicesCount; ii++) {
|
||||
std::uint16_t index = 0;
|
||||
if (!ee_utils::readNext(&index, pointer, leftoverSize, sizeof(std::uint16_t)))
|
||||
break;
|
||||
@ -92,18 +84,16 @@ ee_assets::AssetMapMesh::AssetMapMesh(std::uint8_t* &source, const std::size_t s
|
||||
}
|
||||
|
||||
|
||||
ee_assets::AssetSave::AssetSave(std::uint8_t* &source, const std::size_t sourceSize)
|
||||
{
|
||||
std::uint8_t* buffer = source;
|
||||
std::uint8_t* pointer = source;
|
||||
ee_assets::AssetSave::AssetSave(std::uint8_t * & source, const std::size_t sourceSize) {
|
||||
std::uint8_t *buffer = source;
|
||||
std::uint8_t *pointer = source;
|
||||
std::size_t leftoverSize = sourceSize;
|
||||
source = nullptr;
|
||||
|
||||
std::uint16_t subjectsCount = static_cast<std::uint16_t>(content.subjects.size());
|
||||
ee_utils::readNext(&subjectsCount, pointer, leftoverSize, sizeof(std::uint16_t));
|
||||
|
||||
for (std::uint16_t i = 0; i < subjectsCount; i++)
|
||||
{
|
||||
for (std::uint16_t i = 0; i < subjectsCount; i++) {
|
||||
ee_data::Subject subject;
|
||||
|
||||
ee_utils::readNext(&subject.tag, pointer, leftoverSize, sizeof(subject.tag));
|
||||
@ -113,10 +103,10 @@ ee_assets::AssetSave::AssetSave(std::uint8_t* &source, const std::size_t sourceS
|
||||
ee_utils::readNext(®ionsCount, pointer, leftoverSize, sizeof(std::uint16_t));
|
||||
subject.regions.resize(regionsCount);
|
||||
ee_utils::readNext(
|
||||
subject.regions.data(),
|
||||
pointer,
|
||||
leftoverSize,
|
||||
subject.regions.size() * sizeof(std::uint32_t)
|
||||
subject.regions.data(),
|
||||
pointer,
|
||||
leftoverSize,
|
||||
subject.regions.size() * sizeof(std::uint32_t)
|
||||
);
|
||||
|
||||
content.subjects.push_back(subject);
|
||||
@ -126,16 +116,11 @@ ee_assets::AssetSave::AssetSave(std::uint8_t* &source, const std::size_t sourceS
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// SERIALIZERS
|
||||
|
||||
std::uint8_t* ee_assets::AssetSave::Serialize(std::size_t &size)
|
||||
{
|
||||
std::uint8_t* ee_assets::AssetSave::Serialize(std::size_t& size) {
|
||||
size = sizeof(std::uint16_t);
|
||||
for (ee_data::Subject &subject : content.subjects)
|
||||
{
|
||||
for (ee_data::Subject& subject : content.subjects) {
|
||||
size += sizeof(subject.tag);
|
||||
size += sizeof(subject.color);
|
||||
size += sizeof(std::uint16_t) + subject.regions.size() * sizeof(std::uint32_t);
|
||||
@ -148,20 +133,19 @@ std::uint8_t* ee_assets::AssetSave::Serialize(std::size_t &size)
|
||||
std::uint16_t subjectsCount = static_cast<std::uint16_t>(content.subjects.size());
|
||||
ee_utils::writeNext(pointer, &subjectsCount, leftover, sizeof(std::uint16_t));
|
||||
|
||||
for (ee_data::Subject &subject : content.subjects)
|
||||
{
|
||||
for (ee_data::Subject& subject : content.subjects) {
|
||||
ee_utils::writeNext(pointer, &subject.tag, leftover, sizeof(subject.tag));
|
||||
ee_utils::writeNext(pointer, &subject.color, leftover, sizeof(subject.color));
|
||||
|
||||
std::uint16_t regionsCount = static_cast<std::uint16_t>(subject.regions.size());
|
||||
ee_utils::writeNext(pointer, ®ionsCount, leftover, sizeof(std::uint16_t));
|
||||
ee_utils::writeNext(
|
||||
pointer,
|
||||
subject.regions.data(),
|
||||
leftover,
|
||||
subject.regions.size() * sizeof(std::uint32_t)
|
||||
pointer,
|
||||
subject.regions.data(),
|
||||
leftover,
|
||||
subject.regions.size() * sizeof(std::uint32_t)
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,8 +7,7 @@ module Render;
|
||||
import std;
|
||||
import utils;
|
||||
|
||||
ee_engine::IRenderer::IRenderer(GLFWwindow *window)
|
||||
{
|
||||
ee_engine::IRenderer::IRenderer(GLFWwindow *window) {
|
||||
commandsMapping[RendererCommand::UPDATE_REGION] = std::bind_front(&IRenderer::UpdateRegionCmd, this);
|
||||
|
||||
this->window = window;
|
||||
@ -16,39 +15,30 @@ ee_engine::IRenderer::IRenderer(GLFWwindow *window)
|
||||
screenAspect = static_cast<float>(screenWidth) / static_cast<float>(screenHeight);
|
||||
}
|
||||
|
||||
ee_engine::IRenderer::~IRenderer()
|
||||
{
|
||||
ee_engine::IRenderer::~IRenderer() {}
|
||||
|
||||
}
|
||||
|
||||
void ee_engine::IRenderer::RegisterMaterials(const ShaderRefs &shaders)
|
||||
{
|
||||
void ee_engine::IRenderer::RegisterMaterials(const ShaderRefs& shaders) {
|
||||
this->shaders = shaders;
|
||||
}
|
||||
|
||||
void ee_engine::IRenderer::RegisterMapMesh(MapMesh* mapMesh)
|
||||
{
|
||||
void ee_engine::IRenderer::RegisterMapMesh(MapMesh *mapMesh) {
|
||||
this->mapMesh = mapMesh;
|
||||
}
|
||||
|
||||
void ee_engine::IRenderer::Draw()
|
||||
{
|
||||
void ee_engine::IRenderer::Draw() {
|
||||
Clear();
|
||||
DrawMap();
|
||||
DrawUI();
|
||||
}
|
||||
|
||||
void ee_engine::IRenderer::ResizeWindow(int width, int height)
|
||||
{
|
||||
void ee_engine::IRenderer::ResizeWindow(int width, int height) {
|
||||
screenWidth = width;
|
||||
screenHeight = height;
|
||||
screenAspect = static_cast<float>(screenWidth) / static_cast<float>(screenHeight);
|
||||
}
|
||||
|
||||
void ee_engine::IRenderer::SetCamera(const CameraTransform &camera)
|
||||
{
|
||||
if (camera.zoom <= 0)
|
||||
{
|
||||
void ee_engine::IRenderer::SetCamera(const CameraTransform& camera) {
|
||||
if (camera.zoom <= 0) {
|
||||
LOG(WARNING, "Camera zoom cannot be zero or less!");
|
||||
return;
|
||||
}
|
||||
@ -59,13 +49,13 @@ void ee_engine::IRenderer::SetCamera(const CameraTransform &camera)
|
||||
float halfWidth = camera.zoom * screenAspect;
|
||||
|
||||
glm::mat4 P = glm::ortho(
|
||||
-halfWidth, +halfWidth,
|
||||
-halfHeight, +halfHeight
|
||||
-halfWidth, +halfWidth,
|
||||
-halfHeight, +halfHeight
|
||||
);
|
||||
|
||||
glm::mat4 V = glm::translate(
|
||||
glm::mat4(1.0f),
|
||||
glm::vec3(-camera.position, 0.0f)
|
||||
glm::mat4(1.0f),
|
||||
glm::vec3(-camera.position, 0.0f)
|
||||
);
|
||||
|
||||
viewProjection = P * V;
|
||||
@ -74,13 +64,11 @@ void ee_engine::IRenderer::SetCamera(const CameraTransform &camera)
|
||||
ApplyCamera();
|
||||
}
|
||||
|
||||
glm::vec2 ee_engine::IRenderer::ScreenToWorld(const float screenX, const float screenY)
|
||||
{
|
||||
glm::vec2 ee_engine::IRenderer::ScreenToWorld(const float screenX, const float screenY) {
|
||||
return ScreenToWorld(glm::vec2(screenX, screenY));
|
||||
}
|
||||
|
||||
glm::vec2 ee_engine::IRenderer::ScreenToWorld(const glm::vec2 &screenPos)
|
||||
{
|
||||
glm::vec2 ee_engine::IRenderer::ScreenToWorld(const glm::vec2& screenPos) {
|
||||
float x = 2.0f * screenPos.x / screenWidth - 1.0f;
|
||||
float y = -2.0f * screenPos.y / screenHeight + 1.0f;
|
||||
|
||||
@ -91,16 +79,13 @@ glm::vec2 ee_engine::IRenderer::ScreenToWorld(const glm::vec2 &screenPos)
|
||||
return glm::vec2(world) / world.w;
|
||||
}
|
||||
|
||||
void ee_engine::IRenderer::UpdateRegionCmd(ee_engine::RendererCommand &command)
|
||||
{
|
||||
if (!regionsMapping.contains(command.region.id))
|
||||
{
|
||||
void ee_engine::IRenderer::UpdateRegionCmd(ee_engine::RendererCommand& command) {
|
||||
if (!regionsMapping.contains(command.region.id)) {
|
||||
LOG(WARNING, "Updating unregistered region with id: %d", command.region.id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.region.id != command.region.data.regionId)
|
||||
{
|
||||
if (command.region.id != command.region.data.regionId) {
|
||||
LOG(ERROR, "Updating regions ID is not supported! Region: %d Changed ID: %d",
|
||||
command.region.id, command.region.data.regionId);
|
||||
}
|
||||
@ -108,12 +93,11 @@ void ee_engine::IRenderer::UpdateRegionCmd(ee_engine::RendererCommand &command)
|
||||
RegionIndecies mapping = regionsMapping[command.region.id];
|
||||
std::vector<ProvinceSSBO> buffer;
|
||||
buffer.reserve(mapping.provincesCount);
|
||||
for (std::size_t i = 0; i < mapping.provincesCount; i++)
|
||||
{
|
||||
for (std::size_t i = 0; i < mapping.provincesCount; i++) {
|
||||
buffer.push_back(command.region.data);
|
||||
}
|
||||
|
||||
UpdateProvinces(mapping.startIndex, buffer);
|
||||
|
||||
command.type = ee_engine::RendererCommand::COMPLETED;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,8 +3,7 @@ import Input;
|
||||
|
||||
export
|
||||
{
|
||||
class Actions
|
||||
{
|
||||
class Actions {
|
||||
public:
|
||||
static ee_engine::InputHandlers mappings;
|
||||
|
||||
@ -14,4 +13,4 @@ export
|
||||
|
||||
Actions();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ module;
|
||||
#include <xxhash.h>
|
||||
|
||||
export module AssetManager;
|
||||
export import AssetData;
|
||||
export import AssetData;
|
||||
|
||||
import utils;
|
||||
import FileSystem;
|
||||
@ -12,28 +12,24 @@ import std;
|
||||
|
||||
export
|
||||
{
|
||||
struct AssetAddress
|
||||
{
|
||||
struct AssetAddress {
|
||||
std::atomic<void*> resource;
|
||||
};
|
||||
|
||||
struct AssetHandle
|
||||
{
|
||||
struct AssetHandle {
|
||||
static constexpr std::uint32_t INVALID_ASSET_ID = UINT32_MAX;
|
||||
std::size_t slot = 0;
|
||||
std::uint32_t id = 0;
|
||||
};
|
||||
|
||||
class AssetInfo
|
||||
{
|
||||
class AssetInfo {
|
||||
public:
|
||||
ee_assets::AssetType type = ee_assets::BINARY;
|
||||
|
||||
std::atomic<bool> isReady;
|
||||
AssetAddress* resourceAddress;
|
||||
AssetAddress *resourceAddress;
|
||||
|
||||
AssetInfo(void *resource)
|
||||
{
|
||||
AssetInfo(void *resource) {
|
||||
this->resourceAddress = Allocate<AssetAddress>();
|
||||
this->resourceAddress->resource.store(resource);
|
||||
}
|
||||
@ -43,18 +39,15 @@ export
|
||||
|
||||
AssetInfo(AssetInfo&& other) noexcept :
|
||||
type(other.type),
|
||||
resourceAddress(other.resourceAddress)
|
||||
{
|
||||
resourceAddress(other.resourceAddress) {
|
||||
isReady.store(other.isReady.load(std::memory_order_relaxed), std::memory_order_relaxed);
|
||||
|
||||
other.resourceAddress = nullptr;
|
||||
other.isReady.store(false, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
AssetInfo& operator=(AssetInfo&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
AssetInfo& operator=(AssetInfo&& other) noexcept {
|
||||
if (this != &other) {
|
||||
type = other.type;
|
||||
resourceAddress = other.resourceAddress;
|
||||
isReady.store(other.isReady.load(std::memory_order_relaxed), std::memory_order_relaxed);
|
||||
@ -66,17 +59,14 @@ export
|
||||
}
|
||||
};
|
||||
|
||||
struct AssetLoadingEntry
|
||||
{
|
||||
struct AssetLoadingEntry {
|
||||
AssetHandle handle;
|
||||
FileHandle* file;
|
||||
IFileSystem* fileOwner;
|
||||
FileHandle *file;
|
||||
IFileSystem *fileOwner;
|
||||
};
|
||||
|
||||
struct AssetStreamCommand : ee_utils::WorkerCommand
|
||||
{
|
||||
enum Type : std::uint8_t
|
||||
{
|
||||
struct AssetStreamCommand : ee_utils::WorkerCommand {
|
||||
enum Type : std::uint8_t {
|
||||
NONE,
|
||||
|
||||
LOAD,
|
||||
@ -90,14 +80,12 @@ export
|
||||
std::uint32_t targetId = AssetHandle::INVALID_ASSET_ID;
|
||||
std::filesystem::path targetPath;
|
||||
ee_assets::AssetType targetType = ee_assets::BINARY;
|
||||
std::atomic<void*>* out = nullptr;
|
||||
std::atomic<void*> *out = nullptr;
|
||||
};
|
||||
|
||||
class AssetManager final : public ee_utils::ThreadedWorker<AssetStreamCommand, AssetStreamCommand::COMPLETED>
|
||||
{
|
||||
class AssetManager final : public ee_utils::ThreadedWorker<AssetStreamCommand, AssetStreamCommand::COMPLETED> {
|
||||
public:
|
||||
AssetManager() : ThreadedWorker(L"Assets Stream", 250)
|
||||
{
|
||||
AssetManager() : ThreadedWorker(L"Assets Stream", 250) {
|
||||
commandsMapping[AssetStreamCommand::LOAD] = std::bind_front(&AssetManager::LoadCmd, this);
|
||||
commandsMapping[AssetStreamCommand::FIND] = std::bind_front(&AssetManager::FindCmd, this);
|
||||
commandsMapping[AssetStreamCommand::GET] = std::bind_front(&AssetManager::GetCmd, this);
|
||||
@ -105,22 +93,18 @@ export
|
||||
diskSystem = Allocate<NativeFileSystem>();
|
||||
}
|
||||
|
||||
~AssetManager() override
|
||||
{
|
||||
~AssetManager() override {
|
||||
Deallocate(diskSystem);
|
||||
}
|
||||
|
||||
void LoadDir(ee_assets::AssetType type, const std::filesystem::path &path)
|
||||
{
|
||||
for (const std::filesystem::directory_entry &entry : std::filesystem::directory_iterator(path))
|
||||
{
|
||||
void LoadDir(ee_assets::AssetType type, const std::filesystem::path& path) {
|
||||
for (const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(path)) {
|
||||
if (entry.is_directory()) continue;
|
||||
LoadAsync(type, entry.path());
|
||||
}
|
||||
}
|
||||
|
||||
void LoadAsync(ee_assets::AssetType type, const std::filesystem::path &path)
|
||||
{
|
||||
void LoadAsync(ee_assets::AssetType type, const std::filesystem::path& path) {
|
||||
AssetStreamCommand command;
|
||||
command.type = AssetStreamCommand::LOAD;
|
||||
command.targetPath = path;
|
||||
@ -129,8 +113,7 @@ export
|
||||
Request(command);
|
||||
}
|
||||
|
||||
AssetHandle& Find(const std::filesystem::path &path)
|
||||
{
|
||||
AssetHandle& Find(const std::filesystem::path& path) {
|
||||
std::atomic<void*> result;
|
||||
AssetStreamCommand command;
|
||||
command.type = AssetStreamCommand::FIND;
|
||||
@ -142,8 +125,7 @@ export
|
||||
return *reinterpret_cast<AssetHandle*>(command.out->load());
|
||||
}
|
||||
|
||||
AssetHandle& Find(const std::uint32_t id)
|
||||
{
|
||||
AssetHandle& Find(const std::uint32_t id) {
|
||||
std::atomic<void*> result;
|
||||
AssetStreamCommand command;
|
||||
command.type = AssetStreamCommand::FIND;
|
||||
@ -156,40 +138,37 @@ export
|
||||
}
|
||||
|
||||
// Returned resource reference should not be stored
|
||||
template <ee_assets::Asset T> T& FindOnce(const std::filesystem::path &path)
|
||||
{
|
||||
template <ee_assets::Asset T>
|
||||
T& FindOnce(const std::filesystem::path& path) {
|
||||
return Get<T>(Find(path));
|
||||
}
|
||||
|
||||
// Returned resource reference should not be stored
|
||||
template <ee_assets::Asset T> T& FindOnce(const std::uint32_t id)
|
||||
{
|
||||
template <ee_assets::Asset T>
|
||||
T& FindOnce(const std::uint32_t id) {
|
||||
return Get<T>(Find(id));
|
||||
}
|
||||
|
||||
void Redirect(const AssetHandle &handle, void *resource)
|
||||
{
|
||||
const AssetInfo &asset = activeAssets[handle.slot];
|
||||
if (asset.resourceAddress == nullptr)
|
||||
{
|
||||
void Redirect(const AssetHandle& handle, void *resource) {
|
||||
const AssetInfo& asset = activeAssets[handle.slot];
|
||||
if (asset.resourceAddress == nullptr) {
|
||||
LOG(WARNING, "Attempt to redirect empty handle");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: LEAK! Free old resource after redirecting handler to other resource
|
||||
if (asset.resourceAddress->resource.load() != nullptr)
|
||||
{
|
||||
void* oldResource = asset.resourceAddress->resource.exchange(nullptr, std::memory_order_acq_rel);
|
||||
if (asset.resourceAddress->resource.load() != nullptr) {
|
||||
void *oldResource = asset.resourceAddress->resource.exchange(nullptr, std::memory_order_acq_rel);
|
||||
//if (oldResource)
|
||||
//Deallocate(oldResource);
|
||||
//Deallocate(oldResource);
|
||||
}
|
||||
|
||||
asset.resourceAddress->resource.store(resource);
|
||||
}
|
||||
|
||||
// Returned resource reference should not be stored
|
||||
template <ee_assets::Asset T> T& Get(const AssetHandle &handle)
|
||||
{
|
||||
template <ee_assets::Asset T>
|
||||
T& Get(const AssetHandle& handle) {
|
||||
std::atomic<void*> result;
|
||||
AssetStreamCommand command;
|
||||
command.type = AssetStreamCommand::GET;
|
||||
@ -201,9 +180,8 @@ export
|
||||
return *reinterpret_cast<T*>(command.out->load());
|
||||
}
|
||||
|
||||
void Free(AssetHandle &handle)
|
||||
{
|
||||
AssetInfo &asset = activeAssets[handle.slot];
|
||||
void Free(AssetHandle& handle) {
|
||||
AssetInfo& asset = activeAssets[handle.slot];
|
||||
Redirect(handle, nullptr);
|
||||
Deallocate(asset.resourceAddress);
|
||||
asset.resourceAddress = nullptr;
|
||||
@ -212,62 +190,55 @@ export
|
||||
}
|
||||
|
||||
protected:
|
||||
void Update() override
|
||||
{
|
||||
void Update() override {
|
||||
// TODO: FinishLoadTasks()
|
||||
for (AssetLoadingEntry &entry : loadingEntries)
|
||||
{
|
||||
for (AssetLoadingEntry& entry : loadingEntries) {
|
||||
bool isReady = entry.fileOwner->PollReady(*entry.file);
|
||||
if (isReady)
|
||||
{
|
||||
if (isReady) {
|
||||
AssetInfo& asset = activeAssets[entry.handle.slot];
|
||||
|
||||
switch (asset.type)
|
||||
{
|
||||
case ee_assets::MAP_MESH:
|
||||
FinishLoadConstruct(entry, mapMeshesStorage);
|
||||
break;
|
||||
case ee_assets::SAVE:
|
||||
FinishLoadConstruct(entry, savesStorage);
|
||||
break;
|
||||
switch (asset.type) {
|
||||
case ee_assets::MAP_MESH:
|
||||
FinishLoadConstruct(entry, mapMeshesStorage);
|
||||
break;
|
||||
case ee_assets::SAVE:
|
||||
FinishLoadConstruct(entry, savesStorage);
|
||||
break;
|
||||
|
||||
case ee_assets::SHADER:
|
||||
FinishLoadConstruct(entry, shadersStorage);
|
||||
break;
|
||||
case ee_assets::MATERIAL:
|
||||
FinishLoadPlain(entry, materialsStorage);
|
||||
break;
|
||||
case ee_assets::IMAGE:
|
||||
break;
|
||||
case ee_assets::SHADER:
|
||||
FinishLoadConstruct(entry, shadersStorage);
|
||||
break;
|
||||
case ee_assets::MATERIAL:
|
||||
FinishLoadPlain(entry, materialsStorage);
|
||||
break;
|
||||
case ee_assets::IMAGE:
|
||||
break;
|
||||
|
||||
case ee_assets::BINARY:
|
||||
default:
|
||||
FinishLoadConstruct(entry, binaryStorage);
|
||||
break;
|
||||
case ee_assets::BINARY:
|
||||
default:
|
||||
FinishLoadConstruct(entry, binaryStorage);
|
||||
break;
|
||||
}
|
||||
|
||||
entry.fileOwner->Close(*entry.file);
|
||||
#ifndef NDEBUG
|
||||
#ifndef NDEBUG
|
||||
LOG(INFO, "Asset loaded: [%hs]", entry.file->debugPath.generic_u8string().c_str());
|
||||
#endif
|
||||
#endif
|
||||
entry.file = nullptr;
|
||||
asset.isReady.store(true);
|
||||
}
|
||||
}
|
||||
|
||||
std::erase_if(loadingEntries, [](const AssetLoadingEntry &entry) {
|
||||
std::erase_if(loadingEntries, [](const AssetLoadingEntry& entry) {
|
||||
return entry.file == nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void Release() override
|
||||
{
|
||||
for (const AssetInfo &asset : activeAssets)
|
||||
{
|
||||
void Release() override {
|
||||
for (const AssetInfo& asset : activeAssets) {
|
||||
//TODO: LEAK! Free resource
|
||||
if (asset.resourceAddress->resource.load() != nullptr)
|
||||
{
|
||||
void* resource = asset.resourceAddress->resource.exchange(nullptr, std::memory_order_acq_rel);
|
||||
if (asset.resourceAddress->resource.load() != nullptr) {
|
||||
void *resource = asset.resourceAddress->resource.exchange(nullptr, std::memory_order_acq_rel);
|
||||
//if (resource)
|
||||
//Deallocate(resource);
|
||||
}
|
||||
@ -275,7 +246,7 @@ export
|
||||
}
|
||||
activeAssets.clear();
|
||||
|
||||
for (AssetHandle *&handle: assetsMapping | std::views::values)
|
||||
for (AssetHandle *& handle : assetsMapping | std::views::values)
|
||||
Deallocate(handle);
|
||||
assetsMapping.clear();
|
||||
|
||||
@ -300,58 +271,54 @@ export
|
||||
std::vector<ee_assets::AssetShader*> shadersStorage;
|
||||
std::vector<ee_assets::AssetMaterial*> materialsStorage;
|
||||
|
||||
void LoadCmd(AssetStreamCommand &command)
|
||||
{
|
||||
void LoadCmd(AssetStreamCommand& command) {
|
||||
LOG(INFO, "LOAD command: [%hs]", command.targetPath.generic_u8string().c_str());
|
||||
|
||||
/* TODO: process path to select FS */
|
||||
/* TODO: select between async load and sync job task */
|
||||
|
||||
//Async load of full file without mmap in one thread
|
||||
FileHandle &file = diskSystem->Open(command.targetPath, IFileSystem::FILE_OPEN_READ);
|
||||
FileHandle& file = diskSystem->Open(command.targetPath, IFileSystem::FILE_OPEN_READ);
|
||||
|
||||
diskSystem->ReadAsync(file, static_cast<std::uint32_t>(file.size), IFileSystem::FILE_READ_SEQUENTIAL);
|
||||
|
||||
AssetHandle* handle = Allocate<AssetHandle>();
|
||||
AssetHandle *handle = Allocate<AssetHandle>();
|
||||
AssetInfo asset(nullptr);
|
||||
asset.type = command.targetType;
|
||||
|
||||
std::size_t assetPos = 0;
|
||||
if (freeAssetSlots.size() > 0)
|
||||
{
|
||||
if (freeAssetSlots.size() > 0) {
|
||||
assetPos = freeAssetSlots.back();
|
||||
Deallocate(activeAssets[assetPos].resourceAddress);
|
||||
activeAssets[assetPos] = std::move(asset);
|
||||
freeAssetSlots.pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
activeAssets.push_back(std::move(asset));
|
||||
assetPos = activeAssets.size() - 1;
|
||||
}
|
||||
handle->slot = assetPos;
|
||||
auto assetPath = command.targetPath.generic_u8string();
|
||||
std::uint32_t assetId = assetsIdMapping[command.targetPath] =
|
||||
XXH32(assetPath.data(), assetPath.size(), ASSETS_HASH_SPACE);
|
||||
XXH32(assetPath.data(), assetPath.size(), ASSETS_HASH_SPACE);
|
||||
handle->id = assetId;
|
||||
assetsMapping[assetId] = handle;
|
||||
|
||||
AssetLoadingEntry loadingEntry {
|
||||
.handle = *handle,
|
||||
.file = &file,
|
||||
.fileOwner = diskSystem
|
||||
AssetLoadingEntry loadingEntry{
|
||||
.handle = *handle,
|
||||
.file = &file,
|
||||
.fileOwner = diskSystem
|
||||
};
|
||||
loadingEntries.push_back(loadingEntry);
|
||||
|
||||
command.type = AssetStreamCommand::COMPLETED;
|
||||
}
|
||||
|
||||
void FindCmd(AssetStreamCommand &command)
|
||||
{
|
||||
void FindCmd(AssetStreamCommand& command) {
|
||||
std::uint32_t id = command.targetId;
|
||||
if (id == AssetHandle::INVALID_ASSET_ID)
|
||||
{
|
||||
std::unordered_map<std::filesystem::path, std::uint32_t>::iterator idMapping = assetsIdMapping.find(command.targetPath);
|
||||
if (id == AssetHandle::INVALID_ASSET_ID) {
|
||||
std::unordered_map<std::filesystem::path, std::uint32_t>::iterator idMapping = assetsIdMapping.find(
|
||||
command.targetPath);
|
||||
if (idMapping == assetsIdMapping.end())
|
||||
return;
|
||||
id = idMapping->second;
|
||||
@ -368,8 +335,7 @@ export
|
||||
command.type = AssetStreamCommand::COMPLETED;
|
||||
}
|
||||
|
||||
void GetCmd(AssetStreamCommand &command)
|
||||
{
|
||||
void GetCmd(AssetStreamCommand& command) {
|
||||
if (activeAssets.size() <= command.target.slot)
|
||||
return;
|
||||
if (!activeAssets[command.target.slot].isReady)
|
||||
@ -381,16 +347,16 @@ export
|
||||
command.type = AssetStreamCommand::COMPLETED;
|
||||
}
|
||||
|
||||
template<ee_assets::Asset T> void FinishLoadConstruct(AssetLoadingEntry &loaded, std::vector<T*> &storage)
|
||||
{
|
||||
T* resource = Allocate<T>(loaded.file->data, loaded.file->size);
|
||||
template <ee_assets::Asset T>
|
||||
void FinishLoadConstruct(AssetLoadingEntry& loaded, std::vector<T*>& storage) {
|
||||
T *resource = Allocate<T>(loaded.file->data, loaded.file->size);
|
||||
storage.push_back(resource);
|
||||
Redirect(loaded.handle, storage.back());
|
||||
}
|
||||
|
||||
template<ee_assets::Asset T> void FinishLoadPlain(AssetLoadingEntry &loaded, std::vector<T*> &storage)
|
||||
{
|
||||
T* resource = Allocate<T>();
|
||||
template <ee_assets::Asset T>
|
||||
void FinishLoadPlain(AssetLoadingEntry& loaded, std::vector<T*>& storage) {
|
||||
T *resource = Allocate<T>();
|
||||
if (loaded.file->size < sizeof(T))
|
||||
LOG(CRITICAL, "File size is less than needed for asset of type: %d", typeid(T).name());
|
||||
std::memcpy(resource, loaded.file->data, sizeof(T));
|
||||
@ -398,10 +364,9 @@ export
|
||||
Redirect(loaded.handle, storage.back());
|
||||
}
|
||||
|
||||
template<ee_assets::Asset T> void ClearStorage(std::vector<T*> &storage)
|
||||
{
|
||||
for (T* &resource : storage)
|
||||
{
|
||||
template <ee_assets::Asset T>
|
||||
void ClearStorage(std::vector<T*>& storage) {
|
||||
for (T * & resource : storage) {
|
||||
if (resource != nullptr)
|
||||
Deallocate(resource);
|
||||
}
|
||||
|
||||
@ -7,10 +7,8 @@ import std;
|
||||
|
||||
export
|
||||
{
|
||||
struct ClientCommand : public ee_utils::WorkerCommand
|
||||
{
|
||||
enum Type : std::uint8_t
|
||||
{
|
||||
struct ClientCommand : public ee_utils::WorkerCommand {
|
||||
enum Type : std::uint8_t {
|
||||
NONE,
|
||||
|
||||
SEND,
|
||||
@ -19,8 +17,7 @@ export
|
||||
};
|
||||
};
|
||||
|
||||
class Client final : public ee_utils::ThreadedWorker<ClientCommand, ClientCommand::COMPLETED>
|
||||
{
|
||||
class Client final : public ee_utils::ThreadedWorker<ClientCommand, ClientCommand::COMPLETED> {
|
||||
public:
|
||||
Client();
|
||||
~Client() override;
|
||||
@ -41,7 +38,7 @@ export
|
||||
NetworkChannel *networkConnection = nullptr;
|
||||
AssetHandle save;
|
||||
|
||||
void SendCmd(ClientCommand &command);
|
||||
void SendCmd(ClientCommand& command);
|
||||
|
||||
void ViewModelSubject(ee_data::Subject subject);
|
||||
};
|
||||
|
||||
@ -4,21 +4,14 @@ export module DataChannel;
|
||||
|
||||
export
|
||||
{
|
||||
class IDataChannel
|
||||
{
|
||||
class IDataChannel {
|
||||
public:
|
||||
// virtual void Request() = 0;
|
||||
// virtual void Listen() = 0;
|
||||
// virtual void Mute() = 0;
|
||||
};
|
||||
|
||||
class NetworkChannel final : public IDataChannel
|
||||
{
|
||||
class NetworkChannel final : public IDataChannel {};
|
||||
|
||||
};
|
||||
|
||||
class ThreadChannel final : public IDataChannel
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
class ThreadChannel final : public IDataChannel {};
|
||||
}
|
||||
|
||||
@ -3,17 +3,16 @@ module;
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
export module Engine;
|
||||
export import Render;
|
||||
export import Input;
|
||||
export import AssetManager;
|
||||
export import Client;
|
||||
export import Render;
|
||||
export import Input;
|
||||
export import AssetManager;
|
||||
export import Client;
|
||||
|
||||
import utils;
|
||||
|
||||
export
|
||||
{
|
||||
class Engine
|
||||
{
|
||||
class Engine {
|
||||
public:
|
||||
inline static GLFWwindow *window;
|
||||
inline static ee_engine::IInput *input;
|
||||
@ -21,13 +20,11 @@ export
|
||||
inline static ee_engine::IRenderer *renderer;
|
||||
inline static Client *client;
|
||||
|
||||
static void Shutdown()
|
||||
{
|
||||
static void Shutdown() {
|
||||
if (input != nullptr)
|
||||
Deallocate(input);
|
||||
|
||||
if (renderer != nullptr)
|
||||
{
|
||||
if (renderer != nullptr) {
|
||||
renderer->Shutdown();
|
||||
Deallocate(renderer);
|
||||
}
|
||||
@ -41,12 +38,10 @@ export
|
||||
}
|
||||
|
||||
template <ee_utils::IThreadedWorker T>
|
||||
static void WaitThreadShutdown(T* &thread)
|
||||
{
|
||||
if (thread != nullptr)
|
||||
{
|
||||
static void WaitThreadShutdown(T * & thread) {
|
||||
if (thread != nullptr) {
|
||||
thread->Shutdown();
|
||||
while(thread->isRunning.load()) {}
|
||||
while (thread->isRunning.load()) {}
|
||||
Deallocate(thread);
|
||||
}
|
||||
thread = nullptr;
|
||||
@ -55,4 +50,4 @@ export
|
||||
private:
|
||||
Engine();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,17 +15,17 @@ export
|
||||
std::uint8_t *data = nullptr;
|
||||
std::uint8_t *buffer = nullptr;
|
||||
|
||||
#ifndef NDEBUG
|
||||
#ifndef NDEBUG
|
||||
std::filesystem::path debugPath;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef _WIN32
|
||||
HANDLE win32Handle = INVALID_HANDLE_VALUE;
|
||||
OVERLAPPED overlapped;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#endif
|
||||
};
|
||||
|
||||
class IFileSystem {
|
||||
@ -37,33 +37,32 @@ export
|
||||
inline static constexpr std::uint32_t FILE_READ_SEQUENTIAL = 0;
|
||||
inline static constexpr std::uint32_t FILE_READ_RANDOM_ACCESS = (1 << 0);
|
||||
|
||||
virtual FileHandle &Open(const std::filesystem::path &path, const std::uint32_t flags) = 0;
|
||||
virtual FileHandle& Open(const std::filesystem::path& path, const std::uint32_t flags) = 0;
|
||||
|
||||
virtual void ReadAsync(FileHandle &file, const std::uint32_t bufferSize, const std::uint32_t flags) = 0;
|
||||
virtual void ReadAsync(FileHandle& file, const std::uint32_t bufferSize, const std::uint32_t flags) = 0;
|
||||
|
||||
virtual bool PollReady(FileHandle &file) = 0;
|
||||
virtual bool PollReady(FileHandle& file) = 0;
|
||||
|
||||
virtual void Close(FileHandle &file) = 0;
|
||||
virtual void Close(FileHandle& file) = 0;
|
||||
|
||||
virtual ~IFileSystem();
|
||||
|
||||
protected:
|
||||
std::vector<FileHandle *> activeFiles;
|
||||
std::vector<FileHandle *> failedFiles;
|
||||
std::vector<FileHandle*> activeFiles;
|
||||
std::vector<FileHandle*> failedFiles;
|
||||
std::vector<std::size_t> freeFileSlots;
|
||||
};
|
||||
|
||||
class NativeFileSystem final : public IFileSystem {
|
||||
public:
|
||||
FileHandle &Open(const std::filesystem::path &path, const std::uint32_t flags) override;
|
||||
FileHandle& Open(const std::filesystem::path& path, const std::uint32_t flags) override;
|
||||
|
||||
void ReadAsync(FileHandle &file, const std::uint32_t bufferSize, std::uint32_t flags) override;
|
||||
void ReadAsync(FileHandle& file, const std::uint32_t bufferSize, std::uint32_t flags) override;
|
||||
|
||||
bool PollReady(FileHandle &file) override;
|
||||
bool PollReady(FileHandle& file) override;
|
||||
|
||||
void Close(FileHandle &file) override;
|
||||
void Close(FileHandle& file) override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,9 +5,9 @@ module;
|
||||
export module GLFWInput;
|
||||
import Input;
|
||||
|
||||
export {
|
||||
class GLFWInput final : public ee_engine::IInput
|
||||
{
|
||||
export
|
||||
{
|
||||
class GLFWInput final : public ee_engine::IInput {
|
||||
public:
|
||||
GLFWInput(ee_engine::InputHandlers handlers);
|
||||
|
||||
@ -18,4 +18,4 @@ export {
|
||||
void OnRightMouseButton(int state);
|
||||
void OnMiddleMouseButton(int state);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,20 +5,18 @@ module;
|
||||
module Actions;
|
||||
import Engine;
|
||||
|
||||
ee_engine::InputHandlers Actions::mappings {
|
||||
ee_engine::InputHandlers Actions::mappings{
|
||||
.zooming = Zoom,
|
||||
.mapScroll = MapScroll
|
||||
};
|
||||
|
||||
void Actions::Zoom(float dx, float dy)
|
||||
{
|
||||
void Actions::Zoom(float dx, float dy) {
|
||||
ee_engine::CameraTransform cam = Engine::renderer->getCamera();
|
||||
cam.zoom *= pow(1.1f, -dy);
|
||||
Engine::renderer->SetCamera(cam);
|
||||
}
|
||||
|
||||
void Actions::MapScroll(float x, float y, float lastX, float lastY)
|
||||
{
|
||||
void Actions::MapScroll(float x, float y, float lastX, float lastY) {
|
||||
ee_engine::CameraTransform cam = Engine::renderer->getCamera();
|
||||
|
||||
glm::vec2 pos = Engine::renderer->ScreenToWorld(x, y);
|
||||
@ -26,4 +24,4 @@ void Actions::MapScroll(float x, float y, float lastX, float lastY)
|
||||
cam.position -= pos - lastPos;
|
||||
|
||||
Engine::renderer->SetCamera(cam);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,67 +3,50 @@ import utils;
|
||||
import views;
|
||||
import Engine;
|
||||
|
||||
Client::Client() : ThreadedWorker(L"Client", 0)
|
||||
{
|
||||
Client::Client() : ThreadedWorker(L"Client", 0) {
|
||||
commandsMapping[ClientCommand::SEND] = std::bind_front(&Client::SendCmd, this);
|
||||
}
|
||||
|
||||
void Client::Init()
|
||||
{
|
||||
if (Engine::renderer == nullptr || !Engine::renderer->isReady())
|
||||
{
|
||||
void Client::Init() {
|
||||
if (Engine::renderer == nullptr || !Engine::renderer->isReady()) {
|
||||
LOG(CRITICAL, "Renderer is not ready. Client cannot be created");
|
||||
throw std::logic_error("Renderer is not ready");
|
||||
}
|
||||
|
||||
// TEST
|
||||
ee_assets::AssetSave &asset = Engine::assetManager->Get<ee_assets::AssetSave>(save);
|
||||
ee_assets::AssetSave& asset = Engine::assetManager->Get<ee_assets::AssetSave>(save);
|
||||
ViewModelSubject(asset.content.subjects[0]);
|
||||
ViewModelSubject(asset.content.subjects[1]);
|
||||
}
|
||||
|
||||
const IDataChannel* Client::GetConnection()
|
||||
{
|
||||
const IDataChannel* Client::GetConnection() {
|
||||
return networkConnection;
|
||||
}
|
||||
|
||||
void Client::ConnectServer()
|
||||
{
|
||||
void Client::ConnectServer() {
|
||||
if (networkConnection != nullptr)
|
||||
Deallocate(networkConnection);
|
||||
|
||||
networkConnection = Allocate<NetworkChannel>();
|
||||
}
|
||||
|
||||
void Client::LoadSave(const AssetHandle save)
|
||||
{
|
||||
void Client::LoadSave(const AssetHandle save) {
|
||||
this->save = save;
|
||||
}
|
||||
|
||||
void Client::Update()
|
||||
{
|
||||
void Client::Update() {}
|
||||
|
||||
}
|
||||
|
||||
void Client::Release()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Client::SendCmd(ClientCommand &command)
|
||||
{
|
||||
void Client::Release() {}
|
||||
|
||||
|
||||
void Client::SendCmd(ClientCommand& command) {
|
||||
command.type = ClientCommand::COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
void Client::ViewModelSubject(ee_data::Subject subject)
|
||||
{
|
||||
for (const std::uint32_t region : subject.regions)
|
||||
{
|
||||
ee_engine::ProvinceSSBO vm {
|
||||
void Client::ViewModelSubject(ee_data::Subject subject) {
|
||||
for (const std::uint32_t region : subject.regions) {
|
||||
ee_engine::ProvinceSSBO vm{
|
||||
.regionId = region,
|
||||
.color = subject.color
|
||||
};
|
||||
@ -77,9 +60,7 @@ void Client::ViewModelSubject(ee_data::Subject subject)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Client::~Client()
|
||||
{
|
||||
Client::~Client() {
|
||||
if (networkConnection != nullptr)
|
||||
Deallocate(networkConnection);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,19 +7,17 @@ import utils;
|
||||
|
||||
//TOO: REWORK WITH IOCP
|
||||
|
||||
IFileSystem::~IFileSystem()
|
||||
{
|
||||
for (FileHandle* handle : activeFiles)
|
||||
IFileSystem::~IFileSystem() {
|
||||
for (FileHandle *handle : activeFiles)
|
||||
Deallocate(handle);
|
||||
for (FileHandle* handle : failedFiles)
|
||||
for (FileHandle *handle : failedFiles)
|
||||
Deallocate(handle);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
FileHandle& NativeFileSystem::Open(const std::filesystem::path &path, const std::uint32_t flags)
|
||||
{
|
||||
FileHandle* result = Allocate<FileHandle>();
|
||||
FileHandle& NativeFileSystem::Open(const std::filesystem::path& path, const std::uint32_t flags) {
|
||||
FileHandle *result = Allocate<FileHandle>();
|
||||
|
||||
#ifndef NDEBUG
|
||||
result->debugPath = path;
|
||||
@ -33,17 +31,16 @@ FileHandle& NativeFileSystem::Open(const std::filesystem::path &path, const std:
|
||||
createFileMode |= GENERIC_WRITE;
|
||||
|
||||
HANDLE file = CreateFileW(
|
||||
path.c_str(),
|
||||
createFileMode,
|
||||
NULL,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL
|
||||
path.c_str(),
|
||||
createFileMode,
|
||||
NULL,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (file == INVALID_HANDLE_VALUE) {
|
||||
LOG(ERROR, "Failed to open file %s. Error: %d", path.c_str(), GetLastError());
|
||||
failedFiles.push_back(result);
|
||||
return *result;
|
||||
@ -54,15 +51,13 @@ FileHandle& NativeFileSystem::Open(const std::filesystem::path &path, const std:
|
||||
if (result->size == INVALID_FILE_SIZE)
|
||||
LOG(ERROR, "Failed to get size of file %s. Error: %d", path.c_str(), GetLastError());
|
||||
|
||||
if (freeFileSlots.size() > 0)
|
||||
{
|
||||
if (freeFileSlots.size() > 0) {
|
||||
std::size_t pos = freeFileSlots.back();
|
||||
result->id = pos;
|
||||
activeFiles[pos] = result;
|
||||
freeFileSlots.pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
result->id = activeFiles.size();
|
||||
activeFiles.push_back(result);
|
||||
}
|
||||
@ -70,79 +65,70 @@ FileHandle& NativeFileSystem::Open(const std::filesystem::path &path, const std:
|
||||
return *result;
|
||||
}
|
||||
|
||||
void NativeFileSystem::ReadAsync(FileHandle &file, const std::uint32_t bufferSize, const std::uint32_t flags)
|
||||
{
|
||||
void NativeFileSystem::ReadAsync(FileHandle& file, const std::uint32_t bufferSize, const std::uint32_t flags) {
|
||||
file.overlapped = {
|
||||
.hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr)
|
||||
.hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr)
|
||||
};
|
||||
file.buffer = AllocateArray<std::uint8_t>(bufferSize);
|
||||
file.bufferSize = bufferSize;
|
||||
|
||||
BOOL isSync = ReadFile(
|
||||
file.win32Handle,
|
||||
file.buffer,
|
||||
bufferSize,
|
||||
NULL,
|
||||
&file.overlapped
|
||||
file.win32Handle,
|
||||
file.buffer,
|
||||
bufferSize,
|
||||
NULL,
|
||||
&file.overlapped
|
||||
);
|
||||
|
||||
if (isSync || GetLastError() != ERROR_IO_PENDING)
|
||||
LOG(ERROR, "File reading is synchronious while asynchronious is awaited");
|
||||
}
|
||||
|
||||
bool NativeFileSystem::PollReady(FileHandle &file)
|
||||
{
|
||||
bool NativeFileSystem::PollReady(FileHandle& file) {
|
||||
DWORD status = WaitForSingleObject(file.overlapped.hEvent, 0);
|
||||
|
||||
switch (status)
|
||||
switch (status) {
|
||||
case WAIT_OBJECT_0:
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
{
|
||||
if (file.size == file.bufferSize)
|
||||
{
|
||||
file.data = file.buffer;
|
||||
file.buffer = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: reserve size for data, shift and move */
|
||||
}
|
||||
|
||||
break;
|
||||
if (file.size == file.bufferSize) {
|
||||
file.data = file.buffer;
|
||||
file.buffer = nullptr;
|
||||
}
|
||||
else {
|
||||
/* TODO: reserve size for data, shift and move */
|
||||
}
|
||||
|
||||
case WAIT_ABANDONED:
|
||||
case WAIT_TIMEOUT:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
LOG(CRITICAL, "Failed to get file status. Error: %d", GetLastError());
|
||||
return false;
|
||||
}
|
||||
case WAIT_ABANDONED:
|
||||
case WAIT_TIMEOUT:
|
||||
return false;
|
||||
|
||||
default:
|
||||
{
|
||||
LOG(CRITICAL, "Failed to get file status. Error: %d", GetLastError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NativeFileSystem::Close(FileHandle &file)
|
||||
{
|
||||
void NativeFileSystem::Close(FileHandle& file) {
|
||||
if (file.overlapped.hEvent)
|
||||
CloseHandle(file.overlapped.hEvent);
|
||||
|
||||
if (file.buffer != nullptr)
|
||||
{
|
||||
if (file.buffer != nullptr) {
|
||||
DeallocateArray(file.buffer);
|
||||
file.buffer = nullptr;
|
||||
}
|
||||
if (file.data != nullptr)
|
||||
{
|
||||
if (file.data != nullptr) {
|
||||
DeallocateArray(file.data);
|
||||
file.data = nullptr;
|
||||
}
|
||||
|
||||
if (file.win32Handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (file.win32Handle != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(file.win32Handle);
|
||||
file.win32Handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
@ -154,5 +140,4 @@ void NativeFileSystem::Close(FileHandle &file)
|
||||
#ifdef __linux__
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -9,8 +9,7 @@ module GLFWInput;
|
||||
import Engine;
|
||||
import utils;
|
||||
|
||||
GLFWInput::GLFWInput(ee_engine::InputHandlers handlers) : ee_engine::IInput(handlers)
|
||||
{
|
||||
GLFWInput::GLFWInput(ee_engine::InputHandlers handlers) : ee_engine::IInput(handlers) {
|
||||
glfwSetWindowUserPointer(Engine::window, this);
|
||||
glfwSetScrollCallback(Engine::window, [](GLFWwindow *window, double dx, double dy) {
|
||||
GLFW_CALLBACK(zooming, static_cast<float>(dx), static_cast<float>(dy));
|
||||
@ -19,8 +18,7 @@ GLFWInput::GLFWInput(ee_engine::InputHandlers handlers) : ee_engine::IInput(hand
|
||||
LOG(INFO, "Input mappings initialized");
|
||||
}
|
||||
|
||||
void GLFWInput::Poll()
|
||||
{
|
||||
void GLFWInput::Poll() {
|
||||
double mouseX, mouseY;
|
||||
glfwGetCursorPos(Engine::window, &mouseX, &mouseY);
|
||||
this->mouseX = static_cast<float>(mouseX);
|
||||
@ -38,22 +36,20 @@ void GLFWInput::Poll()
|
||||
lastMouseY = this->mouseY;
|
||||
}
|
||||
|
||||
void GLFWInput::OnLeftMouseButton(int state){}
|
||||
void GLFWInput::OnRightMouseButton(int state){}
|
||||
void GLFWInput::OnLeftMouseButton(int state) {}
|
||||
void GLFWInput::OnRightMouseButton(int state) {}
|
||||
|
||||
void GLFWInput::OnMiddleMouseButton(int state)
|
||||
{
|
||||
switch(state)
|
||||
void GLFWInput::OnMiddleMouseButton(int state) {
|
||||
switch (state) {
|
||||
case GLFW_PRESS:
|
||||
{
|
||||
case GLFW_PRESS:
|
||||
{
|
||||
handlers.mapScroll(mouseX, mouseY, lastMouseX, lastMouseY);
|
||||
break;
|
||||
}
|
||||
|
||||
case GLFW_RELEASE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
handlers.mapScroll(mouseX, mouseY, lastMouseX, lastMouseY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case GLFW_RELEASE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,8 +9,7 @@ import MagnumRender;
|
||||
import GLFWInput;
|
||||
import std;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
// Setup P7 logger
|
||||
Logger::Init(P7_SINK P7_LOGS_PATH);
|
||||
Logger::RegisterThread(L"Main");
|
||||
@ -48,23 +47,25 @@ int main(int argc, char **argv)
|
||||
// Setup renderer TODO: builder
|
||||
Engine::renderer = reinterpret_cast<ee_engine::IRenderer*>(Allocate<ee_magnum::MagnumRenderer>(window));
|
||||
|
||||
ee_assets::AssetMapMesh ®ions = Engine::assetManager->FindOnce<ee_assets::AssetMapMesh>("assets/map/ET.map");
|
||||
ee_assets::AssetMapMesh& regions = Engine::assetManager->FindOnce<ee_assets::AssetMapMesh>("assets/map/ET.map");
|
||||
Engine::renderer->RegisterMapMesh(®ions.content);
|
||||
|
||||
//TODO: ShaderRefs builder from set of AssetMaterial
|
||||
ee_assets::AssetMaterial &provincesMaterial =
|
||||
Engine::assetManager->FindOnce<ee_assets::AssetMaterial>("assets/materials/provinces.mat");
|
||||
ee_assets::AssetShader &vertProv = Engine::assetManager->FindOnce<ee_assets::AssetShader>(provincesMaterial.vertexShaderAssetID);
|
||||
ee_assets::AssetShader &fragProv = Engine::assetManager->FindOnce<ee_assets::AssetShader>(provincesMaterial.fragmentShaderAssetID);
|
||||
ee_assets::AssetMaterial& provincesMaterial =
|
||||
Engine::assetManager->FindOnce<ee_assets::AssetMaterial>("assets/materials/provinces.mat");
|
||||
ee_assets::AssetShader& vertProv = Engine::assetManager->FindOnce<ee_assets::AssetShader>(
|
||||
provincesMaterial.vertexShaderAssetID);
|
||||
ee_assets::AssetShader& fragProv = Engine::assetManager->FindOnce<ee_assets::AssetShader>(
|
||||
provincesMaterial.fragmentShaderAssetID);
|
||||
Engine::renderer->RegisterMaterials({
|
||||
.vertProvinces = &vertProv,
|
||||
.fragProvinces = &fragProv
|
||||
.vertProvinces = &vertProv,
|
||||
.fragProvinces = &fragProv
|
||||
});
|
||||
|
||||
Engine::renderer->Init();
|
||||
Engine::renderer->SetCamera({
|
||||
//.position = {1000.0f, 1000.0f},
|
||||
.zoom = 2000.0f
|
||||
//.position = {1000.0f, 1000.0f},
|
||||
.zoom = 2000.0f
|
||||
});
|
||||
|
||||
glfwSetFramebufferSizeCallback(window, [](GLFWwindow *window, int width, int height) {
|
||||
@ -73,15 +74,14 @@ int main(int argc, char **argv)
|
||||
|
||||
// Setup Client TODO: builder
|
||||
Engine::client = Allocate<Client>();
|
||||
// AssetHandle save = Engine::assetManager->Find("assets/scenarios/empires.save");
|
||||
// Engine::client->LoadSave(save);
|
||||
// Engine::client->Init();
|
||||
// AssetHandle save = Engine::assetManager->Find("assets/scenarios/empires.save");
|
||||
// Engine::client->LoadSave(save);
|
||||
// Engine::client->Init();
|
||||
Engine::client->Start();
|
||||
|
||||
// Game loop
|
||||
ee_engine::RendererCommand renderCmdBuffer;
|
||||
while(!glfwWindowShouldClose(window))
|
||||
{
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
Engine::renderer->ProcessQueue(renderCmdBuffer);
|
||||
Engine::renderer->Draw();
|
||||
|
||||
@ -100,4 +100,4 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
// TODO: Use CRTP where possible in classes with virtual/override
|
||||
// TODO: Leaks detection
|
||||
// TODO: Leaks detection
|
||||
|
||||
@ -12,29 +12,26 @@ import std;
|
||||
|
||||
using namespace Magnum;
|
||||
|
||||
export namespace ee_magnum
|
||||
{
|
||||
class BaseMaterial : public GL::AbstractShaderProgram
|
||||
{
|
||||
export namespace ee_magnum {
|
||||
class BaseMaterial : public GL::AbstractShaderProgram {
|
||||
public:
|
||||
inline static constexpr std::int32_t CAMERA_BINDING = 1;
|
||||
//TODO: push constant
|
||||
inline static constexpr std::int32_t TRANSFORM_BINDING = 2;
|
||||
|
||||
void setModel(const Matrix4 &model);
|
||||
void setViewProjection(const Matrix4 &vewProjection);
|
||||
void setModel(const Matrix4& model);
|
||||
void setViewProjection(const Matrix4& vewProjection);
|
||||
|
||||
protected:
|
||||
explicit BaseMaterial(const std::string &vertSrc, const std::string &fragSrc);
|
||||
explicit BaseMaterial(const std::string& vertSrc, const std::string& fragSrc);
|
||||
};
|
||||
|
||||
class ProvinceMaterial final : public BaseMaterial
|
||||
{
|
||||
class ProvinceMaterial final : public BaseMaterial {
|
||||
public:
|
||||
inline static constexpr std::int32_t PROVINCES_DATA_BINDING = 0;
|
||||
inline static constexpr std::int32_t PROVINCES_ID_BINDING = 3;
|
||||
|
||||
explicit ProvinceMaterial(const std::string &vertSrc, const std::string &fragSrc);
|
||||
explicit ProvinceMaterial(const std::string& vertSrc, const std::string& fragSrc);
|
||||
|
||||
void setId(const std::uint32_t id);
|
||||
};
|
||||
|
||||
@ -8,17 +8,15 @@ module;
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
export module MagnumRender;
|
||||
import :Materials;
|
||||
import :Materials;
|
||||
import views;
|
||||
import Render;
|
||||
import std;
|
||||
|
||||
using namespace Magnum;
|
||||
|
||||
export namespace ee_magnum
|
||||
{
|
||||
class MagnumRenderer final : public ee_engine::IRenderer
|
||||
{
|
||||
export namespace ee_magnum {
|
||||
class MagnumRenderer final : public ee_engine::IRenderer {
|
||||
public:
|
||||
MagnumRenderer(GLFWwindow *window);
|
||||
~MagnumRenderer();
|
||||
@ -33,7 +31,8 @@ export namespace ee_magnum
|
||||
|
||||
void ApplyCamera() override;
|
||||
|
||||
virtual void UpdateProvinces(const std::size_t index, const std::vector<ee_engine::ProvinceSSBO> &data) override;
|
||||
virtual void
|
||||
UpdateProvinces(const std::size_t index, const std::vector<ee_engine::ProvinceSSBO>& data) override;
|
||||
|
||||
private:
|
||||
Platform::GLContext context;
|
||||
@ -48,4 +47,4 @@ export namespace ee_magnum
|
||||
|
||||
void ApplyMapMVP();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,13 +9,12 @@ module;
|
||||
|
||||
|
||||
module MagnumRender;
|
||||
import :Materials;
|
||||
import :Materials;
|
||||
import utils;
|
||||
|
||||
ee_magnum::BaseMaterial::BaseMaterial(const std::string &vertSrc, const std::string &fragSrc)
|
||||
{
|
||||
GL::Shader vert {GL::Version::GL430, GL::Shader::Type::Vertex};
|
||||
GL::Shader frag {GL::Version::GL430, GL::Shader::Type::Fragment};
|
||||
ee_magnum::BaseMaterial::BaseMaterial(const std::string& vertSrc, const std::string& fragSrc) {
|
||||
GL::Shader vert{GL::Version::GL430, GL::Shader::Type::Vertex};
|
||||
GL::Shader frag{GL::Version::GL430, GL::Shader::Type::Fragment};
|
||||
|
||||
vert.addSource(vertSrc);
|
||||
frag.addSource(fragSrc);
|
||||
@ -31,22 +30,17 @@ ee_magnum::BaseMaterial::BaseMaterial(const std::string &vertSrc, const std::str
|
||||
link();
|
||||
}
|
||||
|
||||
void ee_magnum::BaseMaterial::setModel(const Matrix4 &m)
|
||||
{
|
||||
void ee_magnum::BaseMaterial::setModel(const Matrix4& m) {
|
||||
setUniform(TRANSFORM_BINDING, m);
|
||||
}
|
||||
|
||||
void ee_magnum::BaseMaterial::setViewProjection(const Matrix4 &vp)
|
||||
{
|
||||
void ee_magnum::BaseMaterial::setViewProjection(const Matrix4& vp) {
|
||||
setUniform(CAMERA_BINDING, vp);
|
||||
}
|
||||
|
||||
ee_magnum::ProvinceMaterial::ProvinceMaterial(const std::string &vertSrc, const std::string &fragSrc): BaseMaterial(vertSrc, fragSrc)
|
||||
{
|
||||
ee_magnum::ProvinceMaterial::ProvinceMaterial(const std::string& vertSrc, const std::string& fragSrc) : BaseMaterial(
|
||||
vertSrc, fragSrc) {}
|
||||
|
||||
}
|
||||
|
||||
void ee_magnum::ProvinceMaterial::setId(const uint32_t id)
|
||||
{
|
||||
void ee_magnum::ProvinceMaterial::setId(const uint32_t id) {
|
||||
setUniform(PROVINCES_ID_BINDING, id);
|
||||
}
|
||||
|
||||
@ -18,15 +18,13 @@ import utils;
|
||||
|
||||
using namespace Math::Literals;
|
||||
|
||||
ee_magnum::MagnumRenderer::MagnumRenderer(GLFWwindow *window) : IRenderer(window)
|
||||
{
|
||||
ee_magnum::MagnumRenderer::MagnumRenderer(GLFWwindow *window) : IRenderer(window) {
|
||||
ValidateSupport();
|
||||
|
||||
LOG(INFO, "Renderer created");
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::Init()
|
||||
{
|
||||
void ee_magnum::MagnumRenderer::Init() {
|
||||
LOG(INFO, "GLSL version: %d", GL::Context::current().version());
|
||||
|
||||
LoadShaders();
|
||||
@ -36,76 +34,62 @@ void ee_magnum::MagnumRenderer::Init()
|
||||
LOG(INFO, "Renderer initialized");
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::Clear()
|
||||
{
|
||||
void ee_magnum::MagnumRenderer::Clear() {
|
||||
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::DrawMap()
|
||||
{
|
||||
void ee_magnum::MagnumRenderer::DrawMap() {
|
||||
ApplyCamera();
|
||||
for (std::uint32_t i = 0; i < provinceMeshes.size(); i++)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < provinceMeshes.size(); i++) {
|
||||
provinceMaterial->setId(i);
|
||||
provinceMaterial->draw(provinceMeshes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::DrawUI()
|
||||
{
|
||||
void ee_magnum::MagnumRenderer::DrawUI() {}
|
||||
|
||||
}
|
||||
void ee_magnum::MagnumRenderer::ValidateSupport() {}
|
||||
|
||||
void ee_magnum::MagnumRenderer::ValidateSupport()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::ApplyCamera()
|
||||
{
|
||||
Matrix4 viewProjection {Magnum::NoInit};
|
||||
void ee_magnum::MagnumRenderer::ApplyCamera() {
|
||||
Matrix4 viewProjection{Magnum::NoInit};
|
||||
std::memcpy(viewProjection.data(), glm::value_ptr(this->viewProjection), sizeof(float) * 16);
|
||||
|
||||
provinceMaterial->setViewProjection(viewProjection);
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::LoadShaders()
|
||||
{
|
||||
void ee_magnum::MagnumRenderer::LoadShaders() {
|
||||
provinceMaterial = Allocate<ProvinceMaterial>(std::string(
|
||||
reinterpret_cast<const char*>(shaders.vertProvinces->content),
|
||||
shaders.vertProvinces->size
|
||||
) + '\0', std::string(
|
||||
reinterpret_cast<const char*>(shaders.fragProvinces->content),
|
||||
shaders.fragProvinces->size
|
||||
)) + '\0';
|
||||
reinterpret_cast<const char*>(shaders.vertProvinces->content),
|
||||
shaders.vertProvinces->size
|
||||
) + '\0', std::string(
|
||||
reinterpret_cast<const char*>(shaders.fragProvinces->content),
|
||||
shaders.fragProvinces->size
|
||||
)) + '\0';
|
||||
|
||||
LOG(INFO, "Shaders loaded");
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::LoadProvinces()
|
||||
{
|
||||
void ee_magnum::MagnumRenderer::LoadProvinces() {
|
||||
std::vector<ee_engine::ProvinceSSBO> provincesData;
|
||||
|
||||
std::size_t regionIndex = 0;
|
||||
for (auto& [region, provs]: mapMesh->regions)
|
||||
{
|
||||
for (ee_engine::MapMesh::Province &province: provs)
|
||||
{
|
||||
for (auto& [region, provs] : mapMesh->regions) {
|
||||
for (ee_engine::MapMesh::Province& province : provs) {
|
||||
GL::Mesh regionMesh;
|
||||
|
||||
Containers::ArrayView provinceVertices(province.vertices.data(), province.vertices.size());
|
||||
Containers::ArrayView provinceIndices(province.indices.data(), province.indices.size());
|
||||
|
||||
regionMesh.setPrimitive(GL::MeshPrimitive::Triangles)
|
||||
.setCount(static_cast<Magnum::Int>(province.indices.size()))
|
||||
.addVertexBuffer(GL::Buffer{provinceVertices}, 0, GL::Attribute<0, Magnum::Vector2>{})
|
||||
.setIndexBuffer(GL::Buffer{provinceIndices}, 0, GL::MeshIndexType::UnsignedShort);
|
||||
.setCount(static_cast<Magnum::Int>(province.indices.size()))
|
||||
.addVertexBuffer(GL::Buffer{provinceVertices}, 0, GL::Attribute<0, Magnum::Vector2>{})
|
||||
.setIndexBuffer(GL::Buffer{provinceIndices}, 0, GL::MeshIndexType::UnsignedShort);
|
||||
|
||||
provinceMeshes.push_back(std::move(regionMesh));
|
||||
|
||||
ee_engine::ProvinceSSBO data {
|
||||
.regionId = region,
|
||||
.color = 0xFFFFFF
|
||||
ee_engine::ProvinceSSBO data{
|
||||
.regionId = region,
|
||||
.color = 0xFFFFFF
|
||||
};
|
||||
|
||||
provincesData.push_back(data);
|
||||
@ -121,17 +105,15 @@ void ee_magnum::MagnumRenderer::LoadProvinces()
|
||||
Containers::ArrayView provincesDataView(provincesData.data(), provincesData.size());
|
||||
provinceSSBO.setData(provincesDataView, GL::BufferUsage::DynamicDraw);
|
||||
provinceSSBO.bind(GL::Buffer::Target::ShaderStorage, ProvinceMaterial::PROVINCES_DATA_BINDING);
|
||||
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::UpdateProvinces(const std::size_t index, const std::vector<ee_engine::ProvinceSSBO> &data)
|
||||
{
|
||||
void ee_magnum::MagnumRenderer::UpdateProvinces(const std::size_t index,
|
||||
const std::vector<ee_engine::ProvinceSSBO>& data) {
|
||||
Containers::ArrayView provincesData(data.data(), data.size());
|
||||
provinceSSBO.setSubData(index, provincesData);
|
||||
}
|
||||
|
||||
void ee_magnum::MagnumRenderer::Shutdown()
|
||||
{
|
||||
void ee_magnum::MagnumRenderer::Shutdown() {
|
||||
provinceMeshes.clear();
|
||||
provinceSSBO = GL::Buffer{NoCreate};
|
||||
if (provinceMaterial != nullptr)
|
||||
@ -139,7 +121,4 @@ void ee_magnum::MagnumRenderer::Shutdown()
|
||||
provinceMaterial = nullptr;
|
||||
}
|
||||
|
||||
ee_magnum::MagnumRenderer::~MagnumRenderer()
|
||||
{
|
||||
|
||||
}
|
||||
ee_magnum::MagnumRenderer::~MagnumRenderer() {}
|
||||
|
||||
@ -1,24 +1,25 @@
|
||||
export module utils:allocator;
|
||||
import std;
|
||||
|
||||
export {
|
||||
template<typename T, typename... Args> T* Allocate(Args&&... args)
|
||||
{
|
||||
export
|
||||
{
|
||||
template <typename T, typename... Args>
|
||||
T* Allocate(Args&&... args) {
|
||||
return new T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T> void Deallocate(T* obj)
|
||||
{
|
||||
template <typename T>
|
||||
void Deallocate(T *obj) {
|
||||
delete obj;
|
||||
}
|
||||
|
||||
template<typename T> T* AllocateArray(std::size_t size)
|
||||
{
|
||||
template <typename T>
|
||||
T* AllocateArray(std::size_t size) {
|
||||
return new T[size];
|
||||
}
|
||||
|
||||
template<typename T> void DeallocateArray(T* obj)
|
||||
{
|
||||
template <typename T>
|
||||
void DeallocateArray(T *obj) {
|
||||
delete[] obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
export module utils:buffers;
|
||||
import std;
|
||||
|
||||
export namespace ee_utils
|
||||
{
|
||||
bool readNext(void* dst, std::uint8_t* &srcPointer, std::size_t &srcLeftoverSize, const std::size_t readSize);
|
||||
bool writeNext(std::uint8_t* &dstPointer, void* src, std::size_t &dstLeftoverSize, const std::size_t writeSize);
|
||||
}
|
||||
export namespace ee_utils {
|
||||
bool readNext(void *dst, std::uint8_t * & srcPointer, std::size_t& srcLeftoverSize, const std::size_t readSize);
|
||||
bool writeNext(std::uint8_t * & dstPointer, void *src, std::size_t& dstLeftoverSize, const std::size_t writeSize);
|
||||
}
|
||||
|
||||
@ -5,10 +5,9 @@ module;
|
||||
|
||||
export module utils:lockfree;
|
||||
|
||||
export namespace boost
|
||||
{
|
||||
export namespace boost {
|
||||
using lockfree::capacity;
|
||||
|
||||
using lockfree::queue;
|
||||
using lockfree::spsc_queue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,29 +7,24 @@ module;
|
||||
export module utils:logger;
|
||||
import std;
|
||||
|
||||
namespace logger
|
||||
{
|
||||
namespace logger {
|
||||
template <std::size_t length>
|
||||
struct wstring
|
||||
{
|
||||
struct wstring {
|
||||
wchar_t content[length];
|
||||
constexpr operator const wchar_t*() const {return content;}
|
||||
constexpr operator const wchar_t*() const { return content; }
|
||||
|
||||
explicit constexpr wstring(const char (&str)[length]) : content{}
|
||||
{
|
||||
explicit constexpr wstring(const char (&str)[length]) : content{} {
|
||||
for (std::size_t i = 0; i < length; i++)
|
||||
content[i] = static_cast<wchar_t>(str[i]);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t length>
|
||||
constexpr wstring<length> TM(const char (&str)[length])
|
||||
{
|
||||
constexpr wstring<length> TM(const char (&str)[length]) {
|
||||
return wstring<length>(str);
|
||||
}
|
||||
|
||||
enum LogLevel : std::uint8_t
|
||||
{
|
||||
enum LogLevel : std::uint8_t {
|
||||
TRACE,
|
||||
DEBUG,
|
||||
INFO,
|
||||
@ -41,15 +36,13 @@ namespace logger
|
||||
class Logger;
|
||||
|
||||
template <typename... Args>
|
||||
struct LOG_WCHAR
|
||||
{
|
||||
struct LOG_WCHAR {
|
||||
LOG_WCHAR(
|
||||
LogLevel level,
|
||||
const wchar_t* format,
|
||||
const wchar_t *format,
|
||||
Args&&... args,
|
||||
const std::source_location &location = std::source_location::current()
|
||||
)
|
||||
{
|
||||
const std::source_location& location = std::source_location::current()
|
||||
) {
|
||||
Logger::trace->Trace(
|
||||
0,
|
||||
static_cast<eP7Trace_Level>(level),
|
||||
@ -65,15 +58,13 @@ namespace logger
|
||||
|
||||
// Notice: logging char string supports only ASCII, use LOG_WCHAR with wchar string for UTF-8
|
||||
template <std::size_t length, typename... Args>
|
||||
struct LOG
|
||||
{
|
||||
struct LOG {
|
||||
LOG(
|
||||
LogLevel level,
|
||||
const char (&format)[length],
|
||||
Args&&... args,
|
||||
const std::source_location &location = std::source_location::current()
|
||||
)
|
||||
{
|
||||
const std::source_location& location = std::source_location::current()
|
||||
) {
|
||||
Logger::trace->Trace(
|
||||
0,
|
||||
static_cast<eP7Trace_Level>(level),
|
||||
@ -87,18 +78,17 @@ namespace logger
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args> LOG_WCHAR(LogLevel, const wchar_t*, Args&&...) -> LOG_WCHAR<Args...>;
|
||||
template <std::size_t length, typename... Args> LOG(LogLevel, const char (&)[length], Args&&...) -> LOG<length, Args...>;
|
||||
template <typename... Args>
|
||||
LOG_WCHAR(LogLevel, const wchar_t *, Args&&...) -> LOG_WCHAR<Args...>;
|
||||
template <std::size_t length, typename... Args>
|
||||
LOG(LogLevel, const char (&)[length], Args&&...) -> LOG<length, Args...>;
|
||||
|
||||
class Logger
|
||||
{
|
||||
class Logger {
|
||||
public:
|
||||
Logger() = delete;
|
||||
|
||||
static void Init(const wchar_t *options)
|
||||
{
|
||||
if (isReady)
|
||||
{
|
||||
static void Init(const wchar_t *options) {
|
||||
if (isReady) {
|
||||
LOG_WCHAR(WARNING, L"Logger already initialized.");
|
||||
return;
|
||||
}
|
||||
@ -110,18 +100,16 @@ namespace logger
|
||||
isReady = true;
|
||||
}
|
||||
|
||||
static void Release()
|
||||
{
|
||||
static void Release() {
|
||||
trace->Release();
|
||||
client->Release();
|
||||
}
|
||||
|
||||
static void RegisterThread(const wchar_t *name)
|
||||
{
|
||||
static void RegisterThread(const wchar_t *name) {
|
||||
trace->Register_Thread(name, 0);
|
||||
}
|
||||
static void UnregisterThread()
|
||||
{
|
||||
|
||||
static void UnregisterThread() {
|
||||
trace->Unregister_Thread(0);
|
||||
}
|
||||
|
||||
@ -131,10 +119,11 @@ namespace logger
|
||||
|
||||
inline static bool isReady = false;
|
||||
|
||||
template <typename... Args> friend struct LOG_WCHAR;
|
||||
template <std::size_t length, typename... Args> friend struct LOG;
|
||||
template <typename... Args>
|
||||
friend struct LOG_WCHAR;
|
||||
template <std::size_t length, typename... Args>
|
||||
friend struct LOG;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
export using logger::Logger;
|
||||
@ -145,4 +134,4 @@ export using logger::LogLevel::DEBUG;
|
||||
export using logger::LogLevel::INFO;
|
||||
export using logger::LogLevel::WARNING;
|
||||
export using logger::LogLevel::ERROR;
|
||||
export using logger::LogLevel::CRITICAL;
|
||||
export using logger::LogLevel::CRITICAL;
|
||||
|
||||
@ -1,68 +1,58 @@
|
||||
export module utils:worker;
|
||||
import :lockfree;
|
||||
import :logger;
|
||||
import :lockfree;
|
||||
import :logger;
|
||||
import std;
|
||||
|
||||
export namespace ee_utils
|
||||
{
|
||||
struct WorkerCommand
|
||||
{
|
||||
export namespace ee_utils {
|
||||
struct WorkerCommand {
|
||||
std::uint8_t type = 0;
|
||||
};
|
||||
|
||||
template <typename T> concept IWorkerCommand = std::is_base_of_v<WorkerCommand, T>;
|
||||
|
||||
template <IWorkerCommand TCommand, std::size_t MaxCmdTypeId, bool IdleDetection = false>
|
||||
class Worker
|
||||
{
|
||||
class Worker {
|
||||
public:
|
||||
void Request(const TCommand &command)
|
||||
{
|
||||
void Request(const TCommand& command) {
|
||||
commands.push(command); //TODO: filled queue case
|
||||
}
|
||||
|
||||
void Request(const std::uint8_t type)
|
||||
{
|
||||
commands.push(TCommand {.type = type}); //TODO: filled queue case
|
||||
void Request(const std::uint8_t type) {
|
||||
commands.push(TCommand{.type = type}); //TODO: filled queue case
|
||||
}
|
||||
|
||||
void ProcessQueue(TCommand &buffer) requires !IdleDetection
|
||||
{
|
||||
while (this->commands.pop(buffer))
|
||||
{
|
||||
void ProcessQueue(TCommand& buffer) requires !IdleDetection {
|
||||
while (this->commands.pop(buffer)) {
|
||||
ProcessCommand(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t ProcessQueue(TCommand &buffer) requires IdleDetection
|
||||
{
|
||||
std::uint32_t ProcessQueue(TCommand& buffer) requires IdleDetection {
|
||||
thread_local std::uint32_t idleCounter = 0;
|
||||
if (!this->commands.pop(buffer))
|
||||
{
|
||||
if (!this->commands.pop(buffer)) {
|
||||
idleCounter++;
|
||||
return idleCounter;
|
||||
}
|
||||
idleCounter = 0;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
ProcessCommand(buffer);
|
||||
} while (this->commands.pop(buffer));
|
||||
}
|
||||
while (this->commands.pop(buffer));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
// TODO: replace std::function with more optimized ref
|
||||
std::array<std::function<void(TCommand &command)>, MaxCmdTypeId + 1> commandsMapping;
|
||||
std::array<std::function<void(TCommand& command)>, MaxCmdTypeId + 1> commandsMapping;
|
||||
// TODO: maybe I should use lockfree::queue ? Otherwise make consumer thread explicit for safety
|
||||
boost::lockfree::spsc_queue<TCommand, boost::lockfree::capacity<512>> commands;
|
||||
|
||||
Worker() {};
|
||||
|
||||
void ProcessCommand(TCommand &command)
|
||||
{
|
||||
if (command.type > MaxCmdTypeId || !commandsMapping[command.type])
|
||||
{
|
||||
void ProcessCommand(TCommand& command) {
|
||||
if (command.type > MaxCmdTypeId || !commandsMapping[command.type]) {
|
||||
LOG(WARNING, "Unhandled command. Type id: %d", command.type);
|
||||
command.type = MaxCmdTypeId;
|
||||
return;
|
||||
@ -78,10 +68,8 @@ export namespace ee_utils
|
||||
|
||||
virtual ~ThreadedWorkerBase() {}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (isRunning.load())
|
||||
{
|
||||
void Start() {
|
||||
if (isRunning.load()) {
|
||||
LOG(CRITICAL, "Thread can be started only once before stop");
|
||||
throw std::logic_error("Thread can be started only once before stop");
|
||||
}
|
||||
@ -93,8 +81,7 @@ export namespace ee_utils
|
||||
});
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
void Shutdown() {
|
||||
if (isRunning.load())
|
||||
thread.request_stop();
|
||||
else LOG(WARNING, "Tried to shutdown stopped thread");
|
||||
@ -106,28 +93,27 @@ export namespace ee_utils
|
||||
|
||||
virtual void Threading() = 0;
|
||||
};
|
||||
template<typename T> concept IThreadedWorker = std::is_base_of_v<ThreadedWorkerBase, T>;
|
||||
|
||||
enum class IdleBackoffMode : std::uint8_t
|
||||
{
|
||||
template <typename T> concept IThreadedWorker = std::is_base_of_v<ThreadedWorkerBase, T>;
|
||||
|
||||
enum class IdleBackoffMode : std::uint8_t {
|
||||
DISABLED,
|
||||
YIELD
|
||||
};
|
||||
|
||||
template <IWorkerCommand TCommand, std::size_t MaxCmdType, IdleBackoffMode IdleBackoffMode = IdleBackoffMode::DISABLED>
|
||||
class ThreadedWorker : public Worker<TCommand, MaxCmdType, static_cast<bool>(IdleBackoffMode)>, public ThreadedWorkerBase
|
||||
{
|
||||
template <IWorkerCommand TCommand, std::size_t MaxCmdType, IdleBackoffMode IdleBackoffMode =
|
||||
IdleBackoffMode::DISABLED>
|
||||
class ThreadedWorker : public Worker<TCommand, MaxCmdType, static_cast<bool>(IdleBackoffMode)>,
|
||||
public ThreadedWorkerBase {
|
||||
protected:
|
||||
const wchar_t *threadName;
|
||||
|
||||
explicit ThreadedWorker(const wchar_t *threadName, std::uint32_t yieldIdleTime = 0)
|
||||
{
|
||||
explicit ThreadedWorker(const wchar_t *threadName, std::uint32_t yieldIdleTime = 0) {
|
||||
this->threadName = threadName;
|
||||
this->yieldIdleTime = yieldIdleTime;
|
||||
}
|
||||
|
||||
void Threading()
|
||||
{
|
||||
void Threading() {
|
||||
Logger::RegisterThread(threadName);
|
||||
LOG(INFO, "Thread started");
|
||||
|
||||
@ -136,17 +122,13 @@ export namespace ee_utils
|
||||
ReleaseStop();
|
||||
}
|
||||
|
||||
void Loop()
|
||||
{
|
||||
void Loop() {
|
||||
TCommand commandBuffer{};
|
||||
while (!stoken->stop_requested())
|
||||
{
|
||||
if constexpr (IdleBackoffMode == IdleBackoffMode::DISABLED)
|
||||
{
|
||||
while (!stoken->stop_requested()) {
|
||||
if constexpr (IdleBackoffMode == IdleBackoffMode::DISABLED) {
|
||||
this->ProcessQueue(commandBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
const std::uint32_t idleCounter = this->ProcessQueue(commandBuffer);
|
||||
|
||||
if (idleCounter > yieldIdleTime)
|
||||
@ -163,12 +145,11 @@ export namespace ee_utils
|
||||
private:
|
||||
std::uint32_t yieldIdleTime;
|
||||
|
||||
void ReleaseStop()
|
||||
{
|
||||
void ReleaseStop() {
|
||||
Release();
|
||||
LOG(INFO, "Thread is released");
|
||||
Logger::UnregisterThread();
|
||||
isRunning.store(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
module utils;
|
||||
import :buffers;
|
||||
import :buffers;
|
||||
|
||||
bool ee_utils::readNext(void* dst, std::uint8_t* &srcPointer, std::size_t &srcLeftoverSize, const std::size_t readSize)
|
||||
{
|
||||
if (srcLeftoverSize >= readSize)
|
||||
{
|
||||
bool ee_utils::readNext(void *dst, std::uint8_t * & srcPointer, std::size_t& srcLeftoverSize,
|
||||
const std::size_t readSize) {
|
||||
if (srcLeftoverSize >= readSize) {
|
||||
srcLeftoverSize -= readSize;
|
||||
std::memcpy(dst, srcPointer, readSize);
|
||||
srcPointer += readSize;
|
||||
@ -15,10 +14,9 @@ bool ee_utils::readNext(void* dst, std::uint8_t* &srcPointer, std::size_t &srcLe
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ee_utils::writeNext(std::uint8_t* &dstPointer, void* src, std::size_t &dstLeftoverSize, const std::size_t writeSize)
|
||||
{
|
||||
if (dstLeftoverSize >= writeSize)
|
||||
{
|
||||
bool ee_utils::writeNext(std::uint8_t * & dstPointer, void *src, std::size_t& dstLeftoverSize,
|
||||
const std::size_t writeSize) {
|
||||
if (dstLeftoverSize >= writeSize) {
|
||||
dstLeftoverSize -= writeSize;
|
||||
std::memcpy(dstPointer, src, writeSize);
|
||||
dstPointer += writeSize;
|
||||
@ -27,4 +25,4 @@ bool ee_utils::writeNext(std::uint8_t* &dstPointer, void* src, std::size_t &dstL
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user