├── .codespaces.dockerfile ├── .devcontainer └── devcontainer.json ├── .editorconfig ├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── funding.yml ├── linters │ └── .ecrc └── workflows │ └── lint.yml ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── Directory.Build.props ├── Directory.Build.targets ├── LICENSE ├── README.md ├── Vignette.sln ├── analysis └── BannedSymbols.txt ├── assets └── logo.png ├── source ├── Directory.Build.props ├── Vignette.Desktop │ ├── Program.cs │ └── Vignette.Desktop.csproj └── Vignette │ ├── Allocation │ └── IObjectPool.cs │ ├── Audio │ ├── AudioManager.cs │ ├── AudioStream.cs │ └── IAudioController.cs │ ├── Behavior.cs │ ├── Camera.cs │ ├── Collections │ └── SortedFilteredCollection.cs │ ├── Content │ ├── ContentManager.cs │ ├── IContentLoader.cs │ ├── ShaderLoader.cs │ ├── TextureLoader.cs │ └── WaveAudioLoader.cs │ ├── Drawable.cs │ ├── Graphics │ ├── Effect.cs │ ├── IMaterial.cs │ ├── IProjector.cs │ ├── IProperty.cs │ ├── IWorld.cs │ ├── RenderContext.cs │ ├── RenderData.cs │ ├── RenderGroup.cs │ ├── RenderObject.cs │ ├── RenderQueue.cs │ ├── RenderTarget.cs │ ├── Renderer.cs │ ├── ShaderMaterial.cs │ └── UnlitMaterial.cs │ ├── Light.cs │ ├── Node.cs │ ├── ServiceLocator.cs │ ├── Vignette.csproj │ ├── VignetteGame.cs │ ├── Window.cs │ └── World.cs └── tests └── Directory.Build.props /.codespaces.dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/vscode/devcontainers/base:debian 2 | 3 | USER vscode 4 | 5 | # Install dependencies 6 | RUN \ 7 | sudo apt-get update && export DEBIAN_FRONTEND=noninteractive \ 8 | && sudo apt-get -y install --no-install-recommends xauth mesa-utils \ 9 | && sudo apt-get autoremove -y \ 10 | && sudo apt-get clean -y \ 11 | && sudo rm -rf /var/lib/apt/lists/* 12 | 13 | # Install .NET SDK 14 | # Source: https://docs.microsoft.com/dotnet/core/install/linux-scripted-manual#scripted-install 15 | RUN \ 16 | mkdir -p /home/vscode/dotnet \ 17 | && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --install-dir /home/vscode/dotnet -c STS 18 | 19 | # .NET Environment Variables 20 | ENV DOTNET_ROOT=/home/vscode/dotnet 21 | ENV DOTNET_NOLOGO=true 22 | ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true 23 | 24 | # Path 25 | ENV PATH=$PATH:/home/vscode/dotnet -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Sekai", 3 | "context": "..", 4 | "dockerFile": "../.codespaces.dockerfile", 5 | "privileged": true, 6 | "customizations": { 7 | "vscode": { 8 | "extensions": [ 9 | "ms-dotnettools.csharp", 10 | "ms-dotnettools.vscode-dotnet-runtime", 11 | "formulahendry.dotnet-test-explorer", 12 | "ryanluker.vscode-coverage-gutters", 13 | "editorconfig.editorconfig", 14 | "patcx.vscode-nuget-gallery" 15 | ] 16 | } 17 | }, 18 | "mounts": [ 19 | // Xauth cookies must be shared to the container. 20 | // This is to prevent authentication errors when launching the application. 21 | "source=${localEnv:XAUTHORITY},target=/home/vscode/.Xauthority,type=bind,consistency=cached", 22 | 23 | // Share NuGet config and packages 24 | "source=${localEnv:HOME}/.nuget/NuGet/NuGet.Config,target=/home/vscode/.nuget/NuGet/NuGet.Config,type=bind,consistency=cached", 25 | "source=${localEnv:HOME}/.nuget/packages,target=/home/vscode/.nuget/packages,type=bind" 26 | ], 27 | "remoteEnv": { 28 | "DISPLAY": "${localEnv:DISPLAY}" 29 | }, 30 | "runArgs": [ 31 | "--network=host" 32 | ], 33 | "postAttachCommand": "dotnet build" 34 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | trim_trailing_whitespace = true 7 | 8 | [*.{json,csproj,targets,props,xml,yml}] 9 | indent_size = 2 10 | 11 | [*.cs] 12 | indent_size = 4 13 | insert_final_newline = true 14 | 15 | # Namespace 16 | dotnet_diagnostic.IDE0130.severity = error 17 | 18 | # File Header 19 | file_header_template = Copyright (c) Cosyne \nLicensed under GPL 3.0 with SDK Exception. See LICENSE for details. 20 | dotnet_diagnostic.IDE0073.severity = error 21 | 22 | # 'this' qualifiers 23 | dotnet_style_qualfication_for_field = false:warning 24 | dotnet_style_qualfication_for_property = false:warning 25 | dotnet_style_qualfication_for_method = false:warning 26 | dotnet_style_qualfication_for_event = false:warning 27 | 28 | # Keyword preferences 29 | dotnet_style_predefined_type_for_locals_parameters_members = true:error 30 | dotnet_style_predefined_type_for_member_access = true:error 31 | 32 | # Modifier Preferences 33 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning 34 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:error 35 | dotnet_style_readonly_field = true:warning 36 | 37 | # Parenthesis preferenes 38 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion 39 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion 40 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion 41 | dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion 42 | 43 | # Expression-level preferences 44 | dotnet_style_object_initializer = true:suggestion 45 | dotnet_style_collection_initializer = true:suggestion 46 | dotnet_style_prefer_auto_properties = true:warning 47 | dotnet_style_explicit_tuple_names = true:warning 48 | dotnet_style_prefer_inferred_tuple_names = true:warning 49 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning 50 | dotnet_style_prefer_conditional_expression_over_assignment = false:silent 51 | dotnet_style_prefer_conditional_expression_over_return = false:silent 52 | dotnet_style_prefer_compound_assignment = true:warning 53 | dotnet_style_prefer_simplified_interpolation = true:warning 54 | dotnet_style_prefer_simplified_boolean_expressions = true:warning 55 | dotnet_diagnostic.IDE0010.severity = silent 56 | dotnet_diagnostic.IDE0082.severity = warning 57 | dotnet_diagnostic.IDE0050.severity = warning 58 | dotnet_duagnostic.IDE0070.severity = error 59 | 60 | # Null checking preferences 61 | dotnet_style_coalesce_expression = true:warning 62 | dotnet_style_null_propagation = true:warning 63 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error 64 | 65 | # 'var' preferences 66 | csharp_style_var_for_built_in_types = false:error 67 | csharp_style_var_when_type_is_apparent = true:suggestion 68 | csharp_style_var_elsewhere = true:suggestion 69 | 70 | # Expression-bodied members 71 | csharp_style_expression_bodied_constructors = false:warning 72 | csharp_style_expression_bodied_methods = false:silent 73 | csharp_style_expression_bodied_operators = false:silent 74 | csharp_style_expression_bodied_properties = when_on_single_line:warning 75 | csharp_style_expression_bodied_indexers = when_on_single_line:warning 76 | csharp_style_expression_bodied_accessors = when_on_single_line:warning 77 | csharp_style_expression_bodied_local_functions = when_on_single_line:warning 78 | 79 | # Pattern matching preferences 80 | csharp_style_pattern_matching_over_as_with_null_check = true:warning 81 | csharp_style_pattern_matching_over_is_with_cast_check = true:warning 82 | csharp_style_prefer_switch_expression = false:silent 83 | csharp_style_prefer_pattern_matching = true:warning 84 | csharp_style_prefer_not_pattern = true:warning 85 | 86 | # Expression-level preferences 87 | csharp_style_inlined_variable_declaration = true:warning 88 | csharp_prefer_simple_default_expression = true:warning 89 | csharp_style_pattern_local_over_anonymous_function = true:warning 90 | csharp_style_deconstructed_variable_declaration = true:warning 91 | csharp_style_prefer_index_operator = true:warning 92 | csharp_style_prefer_range_operator = true:warning 93 | csharp_style_implicit_object_creation_when_type_is_apparent = true:warning 94 | dotnet_diagnostic.IDE0072.severity = none 95 | 96 | # 'null' checking preferences 97 | csharp_style_throw_expression = true:warning 98 | csharp_style_conditional_delegate_call = true:warning 99 | 100 | # Code block preferences 101 | csharp_prefer_braces = when_multiline:suggestion 102 | csharp_prefer_simple_using_statement = true:none 103 | 104 | # 'using' directive preferences 105 | csharp_using_directive_placement = outside_namespace:error 106 | 107 | csharp_prefer_static_local_function = true:error 108 | dotnet_diagnostic.IDE0064.severity = none 109 | 110 | # Unnecessary code rules 111 | dotnet_diagnostic.IDE0001.severity = warning 112 | dotnet_diagnostic.IDE0002.severity = warning 113 | dotnet_diagnostic.IDE0004.severity = warning 114 | dotnet_diagnostic.IDE0005.severity = warning 115 | dotnet_diagnostic.IDE0035.severity = error 116 | dotnet_diagnostic.IDE0051.severity = warning 117 | dotnet_diagnostic.IDE0052.severity = warning 118 | csharp_style_unused_value_expression_statement_preference = discard_variable:none 119 | csharp_style_unused_value_assignment_preference = discard_variable:none 120 | dotnet_code_quality_unused_parameters = all:suggestion 121 | dotnet_remove_unnecessary_suppression_exclusions = none:suggestion 122 | dotnet_diagnostic.IDE0080.severity = warning 123 | dotnet_diagnostic.IDE0100.severity = warning 124 | dotnet_diagnostic.IDE0110.severity = warning 125 | 126 | # Organize Using Directives 127 | dotnet_sort_system_directives_first = true:warning 128 | dotnet_separate_import_directive_groups = false:warning 129 | 130 | # Namespace options 131 | dotnet_style_namespace_match_folder = true:error 132 | csharp_style_namespace_declarations = file_scoped:error 133 | 134 | # New line options 135 | csharp_new_line_before_open_brace = all 136 | csharp_new_line_before_else = true:warning 137 | csharp_new_line_before_catch = true:warning 138 | csharp_new_line_before_finally = true:warning 139 | csharp_new_line_before_members_in_object_initializers = true:warning 140 | csharp_new_line_before_members_in_anonymous_types = true:warning 141 | csharp_new_line_between_query_expression_clauses = true:warning 142 | 143 | # Indentation options 144 | csharp_indent_case_contents = true:warning 145 | csharp_indent_switch_labels = true:warning 146 | csharp_indent_labels = flush_left:warning 147 | csharp_indent_block_contents = true:warning 148 | csharp_indent_braces = false:warning 149 | csharp_indent_case_contents_when_block = false:warning 150 | 151 | # Spacing options 152 | csharp_space_after_cast = false:warning 153 | csharp_space_after_keywords_in_control_flow_statements = true:warning 154 | csharp_space_before_colon_in_inheritance_clause = true:warning 155 | csharp_space_after_colon_in_inheritance_clause = true:warning 156 | csharp_space_around_binary_operators = before_and_after:warning 157 | csharp_space_between_method_declaration_parameter_list_parentheses = false:warning 158 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false:warning 159 | csharp_space_between_method_declaration_name_and_open_parenthesis = false:warning 160 | csharp_space_between_method_call_parameter_list_parentheses = false:warning 161 | csharp_space_between_method_call_empty_parameter_list_parentheses = false:warning 162 | csharp_space_between_method_call_name_and_opening_parenthesis = false:warning 163 | csharp_space_after_comma = true:warning 164 | csharp_space_before_comma = false:warning 165 | csharp_space_after_dot = false:warning 166 | csharp_space_before_dot = false:warning 167 | csharp_space_after_semicolon_in_for_statement = true:warning 168 | csharp_space_around_declaration_statements = false:warning 169 | csharp_space_before_open_square_brackets = false:warning 170 | csharp_space_between_empty_square_brackets = false:warning 171 | csharp_space_between_square_brackets = false:warning 172 | 173 | # Wrap options 174 | csharp_preserve_single_line_statements = false:warning 175 | csharp_preserve_single_line_blocks = true:warning 176 | 177 | # Banned APIs 178 | dotnet_diagnostic.RS0030.severity = error 179 | 180 | # Public Members 181 | dotnet_naming_rule.public_members.severity = warning 182 | dotnet_naming_rule.public_members.style = public_members_style 183 | dotnet_naming_rule.public_members.symbols = public_members_symbols 184 | dotnet_naming_style.public_members_style.capitalization = pascal_case 185 | dotnet_naming_symbols.public_members_symbols.applicable_kinds = property,field,event,method 186 | dotnet_naming_symbols.public_members_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected 187 | 188 | # Public Static Members 189 | dotnet_naming_rule.public_static_members.severity = warning 190 | dotnet_naming_rule.public_static_members.style = public_static_members_style 191 | dotnet_naming_rule.public_static_members.symbols = public_static_members_symbols 192 | dotnet_naming_style.public_static_members_style.capitalization = pascal_case 193 | dotnet_naming_symbols.public_static_members_symbols.applicable_kinds = property,field,event,method 194 | dotnet_naming_symbols.public_static_members_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected 195 | dotnet_naming_symbols.public_static_members_symbols.required_modifiers = static 196 | 197 | # Public Constant Members 198 | dotnet_naming_rule.public_const_members.severity = warning 199 | dotnet_naming_rule.public_const_members.style = public_const_members_style 200 | dotnet_naming_rule.public_const_members.symbols = public_const_members_symbols 201 | dotnet_naming_style.public_const_members_style.capitalization = all_upper 202 | dotnet_naming_style.public_const_members_style.word_separator = _ 203 | dotnet_naming_symbols.public_const_members_symbols.applicable_kinds = property,field,event,method 204 | dotnet_naming_symbols.public_const_members_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected 205 | dotnet_naming_symbols.public_const_members_symbols.required_modifiers = const 206 | 207 | # Private/Local Members 208 | dotnet_naming_rule.private_local_members.severity = warning 209 | dotnet_naming_rule.private_local_members.style = private_local_members_style 210 | dotnet_naming_rule.private_local_members.symbols = private_local_members_symbols 211 | dotnet_naming_style.private_local_members_style.capitalization = camel_case 212 | dotnet_naming_symbols.private_local_members_symbols.applicable_kinds = property,field,event,method,local,local_function 213 | dotnet_naming_symbols.private_local_members_symbols.applicable_accessibilities = private,local 214 | 215 | # Private Static/Const Members 216 | dotnet_naming_rule.private_static_const_members.severity = warning 217 | dotnet_naming_rule.private_static_const_members.style = private_static_const_members_style 218 | dotnet_naming_rule.private_static_const_members.symbols = private_static_const_members_symbols 219 | dotnet_naming_style.private_static_const_members_style.capitalization = all_lower 220 | dotnet_naming_style.private_static_const_members_style.word_separator = _ 221 | dotnet_naming_symbols.private_static_const_members_symbols.applicable_kinds = property,field,event,method 222 | dotnet_naming_symbols.private_static_const_members_symbols.applicable_accessibilities = private 223 | dotnet_naming_symbols.private_static_const_members_symbols.required_modifiers = static,const 224 | 225 | # Local Const Members 226 | dotnet_naming_rule.local_const_members.severity = warning 227 | dotnet_naming_rule.local_const_members.style = local_const_members_style 228 | dotnet_naming_rule.local_const_members.symbols = local_const_members_symbols 229 | dotnet_naming_style.local_const_members_style.capitalization = all_lower 230 | dotnet_naming_style.local_const_members_style.word_separator = _ 231 | dotnet_naming_symbols.local_const_members_symbols.applicable_kinds = local 232 | dotnet_naming_symbols.local_const_members_symbols.applicable_accessibilities = local 233 | dotnet_naming_symbols.local_const_members_symbols.required_modifiers = const 234 | 235 | # Parameters 236 | dotnet_naming_rule.parameters.severity = warning 237 | dotnet_naming_rule.parameters.style = parameters_style 238 | dotnet_naming_rule.parameters.symbols = parameters_symbols 239 | dotnet_naming_style.parameters_style.capitalization = camel_case 240 | dotnet_naming_symbols.parameters_symbols.applicable_kinds = parameter 241 | dotnet_naming_symbols.parameters_symbols.applicable_accessibilities = * 242 | 243 | # Type Parameters 244 | dotnet_naming_rule.type_parameters.severity = warning 245 | dotnet_naming_rule.type_parameters.style = type_parameters_style 246 | dotnet_naming_rule.type_parameters.symbols = type_parameters_symbols 247 | dotnet_naming_style.type_parameters_style.capitalization = pascal_case 248 | dotnet_naming_symbols.type_parameters_symbols.applicable_kinds = type_parameter 249 | 250 | # Non-interface Types 251 | dotnet_naming_rule.types.severity = warning 252 | dotnet_naming_rule.types.style = types_style 253 | dotnet_naming_rule.types.symbols = types_symbols 254 | dotnet_naming_style.types_style.capitalization = pascalcase 255 | dotnet_naming_symbols.types_symbols.applicable_kinds = namespace,class,struct,enum,delegate 256 | dotnet_naming_symbols.types_symbols.applicable_accessibilities = * 257 | 258 | # Interface Types 259 | dotnet_naming_rule.types_interface.severity = warning 260 | dotnet_naming_rule.types_interface.style = types_interface_style 261 | dotnet_naming_rule.types_interface.symbols = types_interface_symbols 262 | dotnet_naming_style.types_interface_style.capitaization = pascal_case 263 | dotnet_naming_style.types_interface_style.required_prefix = I 264 | dotnet_naming_symbols.types_interface_symbols.applicable_kinds = interface 265 | dotnet_naming_symbols.types_interface_symbols.applicable_accessibilities = * 266 | 267 | # Roslynator configuration 268 | dotnet_analyzer_diagnostic.category-roslynator.severity = default 269 | roslynator_analyzers.enabled_by_default = true 270 | roslynator_refactorings.enabled = true 271 | roslynator_compiler_diagnostic_fixes.enabled = true 272 | dotnet_diagnostic.RCS1001.severity = silent -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting one or more of the project maintainers. All complaints 59 | will be reviewed and investigated and will result in a response that is deemed 60 | necessary and appropriate to the circumstances. The project team is obligated to 61 | maintain confidentiality with regard to the reporter of an incident. Further 62 | details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available [here][source]. 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | [source]: https://www.contributor-covenant.org/version/1/4/code-of-conduct.html -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for contributing to Vignette! The following is a set of guidlelines for contributing to Vignette and its libraries. We aim to provide a healthy environment for everyone involved and we have noted important things to keep in mind. 4 | 5 | Do keep in mind that these are not "official rules" but in doing so can help everyone deal with things in an efficient manner. 6 | 7 | ## Submitting an Issue 8 | 9 | - **Search for issues first before submitting a new issue** 10 | 11 | To keep the issue tracker clean, we close issues that are similar to other existing issues. 12 | 13 | - **Provide as much information as possible** 14 | 15 | This is to help other contributors and maintainers understand what you are experiencing. Such information can be by providing your system specifications, logs, reproduction steps, or a video or picture of the bug. 16 | 17 | - **Make issues simple and specific** 18 | 19 | This to help contributors and other maintainers immediately get a grasp of the issue you are experiencing. Please avoid making long submissions and keep it direct to the point. If you are experiencing multiple issues, you are required to make multiple issue submissions for each one. 20 | 21 | - **Please use discussions for feature requests** 22 | 23 | This is another effort of keeping the issue tracker clean. All feature requests are closed and are converted into discussions. Do not fret as we read feature requests whenever possible. 24 | 25 | - **Refrain from off-topic discussions** 26 | 27 | This includes "+1" comments and asking questions if the issue is resolved. This is to keep the issue topic clear of unnecessary noise. You can make use of reactions instead to express your opinion. 28 | 29 | ## Submitting a Pull Request 30 | 31 | We welcome pull requests from contributors outside the organization. You can head over to the [issues page](https://github.com/ppy/osu/issues) of this repository to get started. 32 | 33 | Here are some key things to note before submitting a pull request: 34 | 35 | - **Make sure you are familiar with git and the Feature Branch Workflow** 36 | 37 | [git](https://git-scm.com/) is a version control system that can be confusing at first if you aren't familiar with version control. Basically, projects using git have a specific workflow for submitting code changes, which is called the pull request workflow. 38 | 39 | The feature branch workflow allows specific features to be developed in their own branches and later can be merged to the main branch after conflicts and reviews have been resolved. You can read [this article](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow) on how this workflow works in detail. 40 | 41 | - **For new features, please create a new discussion proposing the new feature first.** 42 | 43 | This is let the core contributors and maintainers of the project have an idea on what you have in mind and have a clear outline of what that feature entails and how it will be implemented. 44 | 45 | To get started, head over to the [discussions page](https://github.com/vignetteapp/vignette/discussions) of this repository. 46 | 47 | - **Refrain from using the GitHub web interface** 48 | 49 | GitHub provides an option to edit code or replace files through the web interface. However it is highly discouraged to be used in most scenarios as there may be issues regarding whitespace or file encoding changes that may happen which will make it difficult for reviewers. 50 | 51 | - **Add tests whenever possible** 52 | 53 | Automated tests help the codebase be more maintainable and organised. 54 | 55 | - **Run tests before opening a pull request** 56 | 57 | While it is available through GitHub Actions, its best not to rely on it as there are other builds that can be queued at any time. Only make a pull request when you are sure that all tests pass. 58 | 59 | - **Run code style analysis before opening a pull request** 60 | 61 | While as a part of GitHub Actions, as stated before, it is best not to rely on it with the same reasons stated above. -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: vignetteapp 2 | open_collective: vignette -------------------------------------------------------------------------------- /.github/linters/.ecrc: -------------------------------------------------------------------------------- 1 | { 2 | "Verbose": false, 3 | "Debug": false, 4 | "IgnoreDefaults": false, 5 | "SpacesAftertabs": false, 6 | "NoColor": false, 7 | "Exclude": ["\\.exe$"], 8 | "AllowedContentTypes": [], 9 | "PassedFiles": [], 10 | "Disable": { 11 | "EndOfLine": false, 12 | "Indentation": false, 13 | "IndentSize": false, 14 | "InsertFinalNewline": false, 15 | "TrimTrailingWhitespace": false, 16 | "MaxLineLength": false 17 | } 18 | } -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | on: 3 | push: 4 | paths: 5 | - 'tests/**/*.cs' 6 | - 'source/**/*.cs' 7 | 8 | jobs: 9 | check: 10 | name: Check 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | with: 16 | fetch-depth: 0 17 | 18 | - name: Lint 19 | uses: github/super-linter@v4 20 | env: 21 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 22 | SUPPRESS_POSSUM: true 23 | VALIDATE_CSHARP: true 24 | VALIDATE_EDITORCONFIG: true 25 | VALIDATE_ALL_CODEBASE: false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # Tye 66 | .tye/ 67 | 68 | # ASP.NET Scaffolding 69 | ScaffoldingReadMe.txt 70 | 71 | # StyleCop 72 | StyleCopReport.xml 73 | 74 | # Files built by Visual Studio 75 | *_i.c 76 | *_p.c 77 | *_h.h 78 | *.ilk 79 | *.meta 80 | *.obj 81 | *.iobj 82 | *.pch 83 | *.pdb 84 | *.ipdb 85 | *.pgc 86 | *.pgd 87 | *.rsp 88 | *.sbr 89 | *.tlb 90 | *.tli 91 | *.tlh 92 | *.tmp 93 | *.tmp_proj 94 | *_wpftmp.csproj 95 | *.log 96 | *.tlog 97 | *.vspscc 98 | *.vssscc 99 | .builds 100 | *.pidb 101 | *.svclog 102 | *.scc 103 | 104 | # Chutzpah Test files 105 | _Chutzpah* 106 | 107 | # Visual C++ cache files 108 | ipch/ 109 | *.aps 110 | *.ncb 111 | *.opendb 112 | *.opensdf 113 | *.sdf 114 | *.cachefile 115 | *.VC.db 116 | *.VC.VC.opendb 117 | 118 | # Visual Studio profiler 119 | *.psess 120 | *.vsp 121 | *.vspx 122 | *.sap 123 | 124 | # Visual Studio Trace Files 125 | *.e2e 126 | 127 | # TFS 2012 Local Workspace 128 | $tf/ 129 | 130 | # Guidance Automation Toolkit 131 | *.gpState 132 | 133 | # ReSharper is a .NET coding add-in 134 | _ReSharper*/ 135 | *.[Rr]e[Ss]harper 136 | *.DotSettings.user 137 | 138 | # TeamCity is a build add-in 139 | _TeamCity* 140 | 141 | # DotCover is a Code Coverage Tool 142 | *.dotCover 143 | 144 | # AxoCover is a Code Coverage Tool 145 | .axoCover/* 146 | !.axoCover/settings.json 147 | 148 | # Coverlet is a free, cross platform Code Coverage Tool 149 | coverage*.json 150 | coverage*.xml 151 | coverage*.info 152 | 153 | # Visual Studio code coverage results 154 | *.coverage 155 | *.coveragexml 156 | 157 | # NCrunch 158 | _NCrunch_* 159 | .*crunch*.local.xml 160 | nCrunchTemp_* 161 | 162 | # MightyMoose 163 | *.mm.* 164 | AutoTest.Net/ 165 | 166 | # Web workbench (sass) 167 | .sass-cache/ 168 | 169 | # Installshield output folder 170 | [Ee]xpress/ 171 | 172 | # DocProject is a documentation generator add-in 173 | DocProject/buildhelp/ 174 | DocProject/Help/*.HxT 175 | DocProject/Help/*.HxC 176 | DocProject/Help/*.hhc 177 | DocProject/Help/*.hhk 178 | DocProject/Help/*.hhp 179 | DocProject/Help/Html2 180 | DocProject/Help/html 181 | 182 | # Click-Once directory 183 | publish/ 184 | 185 | # Publish Web Output 186 | *.[Pp]ublish.xml 187 | *.azurePubxml 188 | # Note: Comment the next line if you want to checkin your web deploy settings, 189 | # but database connection strings (with potential passwords) will be unencrypted 190 | *.pubxml 191 | *.publishproj 192 | 193 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 194 | # checkin your Azure Web App publish settings, but sensitive information contained 195 | # in these scripts will be unencrypted 196 | PublishScripts/ 197 | 198 | # NuGet Packages 199 | *.nupkg 200 | # NuGet Symbol Packages 201 | *.snupkg 202 | # The packages folder can be ignored because of Package Restore 203 | **/[Pp]ackages/* 204 | # except build/, which is used as an MSBuild target. 205 | !**/[Pp]ackages/build/ 206 | # Uncomment if necessary however generally it will be regenerated when needed 207 | #!**/[Pp]ackages/repositories.config 208 | # NuGet v3's project.json files produces more ignorable files 209 | *.nuget.props 210 | *.nuget.targets 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 301 | *.vbp 302 | 303 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 304 | *.dsw 305 | *.dsp 306 | 307 | # Visual Studio 6 technical files 308 | *.ncb 309 | *.aps 310 | 311 | # Visual Studio LightSwitch build output 312 | **/*.HTMLClient/GeneratedArtifacts 313 | **/*.DesktopClient/GeneratedArtifacts 314 | **/*.DesktopClient/ModelManifest.xml 315 | **/*.Server/GeneratedArtifacts 316 | **/*.Server/ModelManifest.xml 317 | _Pvt_Extensions 318 | 319 | # Paket dependency manager 320 | .paket/paket.exe 321 | paket-files/ 322 | 323 | # FAKE - F# Make 324 | .fake/ 325 | 326 | # CodeRush personal settings 327 | .cr/personal 328 | 329 | # Python Tools for Visual Studio (PTVS) 330 | __pycache__/ 331 | *.pyc 332 | 333 | # Cake - Uncomment if you are using it 334 | # tools/** 335 | # !tools/packages.config 336 | 337 | # Tabs Studio 338 | *.tss 339 | 340 | # Telerik's JustMock configuration file 341 | *.jmconfig 342 | 343 | # BizTalk build output 344 | *.btp.cs 345 | *.btm.cs 346 | *.odx.cs 347 | *.xsd.cs 348 | 349 | # OpenCover UI analysis results 350 | OpenCover/ 351 | 352 | # Azure Stream Analytics local run output 353 | ASALocalRun/ 354 | 355 | # MSBuild Binary and Structured Log 356 | *.binlog 357 | 358 | # NVidia Nsight GPU debugger configuration file 359 | *.nvuser 360 | 361 | # MFractors (Xamarin productivity tool) working folder 362 | .mfractor/ 363 | 364 | # Local History for Visual Studio 365 | .localhistory/ 366 | 367 | # Visual Studio History (VSHistory) files 368 | .vshistory/ 369 | 370 | # BeatPulse healthcheck temp database 371 | healthchecksdb 372 | 373 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 374 | MigrationBackup/ 375 | 376 | # Ionide (cross platform F# VS Code tools) working folder 377 | .ionide/ 378 | 379 | # Fody - auto-generated XML schema 380 | FodyWeavers.xsd 381 | 382 | # VS Code files for those working on multiple tools 383 | .vscode/* 384 | !.vscode/settings.json 385 | !.vscode/tasks.json 386 | !.vscode/launch.json 387 | !.vscode/extensions.json 388 | *.code-workspace 389 | 390 | # Local History for Visual Studio Code 391 | .history/ 392 | 393 | # Windows Installer files from build outputs 394 | *.cab 395 | *.msi 396 | *.msix 397 | *.msm 398 | *.msp 399 | 400 | # JetBrains Rider 401 | *.sln.iml 402 | 403 | ## 404 | ## Visual studio for Mac 405 | ## 406 | 407 | 408 | # globs 409 | Makefile.in 410 | *.userprefs 411 | *.usertasks 412 | config.make 413 | config.status 414 | aclocal.m4 415 | install-sh 416 | autom4te.cache/ 417 | *.tar.gz 418 | tarballs/ 419 | test-results/ 420 | 421 | # Mac bundle stuff 422 | *.dmg 423 | *.app 424 | 425 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 426 | # General 427 | .DS_Store 428 | .AppleDouble 429 | .LSOverride 430 | 431 | # Icon must end with two \r 432 | Icon 433 | 434 | 435 | # Thumbnails 436 | ._* 437 | 438 | # Files that might appear in the root of a volume 439 | .DocumentRevisions-V100 440 | .fseventsd 441 | .Spotlight-V100 442 | .TemporaryItems 443 | .Trashes 444 | .VolumeIcon.icns 445 | .com.apple.timemachine.donotpresent 446 | 447 | # Directories potentially created on remote AFP share 448 | .AppleDB 449 | .AppleDesktop 450 | Network Trash Folder 451 | Temporary Items 452 | .apdisk 453 | 454 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore 455 | # Windows thumbnail cache files 456 | Thumbs.db 457 | ehthumbs.db 458 | ehthumbs_vista.db 459 | 460 | # Dump file 461 | *.stackdump 462 | 463 | # Folder config file 464 | [Dd]esktop.ini 465 | 466 | # Recycle Bin used on file shares 467 | $RECYCLE.BIN/ 468 | 469 | # Windows Installer files 470 | *.cab 471 | *.msi 472 | *.msix 473 | *.msm 474 | *.msp 475 | 476 | # Windows shortcuts 477 | *.lnk 478 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-dotnettools.csharp", 4 | "editorconfig.editorconfig", 5 | "ryanluker.vscode-coverage-gutters", 6 | "formulahendry.dotnet-test-explorer" 7 | ] 8 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | // Use IntelliSense to find out which attributes exist for C# debugging 6 | // Use hover for the description of the existing attributes 7 | // For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/source/Vignette.Desktop/bin/Debug/net7.0/Vignette.Desktop.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/source/Vignette.Desktop", 16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console 17 | "console": "internalConsole", 18 | "stopAtEntry": false 19 | }, 20 | { 21 | "name": ".NET Core Attach", 22 | "type": "coreclr", 23 | "request": "attach" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "coverage-gutters.coverageFileNames": [ 3 | "coverage.info", 4 | ], 5 | "dotnet-test-explorer.testProjectPath": "**/*Tests.@(csproj|vbproj|fsproj)", 6 | "dotnet-test-explorer.testArguments": "/p:IncludeTestAssembly=true /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=\"../results/coverage.info\" /p:MergeWith=\"../results/coverage.info\"", 7 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/source/Vignette.Desktop/Vignette.Desktop.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/source/Vignette.Desktop/Vignette.Desktop.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "--project", 36 | "${workspaceFolder}/source/Vignette.Desktop/Vignette.Desktop.csproj" 37 | ], 38 | "problemMatcher": "$msCompile" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | true 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | enable 4 | 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | License-Text: 2 | 3 | NOTE! This copyright does *not* cover community-made extensions 4 | using the extension SDK - this is merely considered normal use of 5 | the program, and does *not* fall under the heading of "derived work". 6 | 7 | While we're GPL-3.0, neither the trademark, name of the copyright holder 8 | nor the names of its contributors may be used to endorse or promote products 9 | derived from this software without specific prior written permission. 10 | 11 | Cosyne 12 | 13 | GNU GENERAL PUBLIC LICENSE 14 | Version 3, 29 June 2007 15 | 16 | Copyright (C) 2007 Free Software Foundation, Inc. 17 | Everyone is permitted to copy and distribute verbatim copies 18 | of this license document, but changing it is not allowed. 19 | 20 | Preamble 21 | 22 | The GNU General Public License is a free, copyleft license for 23 | software and other kinds of works. 24 | 25 | The licenses for most software and other practical works are designed 26 | to take away your freedom to share and change the works. By contrast, 27 | the GNU General Public License is intended to guarantee your freedom to 28 | share and change all versions of a program--to make sure it remains free 29 | software for all its users. We, the Free Software Foundation, use the 30 | GNU General Public License for most of our software; it applies also to 31 | any other work released this way by its authors. You can apply it to 32 | your programs, too. 33 | 34 | When we speak of free software, we are referring to freedom, not 35 | price. Our General Public Licenses are designed to make sure that you 36 | have the freedom to distribute copies of free software (and charge for 37 | them if you wish), that you receive source code or can get it if you 38 | want it, that you can change the software or use pieces of it in new 39 | free programs, and that you know you can do these things. 40 | 41 | To protect your rights, we need to prevent others from denying you 42 | these rights or asking you to surrender the rights. Therefore, you have 43 | certain responsibilities if you distribute copies of the software, or if 44 | you modify it: responsibilities to respect the freedom of others. 45 | 46 | For example, if you distribute copies of such a program, whether 47 | gratis or for a fee, you must pass on to the recipients the same 48 | freedoms that you received. You must make sure that they, too, receive 49 | or can get the source code. And you must show them these terms so they 50 | know their rights. 51 | 52 | Developers that use the GNU GPL protect your rights with two steps: 53 | (1) assert copyright on the software, and (2) offer you this License 54 | giving you legal permission to copy, distribute and/or modify it. 55 | 56 | For the developers' and authors' protection, the GPL clearly explains 57 | that there is no warranty for this free software. For both users' and 58 | authors' sake, the GPL requires that modified versions be marked as 59 | changed, so that their problems will not be attributed erroneously to 60 | authors of previous versions. 61 | 62 | Some devices are designed to deny users access to install or run 63 | modified versions of the software inside them, although the manufacturer 64 | can do so. This is fundamentally incompatible with the aim of 65 | protecting users' freedom to change the software. The systematic 66 | pattern of such abuse occurs in the area of products for individuals to 67 | use, which is precisely where it is most unacceptable. Therefore, we 68 | have designed this version of the GPL to prohibit the practice for those 69 | products. If such problems arise substantially in other domains, we 70 | stand ready to extend this provision to those domains in future versions 71 | of the GPL, as needed to protect the freedom of users. 72 | 73 | Finally, every program is threatened constantly by software patents. 74 | States should not allow patents to restrict development and use of 75 | software on general-purpose computers, but in those that do, we wish to 76 | avoid the special danger that patents applied to a free program could 77 | make it effectively proprietary. To prevent this, the GPL assures that 78 | patents cannot be used to render the program non-free. 79 | 80 | The precise terms and conditions for copying, distribution and 81 | modification follow. 82 | 83 | TERMS AND CONDITIONS 84 | 85 | 0. Definitions. 86 | 87 | "This License" refers to version 3 of the GNU General Public License. 88 | 89 | "Copyright" also means copyright-like laws that apply to other kinds of 90 | works, such as semiconductor masks. 91 | 92 | "The Program" refers to any copyrightable work licensed under this 93 | License. Each licensee is addressed as "you". "Licensees" and 94 | "recipients" may be individuals or organizations. 95 | 96 | To "modify" a work means to copy from or adapt all or part of the work 97 | in a fashion requiring copyright permission, other than the making of an 98 | exact copy. The resulting work is called a "modified version" of the 99 | earlier work or a work "based on" the earlier work. 100 | 101 | A "covered work" means either the unmodified Program or a work based 102 | on the Program. 103 | 104 | To "propagate" a work means to do anything with it that, without 105 | permission, would make you directly or secondarily liable for 106 | infringement under applicable copyright law, except executing it on a 107 | computer or modifying a private copy. Propagation includes copying, 108 | distribution (with or without modification), making available to the 109 | public, and in some countries other activities as well. 110 | 111 | To "convey" a work means any kind of propagation that enables other 112 | parties to make or receive copies. Mere interaction with a user through 113 | a computer network, with no transfer of a copy, is not conveying. 114 | 115 | An interactive user interface displays "Appropriate Legal Notices" 116 | to the extent that it includes a convenient and prominently visible 117 | feature that (1) displays an appropriate copyright notice, and (2) 118 | tells the user that there is no warranty for the work (except to the 119 | extent that warranties are provided), that licensees may convey the 120 | work under this License, and how to view a copy of this License. If 121 | the interface presents a list of user commands or options, such as a 122 | menu, a prominent item in the list meets this criterion. 123 | 124 | 1. Source Code. 125 | 126 | The "source code" for a work means the preferred form of the work 127 | for making modifications to it. "Object code" means any non-source 128 | form of a work. 129 | 130 | A "Standard Interface" means an interface that either is an official 131 | standard defined by a recognized standards body, or, in the case of 132 | interfaces specified for a particular programming language, one that 133 | is widely used among developers working in that language. 134 | 135 | The "System Libraries" of an executable work include anything, other 136 | than the work as a whole, that (a) is included in the normal form of 137 | packaging a Major Component, but which is not part of that Major 138 | Component, and (b) serves only to enable use of the work with that 139 | Major Component, or to implement a Standard Interface for which an 140 | implementation is available to the public in source code form. A 141 | "Major Component", in this context, means a major essential component 142 | (kernel, window system, and so on) of the specific operating system 143 | (if any) on which the executable work runs, or a compiler used to 144 | produce the work, or an object code interpreter used to run it. 145 | 146 | The "Corresponding Source" for a work in object code form means all 147 | the source code needed to generate, install, and (for an executable 148 | work) run the object code and to modify the work, including scripts to 149 | control those activities. However, it does not include the work's 150 | System Libraries, or general-purpose tools or generally available free 151 | programs which are used unmodified in performing those activities but 152 | which are not part of the work. For example, Corresponding Source 153 | includes interface definition files associated with source files for 154 | the work, and the source code for shared libraries and dynamically 155 | linked subprograms that the work is specifically designed to require, 156 | such as by intimate data communication or control flow between those 157 | subprograms and other parts of the work. 158 | 159 | The Corresponding Source need not include anything that users 160 | can regenerate automatically from other parts of the Corresponding 161 | Source. 162 | 163 | The Corresponding Source for a work in source code form is that 164 | same work. 165 | 166 | 2. Basic Permissions. 167 | 168 | All rights granted under this License are granted for the term of 169 | copyright on the Program, and are irrevocable provided the stated 170 | conditions are met. This License explicitly affirms your unlimited 171 | permission to run the unmodified Program. The output from running a 172 | covered work is covered by this License only if the output, given its 173 | content, constitutes a covered work. This License acknowledges your 174 | rights of fair use or other equivalent, as provided by copyright law. 175 | 176 | You may make, run and propagate covered works that you do not 177 | convey, without conditions so long as your license otherwise remains 178 | in force. You may convey covered works to others for the sole purpose 179 | of having them make modifications exclusively for you, or provide you 180 | with facilities for running those works, provided that you comply with 181 | the terms of this License in conveying all material for which you do 182 | not control copyright. Those thus making or running the covered works 183 | for you must do so exclusively on your behalf, under your direction 184 | and control, on terms that prohibit them from making any copies of 185 | your copyrighted material outside their relationship with you. 186 | 187 | Conveying under any other circumstances is permitted solely under 188 | the conditions stated below. Sublicensing is not allowed; section 10 189 | makes it unnecessary. 190 | 191 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 192 | 193 | No covered work shall be deemed part of an effective technological 194 | measure under any applicable law fulfilling obligations under article 195 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 196 | similar laws prohibiting or restricting circumvention of such 197 | measures. 198 | 199 | When you convey a covered work, you waive any legal power to forbid 200 | circumvention of technological measures to the extent such circumvention 201 | is effected by exercising rights under this License with respect to 202 | the covered work, and you disclaim any intention to limit operation or 203 | modification of the work as a means of enforcing, against the work's 204 | users, your or third parties' legal rights to forbid circumvention of 205 | technological measures. 206 | 207 | 4. Conveying Verbatim Copies. 208 | 209 | You may convey verbatim copies of the Program's source code as you 210 | receive it, in any medium, provided that you conspicuously and 211 | appropriately publish on each copy an appropriate copyright notice; 212 | keep intact all notices stating that this License and any 213 | non-permissive terms added in accord with section 7 apply to the code; 214 | keep intact all notices of the absence of any warranty; and give all 215 | recipients a copy of this License along with the Program. 216 | 217 | You may charge any price or no price for each copy that you convey, 218 | and you may offer support or warranty protection for a fee. 219 | 220 | 5. Conveying Modified Source Versions. 221 | 222 | You may convey a work based on the Program, or the modifications to 223 | produce it from the Program, in the form of source code under the 224 | terms of section 4, provided that you also meet all of these conditions: 225 | 226 | a) The work must carry prominent notices stating that you modified 227 | it, and giving a relevant date. 228 | 229 | b) The work must carry prominent notices stating that it is 230 | released under this License and any conditions added under section 231 | 7. This requirement modifies the requirement in section 4 to 232 | "keep intact all notices". 233 | 234 | c) You must license the entire work, as a whole, under this 235 | License to anyone who comes into possession of a copy. This 236 | License will therefore apply, along with any applicable section 7 237 | additional terms, to the whole of the work, and all its parts, 238 | regardless of how they are packaged. This License gives no 239 | permission to license the work in any other way, but it does not 240 | invalidate such permission if you have separately received it. 241 | 242 | d) If the work has interactive user interfaces, each must display 243 | Appropriate Legal Notices; however, if the Program has interactive 244 | interfaces that do not display Appropriate Legal Notices, your 245 | work need not make them do so. 246 | 247 | A compilation of a covered work with other separate and independent 248 | works, which are not by their nature extensions of the covered work, 249 | and which are not combined with it such as to form a larger program, 250 | in or on a volume of a storage or distribution medium, is called an 251 | "aggregate" if the compilation and its resulting copyright are not 252 | used to limit the access or legal rights of the compilation's users 253 | beyond what the individual works permit. Inclusion of a covered work 254 | in an aggregate does not cause this License to apply to the other 255 | parts of the aggregate. 256 | 257 | 6. Conveying Non-Source Forms. 258 | 259 | You may convey a covered work in object code form under the terms 260 | of sections 4 and 5, provided that you also convey the 261 | machine-readable Corresponding Source under the terms of this License, 262 | in one of these ways: 263 | 264 | a) Convey the object code in, or embodied in, a physical product 265 | (including a physical distribution medium), accompanied by the 266 | Corresponding Source fixed on a durable physical medium 267 | customarily used for software interchange. 268 | 269 | b) Convey the object code in, or embodied in, a physical product 270 | (including a physical distribution medium), accompanied by a 271 | written offer, valid for at least three years and valid for as 272 | long as you offer spare parts or customer support for that product 273 | model, to give anyone who possesses the object code either (1) a 274 | copy of the Corresponding Source for all the software in the 275 | product that is covered by this License, on a durable physical 276 | medium customarily used for software interchange, for a price no 277 | more than your reasonable cost of physically performing this 278 | conveying of source, or (2) access to copy the 279 | Corresponding Source from a network server at no charge. 280 | 281 | c) Convey individual copies of the object code with a copy of the 282 | written offer to provide the Corresponding Source. This 283 | alternative is allowed only occasionally and noncommercially, and 284 | only if you received the object code with such an offer, in accord 285 | with subsection 6b. 286 | 287 | d) Convey the object code by offering access from a designated 288 | place (gratis or for a charge), and offer equivalent access to the 289 | Corresponding Source in the same way through the same place at no 290 | further charge. You need not require recipients to copy the 291 | Corresponding Source along with the object code. If the place to 292 | copy the object code is a network server, the Corresponding Source 293 | may be on a different server (operated by you or a third party) 294 | that supports equivalent copying facilities, provided you maintain 295 | clear directions next to the object code saying where to find the 296 | Corresponding Source. Regardless of what server hosts the 297 | Corresponding Source, you remain obligated to ensure that it is 298 | available for as long as needed to satisfy these requirements. 299 | 300 | e) Convey the object code using peer-to-peer transmission, provided 301 | you inform other peers where the object code and Corresponding 302 | Source of the work are being offered to the general public at no 303 | charge under subsection 6d. 304 | 305 | A separable portion of the object code, whose source code is excluded 306 | from the Corresponding Source as a System Library, need not be 307 | included in conveying the object code work. 308 | 309 | A "User Product" is either (1) a "consumer product", which means any 310 | tangible personal property which is normally used for personal, family, 311 | or household purposes, or (2) anything designed or sold for incorporation 312 | into a dwelling. In determining whether a product is a consumer product, 313 | doubtful cases shall be resolved in favor of coverage. For a particular 314 | product received by a particular user, "normally used" refers to a 315 | typical or common use of that class of product, regardless of the status 316 | of the particular user or of the way in which the particular user 317 | actually uses, or expects or is expected to use, the product. A product 318 | is a consumer product regardless of whether the product has substantial 319 | commercial, industrial or non-consumer uses, unless such uses represent 320 | the only significant mode of use of the product. 321 | 322 | "Installation Information" for a User Product means any methods, 323 | procedures, authorization keys, or other information required to install 324 | and execute modified versions of a covered work in that User Product from 325 | a modified version of its Corresponding Source. The information must 326 | suffice to ensure that the continued functioning of the modified object 327 | code is in no case prevented or interfered with solely because 328 | modification has been made. 329 | 330 | If you convey an object code work under this section in, or with, or 331 | specifically for use in, a User Product, and the conveying occurs as 332 | part of a transaction in which the right of possession and use of the 333 | User Product is transferred to the recipient in perpetuity or for a 334 | fixed term (regardless of how the transaction is characterized), the 335 | Corresponding Source conveyed under this section must be accompanied 336 | by the Installation Information. But this requirement does not apply 337 | if neither you nor any third party retains the ability to install 338 | modified object code on the User Product (for example, the work has 339 | been installed in ROM). 340 | 341 | The requirement to provide Installation Information does not include a 342 | requirement to continue to provide support service, warranty, or updates 343 | for a work that has been modified or installed by the recipient, or for 344 | the User Product in which it has been modified or installed. Access to a 345 | network may be denied when the modification itself materially and 346 | adversely affects the operation of the network or violates the rules and 347 | protocols for communication across the network. 348 | 349 | Corresponding Source conveyed, and Installation Information provided, 350 | in accord with this section must be in a format that is publicly 351 | documented (and with an implementation available to the public in 352 | source code form), and must require no special password or key for 353 | unpacking, reading or copying. 354 | 355 | 7. Additional Terms. 356 | 357 | "Additional permissions" are terms that supplement the terms of this 358 | License by making exceptions from one or more of its conditions. 359 | Additional permissions that are applicable to the entire Program shall 360 | be treated as though they were included in this License, to the extent 361 | that they are valid under applicable law. If additional permissions 362 | apply only to part of the Program, that part may be used separately 363 | under those permissions, but the entire Program remains governed by 364 | this License without regard to the additional permissions. 365 | 366 | When you convey a copy of a covered work, you may at your option 367 | remove any additional permissions from that copy, or from any part of 368 | it. (Additional permissions may be written to require their own 369 | removal in certain cases when you modify the work.) You may place 370 | additional permissions on material, added by you to a covered work, 371 | for which you have or can give appropriate copyright permission. 372 | 373 | Notwithstanding any other provision of this License, for material you 374 | add to a covered work, you may (if authorized by the copyright holders of 375 | that material) supplement the terms of this License with terms: 376 | 377 | a) Disclaiming warranty or limiting liability differently from the 378 | terms of sections 15 and 16 of this License; or 379 | 380 | b) Requiring preservation of specified reasonable legal notices or 381 | author attributions in that material or in the Appropriate Legal 382 | Notices displayed by works containing it; or 383 | 384 | c) Prohibiting misrepresentation of the origin of that material, or 385 | requiring that modified versions of such material be marked in 386 | reasonable ways as different from the original version; or 387 | 388 | d) Limiting the use for publicity purposes of names of licensors or 389 | authors of the material; or 390 | 391 | e) Declining to grant rights under trademark law for use of some 392 | trade names, trademarks, or service marks; or 393 | 394 | f) Requiring indemnification of licensors and authors of that 395 | material by anyone who conveys the material (or modified versions of 396 | it) with contractual assumptions of liability to the recipient, for 397 | any liability that these contractual assumptions directly impose on 398 | those licensors and authors. 399 | 400 | All other non-permissive additional terms are considered "further 401 | restrictions" within the meaning of section 10. If the Program as you 402 | received it, or any part of it, contains a notice stating that it is 403 | governed by this License along with a term that is a further 404 | restriction, you may remove that term. If a license document contains 405 | a further restriction but permits relicensing or conveying under this 406 | License, you may add to a covered work material governed by the terms 407 | of that license document, provided that the further restriction does 408 | not survive such relicensing or conveying. 409 | 410 | If you add terms to a covered work in accord with this section, you 411 | must place, in the relevant source files, a statement of the 412 | additional terms that apply to those files, or a notice indicating 413 | where to find the applicable terms. 414 | 415 | Additional terms, permissive or non-permissive, may be stated in the 416 | form of a separately written license, or stated as exceptions; 417 | the above requirements apply either way. 418 | 419 | 8. Termination. 420 | 421 | You may not propagate or modify a covered work except as expressly 422 | provided under this License. Any attempt otherwise to propagate or 423 | modify it is void, and will automatically terminate your rights under 424 | this License (including any patent licenses granted under the third 425 | paragraph of section 11). 426 | 427 | However, if you cease all violation of this License, then your 428 | license from a particular copyright holder is reinstated (a) 429 | provisionally, unless and until the copyright holder explicitly and 430 | finally terminates your license, and (b) permanently, if the copyright 431 | holder fails to notify you of the violation by some reasonable means 432 | prior to 60 days after the cessation. 433 | 434 | Moreover, your license from a particular copyright holder is 435 | reinstated permanently if the copyright holder notifies you of the 436 | violation by some reasonable means, this is the first time you have 437 | received notice of violation of this License (for any work) from that 438 | copyright holder, and you cure the violation prior to 30 days after 439 | your receipt of the notice. 440 | 441 | Termination of your rights under this section does not terminate the 442 | licenses of parties who have received copies or rights from you under 443 | this License. If your rights have been terminated and not permanently 444 | reinstated, you do not qualify to receive new licenses for the same 445 | material under section 10. 446 | 447 | 9. Acceptance Not Required for Having Copies. 448 | 449 | You are not required to accept this License in order to receive or 450 | run a copy of the Program. Ancillary propagation of a covered work 451 | occurring solely as a consequence of using peer-to-peer transmission 452 | to receive a copy likewise does not require acceptance. However, 453 | nothing other than this License grants you permission to propagate or 454 | modify any covered work. These actions infringe copyright if you do 455 | not accept this License. Therefore, by modifying or propagating a 456 | covered work, you indicate your acceptance of this License to do so. 457 | 458 | 10. Automatic Licensing of Downstream Recipients. 459 | 460 | Each time you convey a covered work, the recipient automatically 461 | receives a license from the original licensors, to run, modify and 462 | propagate that work, subject to this License. You are not responsible 463 | for enforcing compliance by third parties with this License. 464 | 465 | An "entity transaction" is a transaction transferring control of an 466 | organization, or substantially all assets of one, or subdividing an 467 | organization, or merging organizations. If propagation of a covered 468 | work results from an entity transaction, each party to that 469 | transaction who receives a copy of the work also receives whatever 470 | licenses to the work the party's predecessor in interest had or could 471 | give under the previous paragraph, plus a right to possession of the 472 | Corresponding Source of the work from the predecessor in interest, if 473 | the predecessor has it or can get it with reasonable efforts. 474 | 475 | You may not impose any further restrictions on the exercise of the 476 | rights granted or affirmed under this License. For example, you may 477 | not impose a license fee, royalty, or other charge for exercise of 478 | rights granted under this License, and you may not initiate litigation 479 | (including a cross-claim or counterclaim in a lawsuit) alleging that 480 | any patent claim is infringed by making, using, selling, offering for 481 | sale, or importing the Program or any portion of it. 482 | 483 | 11. Patents. 484 | 485 | A "contributor" is a copyright holder who authorizes use under this 486 | License of the Program or a work on which the Program is based. The 487 | work thus licensed is called the contributor's "contributor version". 488 | 489 | A contributor's "essential patent claims" are all patent claims 490 | owned or controlled by the contributor, whether already acquired or 491 | hereafter acquired, that would be infringed by some manner, permitted 492 | by this License, of making, using, or selling its contributor version, 493 | but do not include claims that would be infringed only as a 494 | consequence of further modification of the contributor version. For 495 | purposes of this definition, "control" includes the right to grant 496 | patent sublicenses in a manner consistent with the requirements of 497 | this License. 498 | 499 | Each contributor grants you a non-exclusive, worldwide, royalty-free 500 | patent license under the contributor's essential patent claims, to 501 | make, use, sell, offer for sale, import and otherwise run, modify and 502 | propagate the contents of its contributor version. 503 | 504 | In the following three paragraphs, a "patent license" is any express 505 | agreement or commitment, however denominated, not to enforce a patent 506 | (such as an express permission to practice a patent or covenant not to 507 | sue for patent infringement). To "grant" such a patent license to a 508 | party means to make such an agreement or commitment not to enforce a 509 | patent against the party. 510 | 511 | If you convey a covered work, knowingly relying on a patent license, 512 | and the Corresponding Source of the work is not available for anyone 513 | to copy, free of charge and under the terms of this License, through a 514 | publicly available network server or other readily accessible means, 515 | then you must either (1) cause the Corresponding Source to be so 516 | available, or (2) arrange to deprive yourself of the benefit of the 517 | patent license for this particular work, or (3) arrange, in a manner 518 | consistent with the requirements of this License, to extend the patent 519 | license to downstream recipients. "Knowingly relying" means you have 520 | actual knowledge that, but for the patent license, your conveying the 521 | covered work in a country, or your recipient's use of the covered work 522 | in a country, would infringe one or more identifiable patents in that 523 | country that you have reason to believe are valid. 524 | 525 | If, pursuant to or in connection with a single transaction or 526 | arrangement, you convey, or propagate by procuring conveyance of, a 527 | covered work, and grant a patent license to some of the parties 528 | receiving the covered work authorizing them to use, propagate, modify 529 | or convey a specific copy of the covered work, then the patent license 530 | you grant is automatically extended to all recipients of the covered 531 | work and works based on it. 532 | 533 | A patent license is "discriminatory" if it does not include within 534 | the scope of its coverage, prohibits the exercise of, or is 535 | conditioned on the non-exercise of one or more of the rights that are 536 | specifically granted under this License. You may not convey a covered 537 | work if you are a party to an arrangement with a third party that is 538 | in the business of distributing software, under which you make payment 539 | to the third party based on the extent of your activity of conveying 540 | the work, and under which the third party grants, to any of the 541 | parties who would receive the covered work from you, a discriminatory 542 | patent license (a) in connection with copies of the covered work 543 | conveyed by you (or copies made from those copies), or (b) primarily 544 | for and in connection with specific products or compilations that 545 | contain the covered work, unless you entered into that arrangement, 546 | or that patent license was granted, prior to 28 March 2007. 547 | 548 | Nothing in this License shall be construed as excluding or limiting 549 | any implied license or other defenses to infringement that may 550 | otherwise be available to you under applicable patent law. 551 | 552 | 12. No Surrender of Others' Freedom. 553 | 554 | If conditions are imposed on you (whether by court order, agreement or 555 | otherwise) that contradict the conditions of this License, they do not 556 | excuse you from the conditions of this License. If you cannot convey a 557 | covered work so as to satisfy simultaneously your obligations under this 558 | License and any other pertinent obligations, then as a consequence you may 559 | not convey it at all. For example, if you agree to terms that obligate you 560 | to collect a royalty for further conveying from those to whom you convey 561 | the Program, the only way you could satisfy both those terms and this 562 | License would be to refrain entirely from conveying the Program. 563 | 564 | 13. Use with the GNU Affero General Public License. 565 | 566 | Notwithstanding any other provision of this License, you have 567 | permission to link or combine any covered work with a work licensed 568 | under version 3 of the GNU Affero General Public License into a single 569 | combined work, and to convey the resulting work. The terms of this 570 | License will continue to apply to the part which is the covered work, 571 | but the special requirements of the GNU Affero General Public License, 572 | section 13, concerning interaction through a network will apply to the 573 | combination as such. 574 | 575 | 14. Revised Versions of this License. 576 | 577 | The Free Software Foundation may publish revised and/or new versions of 578 | the GNU General Public License from time to time. Such new versions will 579 | be similar in spirit to the present version, but may differ in detail to 580 | address new problems or concerns. 581 | 582 | Each version is given a distinguishing version number. If the 583 | Program specifies that a certain numbered version of the GNU General 584 | Public License "or any later version" applies to it, you have the 585 | option of following the terms and conditions either of that numbered 586 | version or of any later version published by the Free Software 587 | Foundation. If the Program does not specify a version number of the 588 | GNU General Public License, you may choose any version ever published 589 | by the Free Software Foundation. 590 | 591 | If the Program specifies that a proxy can decide which future 592 | versions of the GNU General Public License can be used, that proxy's 593 | public statement of acceptance of a version permanently authorizes you 594 | to choose that version for the Program. 595 | 596 | Later license versions may give you additional or different 597 | permissions. However, no additional obligations are imposed on any 598 | author or copyright holder as a result of your choosing to follow a 599 | later version. 600 | 601 | 15. Disclaimer of Warranty. 602 | 603 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 604 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 605 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 606 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 607 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 608 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 609 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 610 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 611 | 612 | 16. Limitation of Liability. 613 | 614 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 615 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 616 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 617 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 618 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 619 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 620 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 621 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 622 | SUCH DAMAGES. 623 | 624 | 17. Interpretation of Sections 15 and 16. 625 | 626 | If the disclaimer of warranty and limitation of liability provided 627 | above cannot be given local legal effect according to their terms, 628 | reviewing courts shall apply local law that most closely approximates 629 | an absolute waiver of all civil liability in connection with the 630 | Program, unless a warranty or assumption of liability accompanies a 631 | copy of the Program in return for a fee. 632 | 633 | END OF TERMS AND CONDITIONS 634 | 635 | How to Apply These Terms to Your New Programs 636 | 637 | If you develop a new program, and you want it to be of the greatest 638 | possible use to the public, the best way to achieve this is to make it 639 | free software which everyone can redistribute and change under these terms. 640 | 641 | To do so, attach the following notices to the program. It is safest 642 | to attach them to the start of each source file to most effectively 643 | state the exclusion of warranty; and each file should have at least 644 | the "copyright" line and a pointer to where the full notice is found. 645 | 646 | 647 | Copyright (C) 648 | 649 | This program is free software: you can redistribute it and/or modify 650 | it under the terms of the GNU General Public License as published by 651 | the Free Software Foundation, either version 3 of the License, or 652 | (at your option) any later version. 653 | 654 | This program is distributed in the hope that it will be useful, 655 | but WITHOUT ANY WARRANTY; without even the implied warranty of 656 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 657 | GNU General Public License for more details. 658 | 659 | You should have received a copy of the GNU General Public License 660 | along with this program. If not, see . 661 | 662 | Also add information on how to contact you by electronic and paper mail. 663 | 664 | If the program does terminal interaction, make it output a short 665 | notice like this when it starts in an interactive mode: 666 | 667 | Copyright (C) 668 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 669 | This is free software, and you are welcome to redistribute it 670 | under certain conditions; type `show c' for details. 671 | 672 | The hypothetical commands `show w' and `show c' should show the appropriate 673 | parts of the General Public License. Of course, your program's commands 674 | might be different; for a GUI interface, you would use an "about box". 675 | 676 | You should also get your employer (if you work as a programmer) or school, 677 | if any, to sign a "copyright disclaimer" for the program, if necessary. 678 | For more information on this, and how to apply and follow the GNU GPL, see 679 | . 680 | 681 | The GNU General Public License does not permit incorporating your program 682 | into proprietary programs. If your program is a subroutine library, you 683 | may consider it more useful to permit linking proprietary applications with 684 | the library. If this is what you want to do, use the GNU Lesser General 685 | Public License instead of this License. But first, please read 686 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Vignette 4 | 5 |

6 | 7 |

8 | 9 | GitHub 10 | 11 | 12 |

13 | 14 |

15 | The open-source VTuber toolkit. 16 |

17 | 18 | ## Getting Started 19 | 20 | ### Building 21 | Please make sure you meet the following prerequisites: 22 | - A desktop platform with .NET 7 SDK or above installed. 23 | - Access to [GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry). 24 | 25 | ## License 26 | Vignette is Copyright © 2023 Cosyne, licensed under GNU General Public License v3.0 with SDK exception. For the full license text please see the [LICENSE](./LICENSE) file in this repository. -------------------------------------------------------------------------------- /Vignette.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "source", "source", "{287C23D6-960D-4ACA-8C4C-5833A62D9AEC}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vignette", "source\Vignette\Vignette.csproj", "{25C6A684-ABFE-4A8F-8DCD-B936E92A4FC7}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vignette.Desktop", "source\Vignette.Desktop\Vignette.Desktop.csproj", "{48F80885-59E2-4289-B65A-CB2F50EB981A}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {25C6A684-ABFE-4A8F-8DCD-B936E92A4FC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {25C6A684-ABFE-4A8F-8DCD-B936E92A4FC7}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {25C6A684-ABFE-4A8F-8DCD-B936E92A4FC7}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {25C6A684-ABFE-4A8F-8DCD-B936E92A4FC7}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {48F80885-59E2-4289-B65A-CB2F50EB981A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {48F80885-59E2-4289-B65A-CB2F50EB981A}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {48F80885-59E2-4289-B65A-CB2F50EB981A}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {48F80885-59E2-4289-B65A-CB2F50EB981A}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(NestedProjects) = preSolution 31 | {25C6A684-ABFE-4A8F-8DCD-B936E92A4FC7} = {287C23D6-960D-4ACA-8C4C-5833A62D9AEC} 32 | {48F80885-59E2-4289-B65A-CB2F50EB981A} = {287C23D6-960D-4ACA-8C4C-5833A62D9AEC} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /analysis/BannedSymbols.txt: -------------------------------------------------------------------------------- 1 | M:System.Object.Equals(System.Object,System.Object)~System.Boolean;Don't use object.Equals. Use IEquatable or EqualityComparer.Default instead. 2 | M:System.Object.Equals(System.Object)~System.Boolean;Don't use object.Equals. Use IEquatable or EqualityComparer.Default instead. 3 | M:System.ValueType.Equals(System.Object)~System.Boolean;Don't use object.Equals(Fallbacks to ValueType). Use IEquatable or EqualityComparer.Default instead. 4 | T:System.IComparable;Don't use non-generic IComparable. Use generic version instead. 5 | M:System.Guid.#ctor;You probably meant to use Guid.NewGuid() instead. If you actually want empty, use Guid.Empty. -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vignetteapp/vignette/70eb27079a7f928e329d4a7fdc1ecbc9486c8aa8/assets/logo.png -------------------------------------------------------------------------------- /source/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | Vignette 4 | The open source VTuber software. 5 | Cosyne 6 | Copyright (c) 2023 Cosyne 7 | README.md 8 | LICENSE 9 | https://github.com/vignetteapp/vignette 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /source/Vignette.Desktop/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using Sekai; 5 | using Vignette; 6 | 7 | Host.Run(new HostOptions { Name = "Vignette" }); 8 | -------------------------------------------------------------------------------- /source/Vignette.Desktop/Vignette.Desktop.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | WinExe 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /source/Vignette/Allocation/IObjectPool.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | namespace Vignette.Allocation; 5 | 6 | /// 7 | /// Defines a mechanism for objects that can pool . 8 | /// 9 | /// The type of object being pooled. 10 | public interface IObjectPool 11 | { 12 | /// 13 | /// Gets one from the pool. 14 | /// 15 | T Get(); 16 | 17 | /// 18 | /// Returns back to the pool. 19 | /// 20 | /// The to return. 21 | /// if the item has been returned. Otherwise, . 22 | bool Return(T item); 23 | } 24 | -------------------------------------------------------------------------------- /source/Vignette/Audio/AudioManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections.Concurrent; 6 | using System.Collections.Generic; 7 | using Sekai.Audio; 8 | using Vignette.Allocation; 9 | 10 | namespace Vignette.Audio; 11 | 12 | public sealed class AudioManager : IObjectPool 13 | { 14 | private const int max_buffer_size = 8192; 15 | private const int max_buffer_count = 500; 16 | private readonly AudioDevice device; 17 | private readonly ConcurrentBag bufferPool = new(); 18 | private readonly List controllers = new(); 19 | 20 | internal AudioManager(AudioDevice device) 21 | { 22 | this.device = device; 23 | } 24 | 25 | /// 26 | /// Creates a new for a . 27 | /// 28 | /// The audio stream to attach to the controller. 29 | /// An audio controller. 30 | public IAudioController GetController(AudioStream stream) 31 | { 32 | return new StreamingAudioController(device.CreateSource(), stream, this); 33 | } 34 | 35 | internal void Update() 36 | { 37 | for (int i = 0; i < controllers.Count; i++) 38 | { 39 | controllers[i].Update(); 40 | } 41 | } 42 | 43 | /// 44 | /// Returns an back to the . 45 | /// 46 | /// The controller to return. 47 | public void Return(IAudioController controller) 48 | { 49 | if (controller is not StreamingAudioController streaming) 50 | { 51 | return; 52 | } 53 | 54 | if (!controllers.Remove(streaming)) 55 | { 56 | return; 57 | } 58 | 59 | streaming.Dispose(); 60 | } 61 | 62 | AudioBuffer IObjectPool.Get() 63 | { 64 | if (!bufferPool.TryTake(out var buffer)) 65 | { 66 | buffer = device.CreateBuffer(); 67 | } 68 | 69 | return buffer; 70 | } 71 | 72 | bool IObjectPool.Return(AudioBuffer item) 73 | { 74 | if (bufferPool.Count >= max_buffer_count) 75 | { 76 | item.Dispose(); 77 | return false; 78 | } 79 | 80 | bufferPool.Add(item); 81 | return true; 82 | } 83 | 84 | private sealed class StreamingAudioController : IAudioController, IDisposable 85 | { 86 | public bool Loop { get; set; } 87 | 88 | public TimeSpan Position 89 | { 90 | get => getTimeFromByteCount((int)stream.Position, stream.Format, stream.SampleRate); 91 | set => seek(getByteCountFromTime(value, stream.Format, stream.SampleRate)); 92 | } 93 | 94 | public TimeSpan Duration => getTimeFromByteCount((int)stream.Length, stream.Format, stream.SampleRate); 95 | 96 | public TimeSpan Buffered => getTimeFromByteCount(buffered, stream.Format, stream.SampleRate); 97 | 98 | public AudioSourceState State => source.State; 99 | 100 | private int buffered; 101 | private bool isDisposed; 102 | private const int max_buffer_stream = 4; 103 | private readonly AudioSource source; 104 | private readonly AudioStream stream; 105 | private readonly IObjectPool bufferPool; 106 | 107 | public StreamingAudioController(AudioSource source, AudioStream stream, IObjectPool bufferPool) 108 | { 109 | this.source = source; 110 | this.stream = stream; 111 | this.bufferPool = bufferPool; 112 | } 113 | 114 | public void Play() 115 | { 116 | if (State != AudioSourceState.Paused) 117 | { 118 | seek(0); 119 | 120 | for (int i = 0; i < max_buffer_stream; i++) 121 | { 122 | var buffer = bufferPool.Get(); 123 | 124 | if (!allocate(buffer)) 125 | { 126 | break; 127 | } 128 | 129 | source.Enqueue(buffer); 130 | } 131 | } 132 | 133 | source.Play(); 134 | } 135 | 136 | public void Stop() 137 | { 138 | seek(0); 139 | } 140 | 141 | public void Pause() 142 | { 143 | source.Pause(); 144 | } 145 | 146 | public void Update() 147 | { 148 | while (source.TryDequeue(out var buffer)) 149 | { 150 | if (!allocate(buffer)) 151 | { 152 | source.Loop = Loop; 153 | break; 154 | } 155 | 156 | source.Enqueue(buffer); 157 | } 158 | } 159 | 160 | public void Dispose() 161 | { 162 | if (isDisposed) 163 | { 164 | return; 165 | } 166 | 167 | source.Stop(); 168 | 169 | while(source.TryDequeue(out var buffer)) 170 | { 171 | bufferPool.Return(buffer); 172 | } 173 | 174 | source.Dispose(); 175 | 176 | isDisposed = false; 177 | } 178 | 179 | private void seek(int position) 180 | { 181 | source.Stop(); 182 | source.Clear(); 183 | stream.Position = buffered = position; 184 | } 185 | 186 | private bool allocate(AudioBuffer buffer) 187 | { 188 | Span data = stackalloc byte[max_buffer_size]; 189 | int read = stream.Read(data); 190 | 191 | if (read <= 0) 192 | { 193 | return false; 194 | } 195 | 196 | buffer.SetData(data[..read], stream.Format, stream.SampleRate); 197 | buffered += read; 198 | 199 | return true; 200 | } 201 | } 202 | 203 | private static int getChannelCount(AudioFormat format) 204 | { 205 | return format is AudioFormat.Stereo8 or AudioFormat.Stereo16 ? 2 : 1; 206 | } 207 | 208 | private static int getSamplesCount(AudioFormat format) 209 | { 210 | return format is AudioFormat.Stereo8 or AudioFormat.Mono8 ? 8 : 16; 211 | } 212 | 213 | private static int getByteCountFromTime(TimeSpan time, AudioFormat format, int sampleRate) 214 | { 215 | return (int)time.TotalSeconds * sampleRate * getChannelCount(format) * (getSamplesCount(format) / 8); 216 | } 217 | 218 | private static TimeSpan getTimeFromByteCount(int count, AudioFormat format, int sampleRate) 219 | { 220 | return TimeSpan.FromSeconds(count / (sampleRate * getChannelCount(format) * (getSamplesCount(format) / 8))); 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /source/Vignette/Audio/AudioStream.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System.IO; 5 | using Sekai.Audio; 6 | 7 | namespace Vignette.Audio; 8 | 9 | /// 10 | /// A containing pulse code modulation (PCM) audio data. 11 | /// 12 | public class AudioStream : Stream 13 | { 14 | /// 15 | /// The audio stream's sample rate 16 | /// 17 | public int SampleRate { get; } 18 | 19 | /// 20 | /// The audio stream's format. 21 | /// 22 | public AudioFormat Format { get; } 23 | 24 | public override bool CanRead => stream.CanRead; 25 | 26 | public override bool CanSeek => stream.CanSeek; 27 | 28 | public override bool CanWrite => stream.CanWrite; 29 | 30 | public override long Length => stream.Length; 31 | 32 | public override long Position 33 | { 34 | get => stream.Position; 35 | set => stream.Position = value; 36 | } 37 | 38 | private bool isDisposed; 39 | private readonly MemoryStream stream; 40 | 41 | public AudioStream(byte[] buffer, AudioFormat format, int sampleRate) 42 | : this(buffer, true, format, sampleRate) 43 | { 44 | } 45 | 46 | public AudioStream(byte[] buffer, bool writable, AudioFormat format, int sampleRate) 47 | { 48 | Format = format; 49 | stream = new MemoryStream(buffer, writable); 50 | SampleRate = sampleRate; 51 | } 52 | 53 | public AudioStream(byte[] buffer, int index, int count, AudioFormat format, int sampleRate) 54 | : this(buffer, index, count, true, format, sampleRate) 55 | { 56 | } 57 | 58 | public AudioStream(byte[] buffer, int index, int count, bool writable, AudioFormat format, int sampleRate) 59 | { 60 | Format = format; 61 | stream = new MemoryStream(buffer, index, count, writable); 62 | SampleRate = sampleRate; 63 | } 64 | 65 | public AudioStream(int capacity, AudioFormat format, int sampleRate) 66 | { 67 | Format = format; 68 | stream = new MemoryStream(capacity); 69 | SampleRate = sampleRate; 70 | } 71 | 72 | public AudioStream(AudioFormat format, int sampleRate) 73 | : this(0, format, sampleRate) 74 | { 75 | } 76 | 77 | public override void Flush() 78 | { 79 | stream.Flush(); 80 | } 81 | 82 | public override int Read(byte[] buffer, int offset, int count) 83 | { 84 | return stream.Read(buffer, offset, count); 85 | } 86 | 87 | public override long Seek(long offset, SeekOrigin origin) 88 | { 89 | return stream.Seek(offset, origin); 90 | } 91 | 92 | public override void SetLength(long value) 93 | { 94 | stream.SetLength(value); 95 | } 96 | 97 | public override void Write(byte[] buffer, int offset, int count) 98 | { 99 | stream.Write(buffer, offset, count); 100 | } 101 | 102 | protected override void Dispose(bool disposing) 103 | { 104 | if (isDisposed) 105 | { 106 | return; 107 | } 108 | 109 | stream.Dispose(); 110 | 111 | isDisposed = true; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /source/Vignette/Audio/IAudioController.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using Sekai.Audio; 6 | 7 | namespace Vignette.Audio; 8 | 9 | /// 10 | /// Provides access to audio playback controls. 11 | /// 12 | public interface IAudioController 13 | { 14 | /// 15 | /// Gets or sets whether audio playback should loop. 16 | /// 17 | bool Loop { get; set; } 18 | 19 | /// 20 | /// Gets or seeks the current playback position. 21 | /// 22 | TimeSpan Position { get; set; } 23 | 24 | /// 25 | /// Gets total playable duration. 26 | /// 27 | TimeSpan Duration { get; } 28 | 29 | /// 30 | /// Gets the duration of the buffered data. 31 | /// 32 | TimeSpan Buffered { get; } 33 | 34 | /// 35 | /// Gets the state of this audio controller. 36 | /// 37 | AudioSourceState State { get; } 38 | 39 | /// 40 | /// Starts audio playback. 41 | /// 42 | void Play(); 43 | 44 | /// 45 | /// Stops audio playback. 46 | /// 47 | void Stop(); 48 | 49 | /// 50 | /// Pauses audio playback. 51 | /// 52 | void Pause(); 53 | } 54 | -------------------------------------------------------------------------------- /source/Vignette/Behavior.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | 6 | namespace Vignette; 7 | 8 | /// 9 | /// A that processes itself per-frame. 10 | /// 11 | public abstract class Behavior : Node, IComparable 12 | { 13 | /// 14 | /// The processing order for this . 15 | /// 16 | public int Order 17 | { 18 | get => order; 19 | set 20 | { 21 | if (order.Equals(value)) 22 | { 23 | return; 24 | } 25 | 26 | order = value; 27 | OrderChanged?.Invoke(this, EventArgs.Empty); 28 | } 29 | } 30 | 31 | /// 32 | /// Whether this should be enabled or not affecting calls. 33 | /// 34 | public bool Enabled 35 | { 36 | get => enabled; 37 | set 38 | { 39 | if (enabled.Equals(value)) 40 | { 41 | return; 42 | } 43 | 44 | enabled = value; 45 | EnabledChanged?.Invoke(this, EventArgs.Empty); 46 | } 47 | } 48 | 49 | /// 50 | /// Called when has been changed. 51 | /// 52 | public event EventHandler? OrderChanged; 53 | 54 | /// 55 | /// Called when has been changed. 56 | /// 57 | public event EventHandler? EnabledChanged; 58 | 59 | private int order; 60 | private bool enabled = true; 61 | 62 | /// 63 | /// Called once in the update loop after the has entered the node graph. 64 | /// 65 | public virtual void Load() 66 | { 67 | } 68 | 69 | /// 70 | /// Called every frame to perform updates on this . 71 | /// 72 | /// The time elapsed between frames. 73 | public virtual void Update(TimeSpan elapsed) 74 | { 75 | } 76 | 77 | /// 78 | /// Called once in the update loop before the exits the node graph. 79 | /// 80 | public virtual void Unload() 81 | { 82 | } 83 | 84 | public int CompareTo(Behavior? other) 85 | { 86 | if (other is null) 87 | { 88 | return -1; 89 | } 90 | 91 | int value = Depth.CompareTo(other.Depth); 92 | 93 | if (value != 0) 94 | { 95 | return value; 96 | } 97 | 98 | return Order.CompareTo(other.Order); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /source/Vignette/Camera.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Numerics; 6 | using Sekai.Mathematics; 7 | using Vignette.Graphics; 8 | 9 | namespace Vignette; 10 | 11 | public class Camera : Node, IProjector 12 | { 13 | /// 14 | /// The near plane distance. 15 | /// 16 | public float NearPlane = 0.1f; 17 | 18 | /// 19 | /// The far plane distance. 20 | /// 21 | public float FarPlane = 1000f; 22 | 23 | /// 24 | /// The camera's aspect ratio. 25 | /// 26 | /// Used when is . 27 | public float AspectRatio = 16.0f / 9.0f; 28 | 29 | /// 30 | /// The camera's field of view. 31 | /// 32 | public float FieldOfView = 60.0f; 33 | 34 | /// 35 | /// The camera's view size. 36 | /// 37 | public SizeF ViewSize = SizeF.Zero; 38 | 39 | /// 40 | /// The camera's view scale. 41 | /// 42 | public Vector2 ViewScale = Vector2.One; 43 | 44 | /// 45 | /// The camera's top left position. 46 | /// 47 | public Vector2 ViewTopLeft = Vector2.Zero; 48 | 49 | /// 50 | /// The camera projection mode. 51 | /// 52 | public CameraProjectionMode ProjectionMode = CameraProjectionMode.OrthographicOffCenter; 53 | 54 | /// 55 | /// The camera's rendering groups. 56 | /// 57 | public RenderGroup Groups { get; set; } = RenderGroup.Default; 58 | 59 | /// 60 | /// The camera's view frustum. 61 | /// 62 | public BoundingFrustum Frustum => BoundingFrustum.FromMatrix(((IProjector)this).ProjMatrix); 63 | 64 | Matrix4x4 IProjector.ViewMatrix => Matrix4x4.CreateLookAt(Position, Position + Vector3.Transform(-Vector3.UnitZ, Matrix4x4.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z)), Vector3.UnitY); 65 | 66 | Matrix4x4 IProjector.ProjMatrix => ProjectionMode switch 67 | { 68 | CameraProjectionMode.Perspective => Matrix4x4.CreatePerspective(ViewSize.Width * ViewScale.X, ViewSize.Height * ViewScale.Y, NearPlane, FarPlane), 69 | CameraProjectionMode.PerspectiveOffCenter => Matrix4x4.CreatePerspectiveOffCenter(ViewTopLeft.X, ViewSize.Width * ViewScale.X, ViewSize.Height * ViewScale.Y, ViewTopLeft.Y, NearPlane, FarPlane), 70 | CameraProjectionMode.PerspectiveFieldOfView => Matrix4x4.CreatePerspectiveFieldOfView(FieldOfView, AspectRatio, NearPlane, FarPlane), 71 | CameraProjectionMode.Orthographic => Matrix4x4.CreateOrthographic(ViewSize.Width * ViewScale.X, ViewSize.Height * ViewScale.Y, NearPlane, FarPlane), 72 | CameraProjectionMode.OrthographicOffCenter => Matrix4x4.CreateOrthographicOffCenter(ViewTopLeft.X, ViewSize.Width * ViewScale.X, ViewSize.Height * ViewScale.Y, ViewTopLeft.Y, NearPlane, FarPlane), 73 | _ => throw new InvalidOperationException($"Unknown {nameof(ProjectionMode)} {ProjectionMode}."), 74 | }; 75 | } 76 | 77 | /// 78 | /// An enumeration of camera projection modes. 79 | /// 80 | public enum CameraProjectionMode 81 | { 82 | /// 83 | /// Orthographic projection. 84 | /// 85 | Orthographic, 86 | 87 | /// 88 | /// Custom orthographic projection. 89 | /// 90 | OrthographicOffCenter, 91 | 92 | /// 93 | /// Perspective projection. 94 | /// 95 | Perspective, 96 | 97 | /// 98 | /// Custom perspective projection. 99 | /// 100 | PerspectiveOffCenter, 101 | 102 | /// 103 | /// Perspective field of view projection. 104 | /// 105 | PerspectiveFieldOfView, 106 | } 107 | -------------------------------------------------------------------------------- /source/Vignette/Collections/SortedFilteredCollection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | namespace Vignette.Collections; 9 | 10 | /// 11 | /// A collection whose items are sorted and filtered. 12 | /// 13 | /// The type this collection will contain. 14 | public class SortedFilteredCollection : ICollection 15 | { 16 | public int Count => items.Count; 17 | 18 | private bool shouldRebuildCache; 19 | private readonly List items = new(); 20 | private readonly List cache = new(); 21 | private readonly IComparer sorter; 22 | private readonly Predicate filter; 23 | private readonly Action sorterChangedSubscriber; 24 | private readonly Action sorterChangedUnsubscriber; 25 | private readonly Action filterChangedSubscriber; 26 | private readonly Action filterChangedUnsubscriber; 27 | 28 | public SortedFilteredCollection( 29 | IComparer sorter, 30 | Predicate filter, 31 | Action sorterChangedSubscriber, 32 | Action sorterChangedUnsubscriber, 33 | Action filterChangedSubscriber, 34 | Action filterChangedUnsubscriber 35 | ) 36 | { 37 | this.sorter = sorter; 38 | this.filter = filter; 39 | this.sorterChangedSubscriber = sorterChangedSubscriber; 40 | this.sorterChangedUnsubscriber = sorterChangedUnsubscriber; 41 | this.filterChangedSubscriber = filterChangedSubscriber; 42 | this.filterChangedUnsubscriber = filterChangedUnsubscriber; 43 | } 44 | 45 | public void Add(T item) 46 | { 47 | items.Add(item); 48 | invalidate(); 49 | } 50 | 51 | public bool Remove(T item) 52 | { 53 | if (!items.Remove(item)) 54 | { 55 | return false; 56 | } 57 | 58 | invalidate(); 59 | unsubscribeFromEvents(item); 60 | 61 | return true; 62 | } 63 | 64 | public void Clear() 65 | { 66 | for (int i = 0; i < items.Count; i++) 67 | { 68 | unsubscribeFromEvents(items[i]); 69 | } 70 | 71 | items.Clear(); 72 | invalidate(); 73 | } 74 | 75 | public bool Contains(T item) 76 | { 77 | return items.Contains(item); 78 | } 79 | 80 | public IEnumerator GetEnumerator() 81 | { 82 | if (shouldRebuildCache) 83 | { 84 | cache.Clear(); 85 | 86 | for (int i = 0; i < items.Count; i++) 87 | { 88 | var item = items[i]; 89 | 90 | if (filter(item)) 91 | { 92 | cache.Add(item); 93 | subscribeToEvents(item); 94 | } 95 | } 96 | 97 | if (cache.Count > 0) 98 | { 99 | cache.Sort(sorter); 100 | } 101 | 102 | shouldRebuildCache = false; 103 | } 104 | 105 | return cache.GetEnumerator(); 106 | } 107 | 108 | private void invalidate() 109 | { 110 | shouldRebuildCache = true; 111 | } 112 | 113 | private void subscribeToEvents(T item) 114 | { 115 | sorterChangedSubscriber(item, handleSorterChanged); 116 | filterChangedSubscriber(item, handleFilterChanged); 117 | } 118 | 119 | private void unsubscribeFromEvents(T item) 120 | { 121 | sorterChangedUnsubscriber(item, handleSorterChanged); 122 | filterChangedUnsubscriber(item, handleFilterChanged); 123 | } 124 | 125 | private void handleSorterChanged(object? sender, EventArgs args) 126 | { 127 | unsubscribeFromEvents((T)sender!); 128 | invalidate(); 129 | } 130 | 131 | private void handleFilterChanged(object? sender, EventArgs args) 132 | { 133 | invalidate(); 134 | } 135 | 136 | IEnumerator IEnumerable.GetEnumerator() 137 | { 138 | return GetEnumerator(); 139 | } 140 | 141 | bool ICollection.IsReadOnly => false; 142 | 143 | void ICollection.CopyTo(T[] array, int arrayIndex) => items.CopyTo(array, arrayIndex); 144 | } 145 | -------------------------------------------------------------------------------- /source/Vignette/Content/ContentManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics.CodeAnalysis; 7 | using System.IO; 8 | using Sekai.Storages; 9 | 10 | namespace Vignette.Content; 11 | 12 | /// 13 | /// Manages content. 14 | /// 15 | public sealed class ContentManager 16 | { 17 | private readonly Storage storage; 18 | private readonly HashSet extensions = new(); 19 | private readonly HashSet loaders = new(); 20 | private readonly Dictionary content = new(); 21 | 22 | internal ContentManager(Storage storage) 23 | { 24 | this.storage = storage; 25 | } 26 | 27 | /// 28 | /// Reads a file from and loads it as . 29 | /// 30 | /// The type of content to load. 31 | /// The path to the content. 32 | /// The loaded content. 33 | /// Thrown when invalid path has been passed. 34 | public T Load([StringSyntax(StringSyntaxAttribute.Uri)] string path) 35 | where T : class 36 | { 37 | string ext = Path.GetExtension(path); 38 | 39 | if (string.IsNullOrEmpty(ext)) 40 | { 41 | throw new ArgumentException($"Failed to determine file extension.", nameof(path)); 42 | } 43 | 44 | if (!extensions.Contains(ext)) 45 | { 46 | throw new ArgumentException($"Cannot load unsupported file extension \"{ext}\"."); 47 | } 48 | 49 | var key = new ContentKey(typeof(T), path); 50 | 51 | if (!content.TryGetValue(key, out var weak)) 52 | { 53 | weak = new WeakReference(null); 54 | content.Add(key, weak); 55 | } 56 | 57 | if (!weak.IsAlive) 58 | { 59 | weak.Target = Load(storage.Open(path, FileMode.Open, FileAccess.Read)); 60 | } 61 | 62 | return (T)weak.Target!; 63 | } 64 | 65 | /// 66 | /// Loads a as . 67 | /// 68 | /// The type of content to load. 69 | /// The stream to be read. 70 | /// The loaded content. 71 | /// Thrown when the stream can't be read. 72 | public T Load(Stream stream) 73 | where T : class 74 | { 75 | Span buffer = stackalloc byte[(int)stream.Length]; 76 | 77 | if (stream.Read(buffer) <= 0) 78 | { 79 | throw new InvalidOperationException("Failed to read stream."); 80 | } 81 | 82 | return Load((ReadOnlySpan)buffer); 83 | } 84 | 85 | /// 86 | /// Loads a as . 87 | /// 88 | /// The type of content to load. 89 | /// The byte data to be read. 90 | /// The loaded content. 91 | public T Load(byte[] bytes) 92 | where T : class 93 | { 94 | return Load(bytes); 95 | } 96 | 97 | /// 98 | /// Loads a as . 99 | /// 100 | /// The type of content to load. 101 | /// The byte data to be read. 102 | /// The loaded content. 103 | /// Thrown when no loader was able to load the content. 104 | public T Load(ReadOnlySpan bytes) 105 | where T : class 106 | { 107 | var result = default(T); 108 | 109 | foreach (var loader in loaders) 110 | { 111 | if (loader is not IContentLoader typedLoader) 112 | { 113 | continue; 114 | } 115 | 116 | try 117 | { 118 | result = typedLoader.Load(bytes); 119 | break; 120 | } 121 | catch 122 | { 123 | } 124 | } 125 | 126 | if (result is null) 127 | { 128 | throw new InvalidOperationException("Failed to load content."); 129 | } 130 | 131 | return result; 132 | } 133 | 134 | /// 135 | /// Adds a content loader to the content manager. 136 | /// 137 | /// The content loader to add. 138 | /// The file extensions supported by this loader. 139 | /// Thrown when 140 | internal void Add(IContentLoader loader, params string[] extensions) 141 | { 142 | foreach (string extension in extensions) 143 | { 144 | string ext = extension.StartsWith(ext_separator) ? extension : ext_separator + extension; 145 | this.loaders.Add(loader); 146 | this.extensions.Add(ext); 147 | } 148 | } 149 | 150 | private const char ext_separator = '.'; 151 | 152 | private readonly record struct ContentKey(Type Type, string Path); 153 | } 154 | -------------------------------------------------------------------------------- /source/Vignette/Content/IContentLoader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | 6 | namespace Vignette.Content; 7 | 8 | /// 9 | /// Defines a mechanism for loading content. 10 | /// 11 | public interface IContentLoader 12 | { 13 | } 14 | 15 | /// 16 | /// Defines a mechanism for loading . 17 | /// 18 | /// The type of content it loads. 19 | public interface IContentLoader : IContentLoader 20 | where T : class 21 | { 22 | /// 23 | /// Loads a as . 24 | /// 25 | /// The byte data to be read. 26 | /// The loaded content. 27 | T Load(ReadOnlySpan bytes); 28 | } 29 | -------------------------------------------------------------------------------- /source/Vignette/Content/ShaderLoader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Text; 6 | using Vignette.Graphics; 7 | 8 | namespace Vignette.Content; 9 | 10 | internal sealed class ShaderLoader : IContentLoader 11 | { 12 | public ShaderMaterial Load(ReadOnlySpan bytes) 13 | { 14 | return ShaderMaterial.Create(Encoding.UTF8.GetString(bytes)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /source/Vignette/Content/TextureLoader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using Sekai.Graphics; 6 | using StbiSharp; 7 | 8 | namespace Vignette.Content; 9 | 10 | internal sealed class TextureLoader : IContentLoader 11 | { 12 | private readonly GraphicsDevice device; 13 | 14 | public TextureLoader(GraphicsDevice device) 15 | { 16 | this.device = device; 17 | } 18 | 19 | public Texture Load(ReadOnlySpan bytes) 20 | { 21 | var image = Stbi.LoadFromMemory(bytes, 4); 22 | 23 | var texture = device.CreateTexture(new TextureDescription 24 | ( 25 | image.Width, 26 | image.Height, 27 | PixelFormat.R8G8B8A8_UNorm, 28 | 1, 29 | 1, 30 | TextureUsage.Resource 31 | )); 32 | 33 | texture.SetData(image.Data, 0, 0, 0, 0, 0, image.Width, image.Height, 0); 34 | 35 | return texture; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /source/Vignette/Content/WaveAudioLoader.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Text; 6 | using Sekai.Audio; 7 | using Vignette.Audio; 8 | 9 | namespace Vignette.Content; 10 | 11 | internal sealed class WaveAudioLoader : IContentLoader 12 | { 13 | public AudioStream Load(ReadOnlySpan bytes) 14 | { 15 | if (!MemoryExtensions.SequenceEqual(bytes[0..4], header_riff)) 16 | throw new ArgumentException(@"Failed to find ""RIFF"" header at position 0.", nameof(bytes)); 17 | 18 | if (!MemoryExtensions.SequenceEqual(bytes[8..12], header_wave)) 19 | throw new ArgumentException(@"Failed to find ""WAVE"" header at position 8.", nameof(bytes)); 20 | 21 | if (!MemoryExtensions.SequenceEqual(bytes[12..16], header_fmt)) 22 | throw new ArgumentException(@"Failed to find ""fmt "" header at position 12.", nameof(bytes)); 23 | 24 | if (!MemoryExtensions.SequenceEqual(bytes[36..40], header_data)) 25 | throw new ArgumentException(@"Failed to find ""data"" header at position 36.", nameof(bytes)); 26 | 27 | short contentType = BitConverter.ToInt16(bytes[20..22]); 28 | 29 | if (contentType != 1) 30 | { 31 | throw new ArgumentException(@"Content is not PCM data.", nameof(bytes)); 32 | } 33 | 34 | short numChannels = BitConverter.ToInt16(bytes[22..24]); 35 | short bitsPerSamp = BitConverter.ToInt16(bytes[34..36]); 36 | 37 | var format = numChannels == 2 38 | ? bitsPerSamp == 8 ? AudioFormat.Stereo8 : AudioFormat.Stereo16 39 | : bitsPerSamp == 8 ? AudioFormat.Mono8 : AudioFormat.Mono16; 40 | 41 | int rate = BitConverter.ToInt32(bytes[24..28]); 42 | int size = BitConverter.ToInt32(bytes[40..44]); 43 | 44 | var stream = new AudioStream(size, format, rate); 45 | stream.Write(bytes[44..size]); 46 | 47 | return stream; 48 | } 49 | 50 | private static readonly byte[] header_riff = Encoding.ASCII.GetBytes("RIFF"); 51 | private static readonly byte[] header_wave = Encoding.ASCII.GetBytes("WAVE"); 52 | private static readonly byte[] header_data = Encoding.ASCII.GetBytes("data"); 53 | private static readonly byte[] header_fmt = Encoding.ASCII.GetBytes("fmt "); 54 | } 55 | -------------------------------------------------------------------------------- /source/Vignette/Drawable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using Vignette.Graphics; 6 | 7 | namespace Vignette; 8 | 9 | /// 10 | /// A that is capable of drawing. 11 | /// 12 | public abstract class Drawable : Behavior 13 | { 14 | /// 15 | /// Whether this should be drawn or not. 16 | /// 17 | public bool Visible 18 | { 19 | get => visible; 20 | set 21 | { 22 | if (visible.Equals(value)) 23 | { 24 | return; 25 | } 26 | 27 | visible = value; 28 | VisibleChanged?.Invoke(this, EventArgs.Empty); 29 | } 30 | } 31 | 32 | /// 33 | /// Called when has been changed. 34 | /// 35 | public event EventHandler? VisibleChanged; 36 | 37 | private bool visible = true; 38 | 39 | /// 40 | /// Called every frame to perform drawing operations on this . 41 | /// 42 | /// The drawable rendering context. 43 | public virtual void Draw(RenderContext context) 44 | { 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/Effect.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Collections.Immutable; 8 | using System.Diagnostics.CodeAnalysis; 9 | using Sekai.Graphics; 10 | 11 | namespace Vignette.Graphics; 12 | 13 | public readonly struct Effect : IEquatable 14 | { 15 | private readonly ShaderCode[] shaderCodes; 16 | 17 | private Effect(params ShaderCode[] shaderCodes) 18 | { 19 | this.shaderCodes = shaderCodes; 20 | } 21 | 22 | public readonly bool Equals(Effect other) 23 | { 24 | return ((IStructuralEquatable)shaderCodes).Equals(other.shaderCodes, EqualityComparer.Default); 25 | } 26 | 27 | public override readonly bool Equals([NotNullWhen(true)] object? obj) 28 | { 29 | return obj is Effect effect && Equals(effect); 30 | } 31 | 32 | public override readonly int GetHashCode() 33 | { 34 | HashCode hash = default; 35 | 36 | for (int i = 0; i < shaderCodes.Length; i++) 37 | { 38 | hash.Add(shaderCodes[i]); 39 | } 40 | 41 | return hash.ToHashCode(); 42 | } 43 | 44 | /// 45 | /// Creates a new from HLSL shader code. 46 | /// 47 | /// The HLSL shader code. 48 | /// The reflected input layout. 49 | /// The reflected shader properties. 50 | /// A new . 51 | internal static Effect From(string code, out InputLayoutDescription layout, out IProperty[] properties) 52 | { 53 | code = sh_common + code; 54 | 55 | var shVert = ShaderCode.From(code, ShaderStage.Vertex, sh_vert, ShaderLanguage.HLSL); 56 | var shFrag = ShaderCode.From(code, ShaderStage.Fragment, sh_frag, ShaderLanguage.HLSL); 57 | 58 | var shVertReflect = shVert.Reflect(); 59 | var shFragReflect = shFrag.Reflect(); 60 | 61 | if (shVertReflect.Inputs is not null) 62 | { 63 | var format = new InputLayoutMember[shVertReflect.Inputs.Length]; 64 | 65 | for (int i = 0; i < shVertReflect.Inputs.Length; i++) 66 | { 67 | format[i] = format_members[shVertReflect.Inputs[i].Type]; 68 | } 69 | 70 | layout = new(format); 71 | } 72 | else 73 | { 74 | layout = new(); 75 | } 76 | 77 | var textures = new List(); 78 | var uniforms = new List(); 79 | 80 | if (shVertReflect.Uniforms is not null) 81 | { 82 | uniforms.AddRange(shVertReflect.Uniforms); 83 | } 84 | 85 | if (shVertReflect.Textures is not null) 86 | { 87 | textures.AddRange(shVertReflect.Textures); 88 | } 89 | 90 | if (shFragReflect.Uniforms is not null) 91 | { 92 | uniforms.AddRange(shFragReflect.Uniforms); 93 | } 94 | 95 | if (shFragReflect.Textures is not null) 96 | { 97 | textures.AddRange(shFragReflect.Textures); 98 | } 99 | 100 | var props = new List(); 101 | 102 | foreach (var uniform in uniforms) 103 | { 104 | if (uniform.Name.StartsWith(sh_global)) 105 | { 106 | continue; 107 | } 108 | 109 | props.Add(new UniformProperty(uniform.Name, uniform.Binding)); 110 | } 111 | 112 | foreach (var texture in textures) 113 | { 114 | if (texture.Name.StartsWith(sh_global)) 115 | { 116 | continue; 117 | } 118 | 119 | props.Add(new TextureProperty(texture.Name, texture.Binding)); 120 | } 121 | 122 | properties = props.ToArray(); 123 | 124 | return new Effect(shVert, shFrag); 125 | } 126 | 127 | public static bool operator ==(Effect left, Effect right) 128 | { 129 | return left.Equals(right); 130 | } 131 | 132 | public static bool operator !=(Effect left, Effect right) 133 | { 134 | return !(left == right); 135 | } 136 | 137 | public static explicit operator ShaderCode[](Effect effect) => effect.shaderCodes; 138 | 139 | public const int GLOBAL_TRANSFORM_ID = 89; 140 | 141 | private const string sh_vert = "Vertex"; 142 | private const string sh_frag = "Pixel"; 143 | private const string sh_global = "g_internal_"; 144 | 145 | private static readonly string sh_common = 146 | @$" 147 | #define P_MATRIX g_internal_ProjMatrix 148 | #define V_MATRIX g_internal_ViewMatrix 149 | #define M_MATRIX g_internal_ModelMatrix 150 | #define OBJECT_TO_CLIP(a) mul(mul(V_MATRIX, M_MATRIX), a) 151 | #define OBJECT_TO_VIEW(a) mul(P_MATRIX, OBJECT_TO_CLIP(a)) 152 | 153 | cbuffer g_internal_Transform : register(b{GLOBAL_TRANSFORM_ID}) 154 | {{ 155 | float4x4 g_internal_ProjMatrix; 156 | float4x4 g_internal_ViewMatrix; 157 | float4x4 g_internal_ModelMatrix; 158 | }}; 159 | "; 160 | 161 | private static readonly IReadOnlyDictionary format_members = ImmutableDictionary.CreateRange 162 | ( 163 | new KeyValuePair[] 164 | { 165 | KeyValuePair.Create("int", new(1, false, InputLayoutFormat.Int)), 166 | KeyValuePair.Create("ivec2", new(2, false, InputLayoutFormat.Int)), 167 | KeyValuePair.Create("ivec3", new(3, false, InputLayoutFormat.Int)), 168 | KeyValuePair.Create("ivec4", new(4, false, InputLayoutFormat.Int)), 169 | KeyValuePair.Create("imat2", new(4, false, InputLayoutFormat.Int)), 170 | KeyValuePair.Create("imat2x3", new(6, false, InputLayoutFormat.Int)), 171 | KeyValuePair.Create("imat2x4", new(8, false, InputLayoutFormat.Int)), 172 | KeyValuePair.Create("imat3", new(9, false, InputLayoutFormat.Int)), 173 | KeyValuePair.Create("imat3x2", new(6, false, InputLayoutFormat.Int)), 174 | KeyValuePair.Create("imat3x4", new(12, false, InputLayoutFormat.Int)), 175 | KeyValuePair.Create("imat4", new(16, false, InputLayoutFormat.Int)), 176 | KeyValuePair.Create("imat4x2", new(8, false, InputLayoutFormat.Int)), 177 | KeyValuePair.Create("imat4x3", new(12, false, InputLayoutFormat.Int)), 178 | KeyValuePair.Create("uint", new(1, false, InputLayoutFormat.UnsignedInt)), 179 | KeyValuePair.Create("uvec2", new(2, false, InputLayoutFormat.UnsignedInt)), 180 | KeyValuePair.Create("uvec3", new(3, false, InputLayoutFormat.UnsignedInt)), 181 | KeyValuePair.Create("uvec4", new(4, false, InputLayoutFormat.UnsignedInt)), 182 | KeyValuePair.Create("umat2", new(4, false, InputLayoutFormat.UnsignedInt)), 183 | KeyValuePair.Create("umat2x3", new(6, false, InputLayoutFormat.UnsignedInt)), 184 | KeyValuePair.Create("umat2x4", new(8, false, InputLayoutFormat.UnsignedInt)), 185 | KeyValuePair.Create("umat3", new(9, false, InputLayoutFormat.UnsignedInt)), 186 | KeyValuePair.Create("umat3x2", new(6, false, InputLayoutFormat.UnsignedInt)), 187 | KeyValuePair.Create("umat3x4", new(12, false, InputLayoutFormat.UnsignedInt)), 188 | KeyValuePair.Create("umat4", new(16, false, InputLayoutFormat.UnsignedInt)), 189 | KeyValuePair.Create("umat4x2", new(8, false, InputLayoutFormat.UnsignedInt)), 190 | KeyValuePair.Create("umat4x3", new(12, false, InputLayoutFormat.UnsignedInt)), 191 | KeyValuePair.Create("bool", new(1, false, InputLayoutFormat.Int)), 192 | KeyValuePair.Create("bvec2", new(2, false, InputLayoutFormat.Int)), 193 | KeyValuePair.Create("bvec3", new(3, false, InputLayoutFormat.Int)), 194 | KeyValuePair.Create("bvec4", new(4, false, InputLayoutFormat.Int)), 195 | KeyValuePair.Create("bmat2", new(4, false, InputLayoutFormat.Int)), 196 | KeyValuePair.Create("bmat2x3", new(6, false, InputLayoutFormat.Int)), 197 | KeyValuePair.Create("bmat2x4", new(8, false, InputLayoutFormat.Int)), 198 | KeyValuePair.Create("bmat3", new(9, false, InputLayoutFormat.Int)), 199 | KeyValuePair.Create("bmat3x2", new(6, false, InputLayoutFormat.Int)), 200 | KeyValuePair.Create("bmat3x4", new(12, false, InputLayoutFormat.Int)), 201 | KeyValuePair.Create("bmat4", new(16, false, InputLayoutFormat.Int)), 202 | KeyValuePair.Create("bmat4x2", new(8, false, InputLayoutFormat.Int)), 203 | KeyValuePair.Create("bmat4x3", new(12, false, InputLayoutFormat.Int)), 204 | KeyValuePair.Create("float", new(1, false, InputLayoutFormat.Float)), 205 | KeyValuePair.Create("vec2", new(2, false, InputLayoutFormat.Float)), 206 | KeyValuePair.Create("vec3", new(3, false, InputLayoutFormat.Float)), 207 | KeyValuePair.Create("vec4", new(4, false, InputLayoutFormat.Float)), 208 | KeyValuePair.Create("mat2", new(4, false, InputLayoutFormat.Float)), 209 | KeyValuePair.Create("mat2x3", new(6, false, InputLayoutFormat.Float)), 210 | KeyValuePair.Create("mat2x4", new(8, false, InputLayoutFormat.Float)), 211 | KeyValuePair.Create("mat3", new(9, false, InputLayoutFormat.Float)), 212 | KeyValuePair.Create("mat3x2", new(6, false, InputLayoutFormat.Float)), 213 | KeyValuePair.Create("mat3x4", new(12, false, InputLayoutFormat.Float)), 214 | KeyValuePair.Create("mat4", new(16, false, InputLayoutFormat.Float)), 215 | KeyValuePair.Create("mat4x2", new(8, false, InputLayoutFormat.Float)), 216 | KeyValuePair.Create("mat4x3", new(12, false, InputLayoutFormat.Float)), 217 | KeyValuePair.Create("double", new(1, false, InputLayoutFormat.Double)), 218 | KeyValuePair.Create("dvec2", new(2, false, InputLayoutFormat.Double)), 219 | KeyValuePair.Create("dvec3", new(3, false, InputLayoutFormat.Double)), 220 | KeyValuePair.Create("dvec4", new(4, false, InputLayoutFormat.Double)), 221 | KeyValuePair.Create("dmat2", new(4, false, InputLayoutFormat.Double)), 222 | KeyValuePair.Create("dmat2x3", new(6, false, InputLayoutFormat.Double)), 223 | KeyValuePair.Create("dmat2x4", new(8, false, InputLayoutFormat.Double)), 224 | KeyValuePair.Create("dmat3", new(9, false, InputLayoutFormat.Double)), 225 | KeyValuePair.Create("dmat3x2", new(6, false, InputLayoutFormat.Double)), 226 | KeyValuePair.Create("dmat3x4", new(12, false, InputLayoutFormat.Double)), 227 | KeyValuePair.Create("dmat4", new(16, false, InputLayoutFormat.Double)), 228 | KeyValuePair.Create("dmat4x2", new(8, false, InputLayoutFormat.Double)), 229 | KeyValuePair.Create("dmat4x3", new(12, false, InputLayoutFormat.Double)), 230 | } 231 | ); 232 | } 233 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/IMaterial.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using Sekai.Graphics; 7 | 8 | namespace Vignette.Graphics; 9 | 10 | /// 11 | /// Defines properties of a surface and how it should be drawn. 12 | /// 13 | public interface IMaterial 14 | { 15 | /// 16 | /// The stencil reference. 17 | /// 18 | int Stencil { get; } 19 | 20 | /// 21 | /// The material effect. 22 | /// 23 | Effect Effect { get; } 24 | 25 | /// 26 | /// The primitive type. 27 | /// 28 | PrimitiveType Primitives { get; } 29 | 30 | /// 31 | /// The layout descriptor. 32 | /// 33 | InputLayoutDescription Layout { get; } 34 | 35 | /// 36 | /// The blend descriptor. 37 | /// 38 | BlendStateDescription Blend { get; } 39 | 40 | /// 41 | /// The rasterizer descriptor. 42 | /// 43 | RasterizerStateDescription Rasterizer { get; } 44 | 45 | /// 46 | /// The depth stencil descriptor. 47 | /// 48 | DepthStencilStateDescription DepthStencil { get; } 49 | 50 | /// 51 | /// The material properties. 52 | /// 53 | IEnumerable Properties { get; } 54 | 55 | /// 56 | /// Gets a unique ID for this . 57 | /// 58 | int GetMaterialID() 59 | { 60 | return HashCode.Combine(Stencil, Blend, Rasterizer, DepthStencil, Effect, Layout); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/IProjector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System.Numerics; 5 | using Sekai.Mathematics; 6 | 7 | namespace Vignette.Graphics; 8 | 9 | /// 10 | /// An interface for objects providing clip space info. 11 | /// 12 | public interface IProjector 13 | { 14 | /// 15 | /// The projector's position. 16 | /// 17 | Vector3 Position { get; } 18 | 19 | /// 20 | /// The projector's rotation. 21 | /// 22 | Vector3 Rotation { get; } 23 | 24 | /// 25 | /// The projector's view matrix. 26 | /// 27 | Matrix4x4 ViewMatrix { get; } 28 | 29 | /// 30 | /// The projector's projection matrix. 31 | /// 32 | Matrix4x4 ProjMatrix { get; } 33 | 34 | /// 35 | /// The projector's render groups. 36 | /// 37 | RenderGroup Groups { get; } 38 | 39 | /// 40 | /// The projector's bounding frustum. 41 | /// 42 | BoundingFrustum Frustum { get; } 43 | } 44 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/IProperty.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using Sekai.Graphics; 5 | 6 | namespace Vignette.Graphics; 7 | 8 | /// 9 | /// Defines a property. 10 | /// 11 | public interface IProperty 12 | { 13 | /// 14 | /// The property name. 15 | /// 16 | string Name { get; } 17 | 18 | /// 19 | /// The property slot. 20 | /// 21 | int Slot { get; } 22 | } 23 | 24 | /// 25 | /// Defines a property that contains a as its value. 26 | /// 27 | /// The property name. 28 | /// The property slot. 29 | /// The buffer. 30 | public record struct UniformProperty(string Name, int Slot, GraphicsBuffer? Uniform = null) : IProperty; 31 | 32 | /// 33 | /// Defines a property that contains a and pair as its value. 34 | /// 35 | /// The property name. 36 | /// The property slot. 37 | /// The texture. 38 | /// The sampler. 39 | public record struct TextureProperty(string Name, int Slot, Texture? Texture = null, Sampler? Sampler = null) : IProperty; 40 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/IWorld.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System.Numerics; 5 | 6 | namespace Vignette.Graphics; 7 | 8 | /// 9 | /// An interface for objects providing world space info. 10 | /// 11 | public interface IWorld 12 | { 13 | /// 14 | /// The world's position. 15 | /// 16 | Vector3 Position { get; } 17 | 18 | /// 19 | /// The world's rotation. 20 | /// 21 | Vector3 Rotation { get; } 22 | 23 | /// 24 | /// The world's scaling. 25 | /// 26 | Vector3 Scale { get; } 27 | 28 | /// 29 | /// The world's shearing. 30 | /// 31 | Vector3 Shear { get; } 32 | 33 | /// 34 | /// The world's local matrix. 35 | /// 36 | Matrix4x4 LocalMatrix { get; } 37 | 38 | /// 39 | /// The world's world matrix. 40 | /// 41 | Matrix4x4 WorldMatrix { get; } 42 | } 43 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/RenderContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | namespace Vignette.Graphics; 5 | 6 | /// 7 | /// A rendering context for a given . 8 | /// 9 | public readonly struct RenderContext 10 | { 11 | private readonly IWorld world; 12 | private readonly RenderQueue queue; 13 | private readonly IProjector projector; 14 | 15 | internal RenderContext(RenderQueue queue, IProjector projector, IWorld world) 16 | { 17 | this.queue = queue; 18 | this.world = world; 19 | this.projector = projector; 20 | } 21 | 22 | /// 23 | /// Draws a render object. 24 | /// 25 | /// The to draw. 26 | public void Draw(RenderObject renderObject) 27 | { 28 | queue.Enqueue(projector, world, renderObject); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/RenderData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | namespace Vignette.Graphics; 5 | 6 | /// 7 | /// A fully realized renderable that can be drawn. 8 | /// 9 | public readonly struct RenderData 10 | { 11 | /// 12 | /// The world. 13 | /// 14 | public IWorld World { get; } 15 | 16 | /// 17 | /// The projector. 18 | /// 19 | public IProjector Projector { get; } 20 | 21 | /// 22 | /// The renderable. 23 | /// 24 | public RenderObject Renderable { get; } 25 | 26 | public RenderData(IProjector projector, IWorld world, RenderObject renderable) 27 | { 28 | World = world; 29 | Projector = projector; 30 | Renderable = renderable; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/RenderGroup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | 6 | namespace Vignette.Graphics; 7 | 8 | /// 9 | /// Render Group Flags. 10 | /// 11 | [Flags] 12 | public enum RenderGroup : uint 13 | { 14 | /// 15 | /// Render Group Default 16 | /// 17 | Default = 0, 18 | 19 | /// 20 | /// Render Group 1 21 | /// 22 | Group1 = 1 << 0, 23 | 24 | /// 25 | /// Render Group 2 26 | /// 27 | Group2 = 1 << 1, 28 | 29 | /// 30 | /// Render Group 3 31 | /// 32 | Group3 = 1 << 2, 33 | 34 | /// 35 | /// Render Group 4 36 | /// 37 | Group4 = 1 << 3, 38 | 39 | /// 40 | /// Render Group 5 41 | /// 42 | Group5 = 1 << 4, 43 | 44 | /// 45 | /// Render Group 6 46 | /// 47 | Group6 = 1 << 5, 48 | 49 | /// 50 | /// Render Group 7 51 | /// 52 | Group7 = 1 << 6, 53 | 54 | /// 55 | /// Render Group 8 56 | /// 57 | Group8 = 1 << 7, 58 | 59 | /// 60 | /// Render Group 9 61 | /// 62 | Group9 = 1 << 8, 63 | 64 | /// 65 | /// Render Group 10 66 | /// 67 | Group10 = 1 << 9, 68 | 69 | /// 70 | /// Render Group 11 71 | /// 72 | Group11 = 1 << 10, 73 | 74 | /// 75 | /// Render Group 12 76 | /// 77 | Group12 = 1 << 11, 78 | 79 | /// 80 | /// Render Group 13 81 | /// 82 | Group13 = 1 << 12, 83 | 84 | /// 85 | /// Render Group 14 86 | /// 87 | Group14 = 1 << 13, 88 | 89 | /// 90 | /// Render Group 15 91 | /// 92 | Group15 = 1 << 14, 93 | 94 | /// 95 | /// Render Group 16 96 | /// 97 | Group16 = 1 << 15, 98 | } 99 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/RenderObject.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using Sekai.Graphics; 5 | using Sekai.Mathematics; 6 | 7 | namespace Vignette.Graphics; 8 | 9 | /// 10 | /// An object that can be drawn. 11 | /// 12 | public class RenderObject 13 | { 14 | /// 15 | /// The bounding box of this . 16 | /// 17 | public BoundingBox Bounds { get; set; } = BoundingBox.Empty; 18 | 19 | /// 20 | /// The rendering groups this is visible to. 21 | /// 22 | public RenderGroup Groups { get; set; } = RenderGroup.Default; 23 | 24 | /// 25 | /// The material this uses. 26 | /// 27 | public IMaterial Material { get; set; } = UnlitMaterial.Default; 28 | 29 | /// 30 | /// The number of indices to be drawn. 31 | /// 32 | public int IndexCount { get; set; } 33 | 34 | /// 35 | /// The type of indices being to be interpreted in the . 36 | /// 37 | public IndexType IndexType { get; set; } = IndexType.UnsignedShort; 38 | 39 | /// 40 | /// The index buffer for this render object. 41 | /// 42 | public GraphicsBuffer? IndexBuffer { get; set; } 43 | 44 | /// 45 | /// The vertex buffer for this render object. 46 | /// 47 | public GraphicsBuffer? VertexBuffer { get; set; } 48 | } 49 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/RenderQueue.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Diagnostics.CodeAnalysis; 8 | using System.Numerics; 9 | using Sekai.Mathematics; 10 | 11 | namespace Vignette.Graphics; 12 | 13 | /// 14 | /// A priority queue that is sorted by the distance between a projector and a model. 15 | /// 16 | public sealed class RenderQueue : IReadOnlyCollection 17 | { 18 | /// 19 | /// Gets the number of s queued. 20 | /// 21 | public int Count => renderables.Count; 22 | 23 | private readonly List renderables = new(); 24 | private readonly List renderOrders = new(); 25 | 26 | /// 27 | /// Creates a new render queue. 28 | /// 29 | public RenderQueue() 30 | { 31 | } 32 | 33 | /// 34 | /// Enqueues a to this queue. 35 | /// 36 | /// The projector used. 37 | /// The model used. 38 | /// The render object to be enqueued. 39 | public void Enqueue(IProjector projector, IWorld world, RenderObject renderObject) 40 | { 41 | if ((projector.Groups & renderObject.Groups) != 0) 42 | { 43 | return; 44 | } 45 | 46 | if (!renderObject.Bounds.Equals(BoundingBox.Empty)) 47 | { 48 | if (BoundingFrustum.Contains(projector.Frustum, renderObject.Bounds) == Containment.Disjoint) 49 | { 50 | return; 51 | } 52 | } 53 | 54 | int renderable = renderables.Count; 55 | int materialID = renderObject.Material.GetMaterialID(); 56 | float distance = Vector3.Distance((renderObject.Bounds.Center * world.Scale) + world.Position, projector.Position); 57 | 58 | renderables.Add(new RenderData(projector, world, renderObject)); 59 | renderOrders.Add(new(renderable, materialID, distance)); 60 | } 61 | 62 | /// 63 | /// Clears the queue. 64 | /// 65 | public void Clear() 66 | { 67 | renderables.Clear(); 68 | renderOrders.Clear(); 69 | } 70 | 71 | /// 72 | /// Returns an enumerator that iterates through this queue in order. 73 | /// 74 | /// An that iterates through this queue in order. 75 | public IEnumerator GetEnumerator() 76 | { 77 | renderOrders.Sort(); 78 | return new Enumerator(renderOrders, renderables); 79 | } 80 | 81 | IEnumerator IEnumerable.GetEnumerator() 82 | { 83 | return GetEnumerator(); 84 | } 85 | 86 | private struct Enumerator : IEnumerator 87 | { 88 | public RenderData Current { get; private set; } 89 | 90 | private int index; 91 | private readonly IReadOnlyList renderables; 92 | private readonly IReadOnlyList renderOrders; 93 | 94 | public Enumerator(IReadOnlyList renderOrders, IReadOnlyList renderables) 95 | { 96 | this.renderables = renderables; 97 | this.renderOrders = renderOrders; 98 | } 99 | 100 | public bool MoveNext() 101 | { 102 | if (index >= renderOrders.Count) 103 | { 104 | Current = default; 105 | return false; 106 | } 107 | else 108 | { 109 | Current = renderables[renderOrders[index].Renderable]; 110 | index += 1; 111 | return true; 112 | } 113 | } 114 | 115 | public void Reset() 116 | { 117 | index = 0; 118 | Current = default; 119 | } 120 | 121 | public readonly void Dispose() 122 | { 123 | } 124 | 125 | readonly object IEnumerator.Current => Current; 126 | } 127 | 128 | private readonly struct RenderOrder : IEquatable, IComparable 129 | { 130 | public int Renderable { get; } 131 | public int MaterialID { get; } 132 | public float Distance { get; } 133 | 134 | public RenderOrder(int renderable, int materialID, float distance) 135 | { 136 | Distance = distance; 137 | Renderable = renderable; 138 | MaterialID = materialID; 139 | } 140 | 141 | public readonly int CompareTo(RenderOrder other) 142 | { 143 | if (Equals(other)) 144 | { 145 | return 0; 146 | } 147 | 148 | int value = Distance.CompareTo(other.Distance); 149 | 150 | if (value != 0) 151 | { 152 | return value; 153 | } 154 | 155 | return MaterialID.CompareTo(other.MaterialID); 156 | } 157 | 158 | public readonly bool Equals(RenderOrder other) 159 | { 160 | return Renderable.Equals(other.Renderable) && MaterialID.Equals(other.MaterialID) && Distance.Equals(other.Distance); 161 | } 162 | 163 | public override readonly bool Equals([NotNullWhen(true)] object? obj) 164 | { 165 | return obj is RenderOrder order && Equals(order); 166 | } 167 | 168 | public override readonly int GetHashCode() 169 | { 170 | return HashCode.Combine(Renderable, MaterialID, Distance); 171 | } 172 | 173 | public static bool operator ==(RenderOrder left, RenderOrder right) 174 | { 175 | return left.Equals(right); 176 | } 177 | 178 | public static bool operator !=(RenderOrder left, RenderOrder right) 179 | { 180 | return !(left == right); 181 | } 182 | 183 | public static bool operator <(RenderOrder left, RenderOrder right) 184 | { 185 | return left.CompareTo(right) < 0; 186 | } 187 | 188 | public static bool operator <=(RenderOrder left, RenderOrder right) 189 | { 190 | return left.CompareTo(right) <= 0; 191 | } 192 | 193 | public static bool operator >(RenderOrder left, RenderOrder right) 194 | { 195 | return left.CompareTo(right) > 0; 196 | } 197 | 198 | public static bool operator >=(RenderOrder left, RenderOrder right) 199 | { 200 | return left.CompareTo(right) >= 0; 201 | } 202 | } 203 | } 204 | 205 | internal static class RenderQueueExtensions 206 | { 207 | /// 208 | /// Begins a rendering context. 209 | /// 210 | /// The render queue. 211 | /// The projector used. 212 | /// The model used. 213 | /// A new render context. 214 | internal static RenderContext Begin(this RenderQueue queue, IProjector projector, IWorld world) 215 | { 216 | return new RenderContext(queue, projector, world); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/RenderTarget.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using Sekai.Graphics; 6 | 7 | namespace Vignette.Graphics; 8 | 9 | /// 10 | /// An output target for rendering. 11 | /// 12 | public sealed class RenderTarget : IDisposable 13 | { 14 | /// 15 | /// The render target's width. 16 | /// 17 | public int Width { get; } 18 | 19 | /// 20 | /// The render target's height. 21 | /// 22 | public int Height { get; } 23 | 24 | private bool isDisposed; 25 | private readonly Texture? color; 26 | private readonly Texture? depth; 27 | private readonly Framebuffer framebuffer; 28 | 29 | private RenderTarget(int width, int height, Texture? color, Texture? depth, Framebuffer framebuffer) 30 | { 31 | this.color = color; 32 | this.depth = depth; 33 | this.Width = width; 34 | this.Height = height; 35 | this.framebuffer = framebuffer; 36 | } 37 | 38 | /// 39 | /// Creates a new . 40 | /// 41 | /// The graphics device used in creating the render target. 42 | /// The width of the render target. 43 | /// The height of the render target. 44 | /// The layer count of the render target. 45 | /// The color texture pixel format. 46 | /// The depth texture pixel format. 47 | /// A new . 48 | /// Thrown when is less than or equal to zero. 49 | /// Thrown when both and are . 50 | /// Thrown when either or are passed with an invalid format. 51 | public static RenderTarget Create(GraphicsDevice device, int width, int height, int layers = 1, PixelFormat? colorFormat = null, PixelFormat? depthFormat = null) 52 | { 53 | if (layers <= 0) 54 | { 55 | throw new ArgumentOutOfRangeException(nameof(layers), "Layer count must be greater than zero."); 56 | } 57 | 58 | if (!depthFormat.HasValue && !colorFormat.HasValue) 59 | { 60 | throw new InvalidOperationException("There must be a defined format for either or both the color and depth textures."); 61 | } 62 | 63 | if (colorFormat.HasValue && colorFormat.Value.IsDepthStencil()) 64 | { 65 | throw new ArgumentException("Invalid color format.", nameof(colorFormat)); 66 | } 67 | 68 | if (depthFormat.HasValue && !depthFormat.Value.IsDepthStencil()) 69 | { 70 | throw new ArgumentException("Invalid depth format.", nameof(depthFormat)); 71 | } 72 | 73 | var color = default(Texture); 74 | var depth = default(Texture); 75 | 76 | FramebufferAttachment? depthAttachment = null; 77 | FramebufferAttachment[] colorAttachments; 78 | 79 | if (colorFormat.HasValue) 80 | { 81 | color = device.CreateTexture(new TextureDescription 82 | ( 83 | TextureType.Texture2D, 84 | width, 85 | height, 86 | 1, 87 | colorFormat.Value, 88 | 1, 89 | layers, 90 | TextureUsage.RenderTarget | TextureUsage.Resource 91 | )); 92 | 93 | colorAttachments = new FramebufferAttachment[layers]; 94 | 95 | for (int i = 0; i < layers; i++) 96 | { 97 | colorAttachments[i] = new FramebufferAttachment(color, i, 0); 98 | } 99 | } 100 | else 101 | { 102 | colorAttachments = Array.Empty(); 103 | } 104 | 105 | if (depthFormat.HasValue) 106 | { 107 | depth = device.CreateTexture(new TextureDescription 108 | ( 109 | TextureType.Texture2D, 110 | width, 111 | height, 112 | 1, 113 | depthFormat.Value, 114 | 1, 115 | 1, 116 | TextureUsage.RenderTarget | TextureUsage.Resource 117 | )); 118 | 119 | depthAttachment = new FramebufferAttachment(depth, 0, 0); 120 | } 121 | 122 | return new RenderTarget(width, height, color, depth, device.CreateFramebuffer(depthAttachment, colorAttachments)); 123 | } 124 | 125 | public void Dispose() 126 | { 127 | if (isDisposed) 128 | { 129 | return; 130 | } 131 | 132 | color?.Dispose(); 133 | depth?.Dispose(); 134 | framebuffer.Dispose(); 135 | 136 | isDisposed = true; 137 | } 138 | 139 | public static explicit operator Framebuffer(RenderTarget target) => target.framebuffer; 140 | } 141 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/Renderer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Numerics; 8 | using Sekai.Graphics; 9 | using Sekai.Mathematics; 10 | 11 | namespace Vignette.Graphics; 12 | 13 | public sealed class Renderer 14 | { 15 | /// 16 | /// A white pixel texture. 17 | /// 18 | public Texture WhitePixel { get; } 19 | 20 | /// 21 | /// A point sampler. 22 | /// 23 | public Sampler SamplerPoint { get; } 24 | 25 | /// 26 | /// A linear sampler. 27 | /// 28 | public Sampler SamplerLinear { get; } 29 | 30 | /// 31 | /// A 4x anisotropic sampler. 32 | /// 33 | public Sampler SamplerAniso4x { get; } 34 | 35 | private readonly GraphicsBuffer ubo; 36 | private readonly GraphicsDevice device; 37 | private readonly Dictionary caches = new(); 38 | 39 | internal Renderer(GraphicsDevice device) 40 | { 41 | ubo = device.CreateBuffer(BufferType.Uniform, 3, true); 42 | 43 | Span whitePixel = stackalloc byte[] { 255, 255, 255, 255 }; 44 | 45 | WhitePixel = device.CreateTexture(new(1, 1, PixelFormat.R8G8B8A8_UNorm, 1, 1, TextureUsage.Resource)); 46 | WhitePixel.SetData((ReadOnlySpan)whitePixel, 0, 0, 0, 0, 0, 1, 1, 0); 47 | 48 | SamplerPoint = device.CreateSampler(new(TextureFilter.MinMagMipPoint, TextureAddress.Repeat, TextureAddress.Repeat, TextureAddress.Repeat, 0, Color.White, 0, 0, 0)); 49 | SamplerLinear = device.CreateSampler(new(TextureFilter.MinMagMipLinear, TextureAddress.Repeat, TextureAddress.Repeat, TextureAddress.Repeat, 0, Color.White, 0, 0, 0)); 50 | SamplerAniso4x = device.CreateSampler(new(TextureFilter.Anisotropic, TextureAddress.Repeat, TextureAddress.Repeat, TextureAddress.Repeat, 4, Color.White, 0, 0, 0)); 51 | 52 | this.device = device; 53 | } 54 | 55 | /// 56 | /// Draws a single to . 57 | /// 58 | /// The renderable to draw. 59 | /// The target to draw to. A value of to draw to the backbuffer. 60 | public void Draw(RenderData renderable, RenderTarget? target = null) 61 | { 62 | Draw(new[] { renderable }, target); 63 | } 64 | 65 | /// 66 | /// Draws to . 67 | /// 68 | /// The renderables to draw. 69 | /// The target to draw to. A value of to draw to the backbuffer. 70 | public void Draw(IEnumerable renderables, RenderTarget? target = null) 71 | { 72 | var currentLayout = default(InputLayout); 73 | int currentMaterialID = -1; 74 | 75 | foreach (var data in renderables) 76 | { 77 | using (var mvp = ubo.Map(MapMode.Write)) 78 | { 79 | mvp[0] = data.Projector.ProjMatrix; 80 | mvp[1] = data.Projector.ViewMatrix; 81 | mvp[2] = data.World.WorldMatrix; 82 | } 83 | 84 | device.SetUniformBuffer(ubo, Effect.GLOBAL_TRANSFORM_ID); 85 | 86 | if (target is not null) 87 | { 88 | device.SetFramebuffer((Framebuffer)target); 89 | } 90 | else 91 | { 92 | device.SetFramebuffer(null); 93 | } 94 | 95 | draw(data.Renderable, ref currentMaterialID, ref currentLayout!); 96 | } 97 | } 98 | 99 | private void draw(RenderObject renderObject, ref int currentMaterialID, ref InputLayout currentLayout) 100 | { 101 | if (renderObject.IndexCount <= 0 || renderObject.VertexBuffer is null || renderObject.IndexBuffer is null) 102 | { 103 | return; 104 | } 105 | 106 | int materialID = renderObject.Material.GetMaterialID(); 107 | 108 | if (currentMaterialID != materialID) 109 | { 110 | apply(renderObject.Material, ref currentLayout); 111 | currentMaterialID = materialID; 112 | } 113 | 114 | foreach (var property in renderObject.Material.Properties) 115 | { 116 | if (property is UniformProperty uniform) 117 | { 118 | if (uniform.Uniform is not null) 119 | { 120 | device.SetUniformBuffer(uniform.Uniform, (uint)uniform.Slot); 121 | } 122 | } 123 | 124 | if (property is TextureProperty texture) 125 | { 126 | device.SetTexture(texture.Texture ?? WhitePixel, texture.Sampler ?? SamplerPoint, (uint)texture.Slot); 127 | } 128 | } 129 | 130 | device.SetVertexBuffer(renderObject.VertexBuffer, currentLayout); 131 | device.SetIndexBuffer(renderObject.IndexBuffer, renderObject.IndexType); 132 | device.DrawIndexed(renderObject.Material.Primitives, (uint)renderObject.IndexCount); 133 | } 134 | 135 | private void apply(IMaterial material, ref InputLayout layout) 136 | { 137 | var blendCache = getCache(); 138 | 139 | if (!blendCache.TryGetValue(material.Blend, out var blendState)) 140 | { 141 | blendState = device.CreateBlendState(material.Blend); 142 | blendCache.Add(material.Blend, blendState); 143 | } 144 | 145 | device.SetBlendState(blendState); 146 | 147 | var shaderCache = getCache(); 148 | 149 | if (!shaderCache.TryGetValue(material.Effect, out var shader)) 150 | { 151 | shader = device.CreateShader((ShaderCode[])material.Effect); 152 | shaderCache.Add(material.Effect, shader); 153 | } 154 | 155 | device.SetShader(shader); 156 | 157 | var layoutCache = getCache(); 158 | 159 | if (!layoutCache.TryGetValue(material.Layout, out var layoutState)) 160 | { 161 | layoutState = device.CreateInputLayout(material.Layout); 162 | layoutCache.Add(material.Layout, layoutState); 163 | } 164 | 165 | layout = layoutState; 166 | 167 | var rasterizerCache = getCache(); 168 | 169 | if (!rasterizerCache.TryGetValue(material.Rasterizer, out var rasterizerState)) 170 | { 171 | rasterizerState = device.CreateRasterizerState(material.Rasterizer); 172 | rasterizerCache.Add(material.Rasterizer, rasterizerState); 173 | } 174 | 175 | device.SetRasterizerState(rasterizerState); 176 | 177 | var depthStencilCache = getCache(); 178 | 179 | if (!depthStencilCache.TryGetValue(material.DepthStencil, out var depthStencilState)) 180 | { 181 | depthStencilState = device.CreateDepthStencilState(material.DepthStencil); 182 | depthStencilCache.Add(material.DepthStencil, depthStencilState); 183 | } 184 | 185 | device.SetDepthStencilState(depthStencilState, material.Stencil); 186 | } 187 | 188 | private IDictionary getCache() 189 | where T : struct, IEquatable 190 | where U : notnull 191 | { 192 | if (!caches.TryGetValue(typeof(T), out var cache)) 193 | { 194 | cache = new Dictionary(); 195 | caches.Add(typeof(T), cache); 196 | } 197 | 198 | return (IDictionary)cache; 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/ShaderMaterial.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Sekai.Graphics; 8 | 9 | namespace Vignette.Graphics; 10 | 11 | /// 12 | /// A composable material that created from shader code. 13 | /// 14 | public sealed class ShaderMaterial : IMaterial, ICloneable 15 | { 16 | private int stencil; 17 | private PrimitiveType primitives; 18 | private BlendStateDescription blend; 19 | private RasterizerStateDescription rasterizer; 20 | private DepthStencilStateDescription depthStencil; 21 | private readonly Effect effect; 22 | private readonly InputLayoutDescription layout; 23 | private readonly IProperty[] properties; 24 | 25 | private ShaderMaterial(InputLayoutDescription layout, Effect effect, IProperty[] properties) 26 | { 27 | this.layout = layout; 28 | this.effect = effect; 29 | this.properties = properties; 30 | } 31 | 32 | private ShaderMaterial(PrimitiveType primitives, BlendStateDescription blend, RasterizerStateDescription rasterizer, DepthStencilStateDescription depthStencil, InputLayoutDescription layout, Effect effect, IProperty[] properties) 33 | { 34 | this.blend = blend; 35 | this.layout = layout; 36 | this.effect = effect; 37 | this.properties = properties; 38 | this.primitives = primitives; 39 | this.rasterizer = rasterizer; 40 | this.depthStencil = depthStencil; 41 | } 42 | 43 | /// 44 | /// Sets the primitive type for this . 45 | /// 46 | /// The primitive type. 47 | public ShaderMaterial SetPrimitives(PrimitiveType primitives) 48 | { 49 | this.primitives = primitives; 50 | return this; 51 | } 52 | 53 | /// 54 | /// Sets the face culling mode for this . 55 | /// 56 | /// The face culling mode. 57 | public ShaderMaterial SetFaceCulling(FaceCulling culling) 58 | { 59 | rasterizer.Culling = culling; 60 | return this; 61 | } 62 | 63 | /// 64 | /// Sets the face winding mode for this . 65 | /// 66 | /// The face winding mode. 67 | public ShaderMaterial SetFaceWinding(FaceWinding winding) 68 | { 69 | rasterizer.Winding = winding; 70 | return this; 71 | } 72 | 73 | /// 74 | /// Sets the polygon fill mode for this . 75 | /// 76 | /// The polygon fill mode. 77 | public ShaderMaterial SetFillMode(FillMode mode) 78 | { 79 | rasterizer.Mode = mode; 80 | return this; 81 | } 82 | 83 | /// 84 | /// Sets custom stencil parameters for this . 85 | /// 86 | /// The stencil reference. 87 | /// The operation performed for the passing front face stencil test. 88 | /// The operation performed for the failing front face stencil test. 89 | /// The operation performed for the failing front face depth test. 90 | /// The comparison performed for the front face. 91 | /// The operation performed for the passing back face stencil test. 92 | /// The operation performed for the failing back face stencil test. 93 | /// The operation performed for the failing back face depth test. 94 | /// The comparison performed for the back face. 95 | public ShaderMaterial SetStencil(int reference, StencilOperation frontStencilPass, StencilOperation frontStencilFail, StencilOperation frontDepthFail, ComparisonKind frontComparison, StencilOperation backStencilPass, StencilOperation backStencilFail, StencilOperation backDepthFail, ComparisonKind backComparison) 96 | { 97 | stencil = reference; 98 | depthStencil.Front.StencilPass = frontStencilPass; 99 | depthStencil.Front.StencilFail = frontStencilFail; 100 | depthStencil.Front.DepthFail = frontDepthFail; 101 | depthStencil.Front.Comparison = frontComparison; 102 | depthStencil.Back.StencilPass = backStencilPass; 103 | depthStencil.Back.StencilFail = backStencilFail; 104 | depthStencil.Back.DepthFail = backDepthFail; 105 | depthStencil.Back.Comparison = backComparison; 106 | return this; 107 | } 108 | 109 | /// 110 | /// Sets custom stencil parameters for both the front and back faces for this . 111 | /// 112 | /// The stencil reference. 113 | /// The operation performed for passing the stencil test. 114 | /// The operation performed for failing the stencil test. 115 | /// The operation performed for failing the depth test. 116 | /// The comparison performed. 117 | public ShaderMaterial SetStencil(int reference, StencilOperation pass, StencilOperation fail, StencilOperation depthFail, ComparisonKind comparison) 118 | { 119 | return SetStencil(reference, pass, fail, depthFail, comparison, pass, fail, depthFail, comparison); 120 | } 121 | 122 | /// 123 | /// Sets custom blending parameters for this . 124 | /// 125 | /// Whether to enable or disable blending. 126 | /// The source color blending. 127 | /// The source alpha blending. 128 | /// The destination color blending. 129 | /// The destination alpha blending. 130 | /// The operation performed between and . 131 | /// The operation performed between and . 132 | public ShaderMaterial SetBlend(bool enabled, BlendType srcColor, BlendType srcAlpha, BlendType dstColor, BlendType dstAlpha, BlendOperation colorOperation, BlendOperation alphaOperation) 133 | { 134 | blend.Enabled = enabled; 135 | blend.SourceColor = srcColor; 136 | blend.SourceAlpha = srcAlpha; 137 | blend.DestinationColor = dstColor; 138 | blend.DestinationAlpha = dstAlpha; 139 | blend.ColorOperation = colorOperation; 140 | blend.AlphaOperation = alphaOperation; 141 | return this; 142 | } 143 | 144 | /// 145 | /// Sets individual blending parameters for this . 146 | /// 147 | /// The source color blending. 148 | /// The source alpha blending. 149 | /// The destination color blending. 150 | /// The destination alpha blending. 151 | public ShaderMaterial SetBlend(BlendType srcColor, BlendType srcAlpha, BlendType dstColor, BlendType dstAlpha) 152 | { 153 | return SetBlend(true, srcColor, srcAlpha, dstColor, dstAlpha, BlendOperation.Add, BlendOperation.Add); 154 | } 155 | 156 | /// 157 | /// Sets blending parameters for the source and destination colors for this . 158 | /// 159 | /// The source blending. 160 | /// The destination blending. 161 | public ShaderMaterial SetBlend(BlendType source, BlendType destination) 162 | { 163 | return SetBlend(source, source, destination, destination); 164 | } 165 | 166 | /// 167 | /// Sets the color write mask. 168 | /// 169 | /// The color write mask. 170 | public ShaderMaterial SetColorMask(ColorWriteMask mask) 171 | { 172 | blend.WriteMask = mask; 173 | return this; 174 | } 175 | 176 | /// 177 | /// Sets a for this . 178 | /// 179 | /// The property name. 180 | /// The to set. Setting will use the default texture. 181 | /// The to set. Setting will use the default sampler. 182 | /// Thrown when the is not usable as a resource. 183 | public ShaderMaterial SetProperty(string name, Texture? texture = null, Sampler? sampler = null) 184 | { 185 | var prop = getProperty(name); 186 | 187 | if (texture is not null && (texture.Usage & TextureUsage.Resource) == 0) 188 | { 189 | throw new ArgumentException($"The texture must have the {nameof(TextureUsage.Resource)} flag to be used on materials.", nameof(texture)); 190 | } 191 | 192 | prop.Texture = texture; 193 | prop.Sampler = sampler; 194 | 195 | return this; 196 | } 197 | 198 | /// 199 | /// Sets a for this . 200 | /// 201 | /// The property name. 202 | /// The to set. Setting will not bind this property during rendering. 203 | /// Thrown when the is not usable as a uniform. 204 | public ShaderMaterial SetProperty(string name, GraphicsBuffer? buffer = null) 205 | { 206 | var prop = getProperty(name); 207 | 208 | if (buffer is not null && buffer.Type is not BufferType.Uniform) 209 | { 210 | throw new ArgumentException($"The buffer must be a {nameof(BufferType.Uniform)} to be used on materials.", nameof(buffer)); 211 | } 212 | 213 | prop.Uniform = buffer; 214 | 215 | return this; 216 | } 217 | 218 | /// 219 | /// Gets whether a property exists. 220 | /// 221 | /// The property name. 222 | /// if the property exists or if it does not. 223 | public bool HasProperty(string name) 224 | { 225 | foreach (var prop in properties) 226 | { 227 | if (prop.Name == name) 228 | { 229 | return true; 230 | } 231 | } 232 | 233 | return false; 234 | } 235 | 236 | /// 237 | /// Creates a shallow copy of this . 238 | /// 239 | /// A new . 240 | public ShaderMaterial Clone() => new 241 | ( 242 | primitives, 243 | blend, 244 | rasterizer, 245 | depthStencil, 246 | layout, 247 | effect, 248 | properties.ToArray() 249 | ); 250 | 251 | private T getProperty(string name) 252 | where T : IProperty 253 | { 254 | var prop = default(IProperty); 255 | 256 | foreach (var p in properties) 257 | { 258 | if (p.Name == name) 259 | { 260 | prop = p; 261 | break; 262 | } 263 | } 264 | 265 | if (prop is null) 266 | { 267 | throw new KeyNotFoundException($"There is no property named \"{name}\" on this material."); 268 | } 269 | 270 | if (prop is not T typedProp) 271 | { 272 | throw new InvalidCastException($"Property \"{name}\" is not compatible with the type {typeof(T)}."); 273 | } 274 | 275 | return typedProp; 276 | } 277 | 278 | int IMaterial.Stencil => stencil; 279 | Effect IMaterial.Effect => effect; 280 | PrimitiveType IMaterial.Primitives => primitives; 281 | InputLayoutDescription IMaterial.Layout => layout; 282 | BlendStateDescription IMaterial.Blend => blend; 283 | RasterizerStateDescription IMaterial.Rasterizer => rasterizer; 284 | DepthStencilStateDescription IMaterial.DepthStencil => depthStencil; 285 | IEnumerable IMaterial.Properties => properties; 286 | object ICloneable.Clone() => Clone(); 287 | 288 | /// 289 | /// Creates a new from HLSL shader code. 290 | /// 291 | /// The shader code to use. 292 | /// A new . 293 | public static ShaderMaterial Create(string code) 294 | { 295 | var effect = Effect.From(code, out var layout, out var properties); 296 | return new(layout, effect, properties); 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /source/Vignette/Graphics/UnlitMaterial.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using Sekai.Graphics; 7 | 8 | namespace Vignette.Graphics; 9 | 10 | /// 11 | /// A material that is unlit. 12 | /// 13 | public sealed class UnlitMaterial : IMaterial 14 | { 15 | /// 16 | /// The default unlit material. 17 | /// 18 | public static readonly IMaterial Default = new UnlitMaterial(true); 19 | 20 | /// 21 | /// The material's texture. 22 | /// 23 | public Texture? Texture 24 | { 25 | get => ((TextureProperty)properties[0]).Texture; 26 | set 27 | { 28 | if (isDefault) 29 | { 30 | throw new InvalidOperationException("Cannot modify the default instance."); 31 | } 32 | 33 | var texture = (TextureProperty)properties[0]; 34 | texture.Texture = value; 35 | } 36 | } 37 | 38 | /// 39 | /// The material's sampler. 40 | /// 41 | public Sampler? Sampler 42 | { 43 | get => ((TextureProperty)properties[0]).Sampler; 44 | set 45 | { 46 | if (isDefault) 47 | { 48 | throw new InvalidOperationException("Cannot modify the default instance."); 49 | } 50 | 51 | var texture = (TextureProperty)properties[0]; 52 | texture.Sampler = value; 53 | } 54 | } 55 | 56 | /// 57 | /// The material's primitive type. 58 | /// 59 | public PrimitiveType Primitives { get; set; } = PrimitiveType.TriangleList; 60 | 61 | private readonly bool isDefault; 62 | private readonly Effect effect; 63 | private readonly IProperty[] properties; 64 | private readonly InputLayoutDescription layout; 65 | private readonly RasterizerStateDescription rasterizer; 66 | private readonly DepthStencilStateDescription depthStencil; 67 | 68 | public UnlitMaterial() 69 | : this(false) 70 | { 71 | } 72 | 73 | public UnlitMaterial(Texture texture) 74 | : this(false) 75 | { 76 | Texture = texture; 77 | } 78 | 79 | public UnlitMaterial(Texture texture, Sampler sampler) 80 | : this(false) 81 | { 82 | Texture = texture; 83 | Sampler = sampler; 84 | } 85 | 86 | private UnlitMaterial(bool isDefault) 87 | { 88 | effect = Effect.From(shader, out layout, out properties); 89 | 90 | rasterizer = new RasterizerStateDescription 91 | ( 92 | FaceCulling.None, 93 | FaceWinding.CounterClockwise, 94 | FillMode.Solid, 95 | false 96 | ); 97 | 98 | depthStencil = new DepthStencilStateDescription 99 | ( 100 | false, 101 | false, 102 | ComparisonKind.Always 103 | ); 104 | 105 | this.isDefault = isDefault; 106 | } 107 | 108 | int IMaterial.Stencil => 0; 109 | Effect IMaterial.Effect => effect; 110 | InputLayoutDescription IMaterial.Layout => layout; 111 | BlendStateDescription IMaterial.Blend => BlendStateDescription.NonPremultiplied; 112 | RasterizerStateDescription IMaterial.Rasterizer => rasterizer; 113 | DepthStencilStateDescription IMaterial.DepthStencil => depthStencil; 114 | IEnumerable IMaterial.Properties => properties; 115 | 116 | private const string shader = 117 | @" 118 | struct VSInput 119 | { 120 | float3 Position : POSITION; 121 | float2 TexCoord : TEXCOORD; 122 | float4 Color : COLOR; 123 | }; 124 | 125 | struct PSInput 126 | { 127 | float4 Position : SV_POSITION; 128 | float2 TexCoord : TEXCOORD; 129 | float4 Color : COLOR; 130 | }; 131 | 132 | Texture2D AlbedoTexture : register(t0); 133 | SamplerState AlbedoSampler : register(s0); 134 | 135 | PSInput Vertex(in VSInput input) 136 | { 137 | PSInput output; 138 | 139 | output.Color = input.Color; 140 | output.Position = OBJECT_TO_VIEW(float4(input.Position, 1.0)); 141 | output.TexCoord = input.TexCoord; 142 | 143 | return output; 144 | } 145 | 146 | float4 Pixel(in PSInput input) : SV_TARGET 147 | { 148 | return AlbedoTexture.Sample(AlbedoSampler, input.TexCoord) * input.Color; 149 | } 150 | "; 151 | } 152 | -------------------------------------------------------------------------------- /source/Vignette/Light.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System.Numerics; 5 | using Sekai.Mathematics; 6 | using Vignette.Graphics; 7 | 8 | namespace Vignette; 9 | 10 | /// 11 | /// Represents a light source. 12 | /// 13 | public abstract class Light : Node, IProjector 14 | { 15 | /// 16 | /// The light source's view matrix. 17 | /// 18 | protected abstract Matrix4x4 ViewMatrix { get; } 19 | 20 | /// 21 | /// The light source's projection matrix. 22 | /// 23 | protected abstract Matrix4x4 ProjMatrix { get; } 24 | 25 | /// 26 | /// The light source's bounding frustum. 27 | /// 28 | public BoundingFrustum Frustum => BoundingFrustum.FromMatrix(ProjMatrix); 29 | 30 | Matrix4x4 IProjector.ViewMatrix => ViewMatrix; 31 | Matrix4x4 IProjector.ProjMatrix => ProjMatrix; 32 | RenderGroup IProjector.Groups => RenderGroup.Default; 33 | } 34 | -------------------------------------------------------------------------------- /source/Vignette/Node.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Collections.Specialized; 8 | using System.Diagnostics.CodeAnalysis; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Numerics; 12 | using Vignette.Graphics; 13 | 14 | namespace Vignette; 15 | 16 | /// 17 | /// The base class of everything that resides inside the node graph. It can be a child of 18 | /// another and can contain its own children s. 19 | /// 20 | public class Node : IWorld, INotifyCollectionChanged, ICollection, IEquatable 21 | { 22 | /// 23 | /// The 's unique identifier. 24 | /// 25 | public Guid Id { get; } 26 | 27 | /// 28 | /// The 's name. 29 | /// 30 | public string Name { get; } 31 | 32 | /// 33 | /// The depth of this relative to the root. 34 | /// 35 | public int Depth { get; private set; } 36 | 37 | /// 38 | /// The number of children this contains. 39 | /// 40 | public int Count => nodes.Count; 41 | 42 | /// 43 | /// The 's services. 44 | /// 45 | public virtual IServiceLocator Services => Parent is not null ? Parent.Services : throw new InvalidOperationException("Services are unavailable"); 46 | 47 | /// 48 | /// The parent . 49 | /// 50 | public Node? Parent { get; private set; } 51 | 52 | /// 53 | /// The node's position. 54 | /// 55 | public Vector3 Position { get; set; } 56 | 57 | /// 58 | /// The node's rotation. 59 | /// 60 | public Vector3 Rotation { get; set; } 61 | 62 | /// 63 | /// The node's scaling. 64 | /// 65 | public Vector3 Scale { get; set; } = Vector3.One; 66 | 67 | /// 68 | /// The node's shearing. 69 | /// 70 | public Vector3 Shear 71 | { 72 | get => new(shear[0, 1], shear[0, 2], shear[1, 2]); 73 | set 74 | { 75 | shear[0, 1] = value.X; 76 | shear[0, 2] = value.Y; 77 | shear[1, 2] = value.Z; 78 | } 79 | } 80 | 81 | /// 82 | /// The node's local matrix. 83 | /// 84 | protected virtual Matrix4x4 LocalMatrix => shear * Matrix4x4.CreateScale(Scale) * Matrix4x4.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * Matrix4x4.CreateTranslation(Position); 85 | 86 | /// 87 | /// The node's world matrix. 88 | /// 89 | protected virtual Matrix4x4 WorldMatrix => Parent is not IWorld provider ? LocalMatrix : provider.LocalMatrix * LocalMatrix; 90 | 91 | /// 92 | /// Called when the 's children has been changed. 93 | /// 94 | public event NotifyCollectionChangedEventHandler? CollectionChanged; 95 | 96 | private Matrix4x4 shear = Matrix4x4.Identity; 97 | private readonly Dictionary nodes = new(); 98 | 99 | /// 100 | /// Creates a new . 101 | /// 102 | /// The optional name for this . 103 | public Node(string? name = null) 104 | : this(Guid.NewGuid(), name) 105 | { 106 | } 107 | 108 | private Node(Guid id, string? name = null) 109 | { 110 | Id = id; 111 | Name = name ?? id.ToString(); 112 | } 113 | 114 | /// 115 | /// Called when the has entered the node graph. 116 | /// 117 | protected virtual void Enter() 118 | { 119 | } 120 | 121 | /// 122 | /// Called when the is leaving the node graph. 123 | /// 124 | protected virtual void Leave() 125 | { 126 | } 127 | 128 | /// 129 | /// Adds a child . 130 | /// 131 | /// The to add. 132 | public void Add(Node node) 133 | { 134 | add(node); 135 | raiseCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, node)); 136 | } 137 | 138 | /// 139 | /// Adds a range of children. 140 | /// 141 | /// The children to add. 142 | public void AddRange(IEnumerable nodes) 143 | { 144 | foreach (var node in nodes) 145 | { 146 | add(node); 147 | } 148 | 149 | raiseCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, nodes.ToArray())); 150 | } 151 | 152 | /// 153 | /// Removes a child . 154 | /// 155 | /// The to remove. 156 | /// if the has been removed. Otherwise, returns . 157 | public bool Remove(Node node) 158 | { 159 | if (!remove(node)) 160 | { 161 | return false; 162 | } 163 | 164 | raiseCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, node)); 165 | 166 | return true; 167 | } 168 | 169 | /// 170 | /// Removes a range of children based on a given . 171 | /// 172 | /// The predicate used to select the children. 173 | /// The number of removed children. 174 | public int RemoveRange(Predicate predicate) 175 | { 176 | var selected = nodes.Values.Where(n => predicate(n)).ToArray(); 177 | 178 | foreach (var node in selected) 179 | { 180 | remove(node); 181 | } 182 | 183 | raiseCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, selected)); 184 | 185 | return selected.Length; 186 | } 187 | 188 | /// 189 | /// Removes a range of children. 190 | /// 191 | /// The children to remove. 192 | /// The number of removed children. 193 | public int RemoveRange(IEnumerable nodes) 194 | { 195 | var removed = new List(); 196 | 197 | foreach (var node in nodes) 198 | { 199 | if (remove(node)) 200 | { 201 | removed.Add(node); 202 | } 203 | } 204 | 205 | raiseCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removed)); 206 | 207 | return removed.Count; 208 | } 209 | 210 | /// 211 | /// Removes all children from this . 212 | /// 213 | public void Clear() 214 | { 215 | var copy = nodes.Values.ToArray(); 216 | 217 | foreach (var node in copy) 218 | { 219 | remove(node); 220 | } 221 | 222 | raiseCollectionChanged(reset_args); 223 | } 224 | 225 | /// 226 | /// Determines whether a given is a child of this node. 227 | /// 228 | /// The node to test. 229 | /// if the is a child of this node or if not. 230 | public bool Contains(Node node) 231 | { 232 | return nodes.ContainsValue(node); 233 | } 234 | 235 | /// 236 | /// Gets the root node. 237 | /// 238 | /// The root node. 239 | public Node GetRoot() 240 | { 241 | var current = this; 242 | 243 | while (current.Parent is not null) 244 | { 245 | current = current.Parent; 246 | } 247 | 248 | return current; 249 | } 250 | 251 | /// 252 | /// Gets the nearest node. 253 | /// 254 | /// The node type to search for. 255 | /// The nearest node. 256 | public T? GetNearest() 257 | where T : Node 258 | { 259 | var current = this; 260 | 261 | while (current.Parent is not null) 262 | { 263 | current = current.Parent; 264 | 265 | if (current is T) 266 | { 267 | break; 268 | } 269 | } 270 | 271 | return current as T; 272 | } 273 | 274 | /// 275 | /// Gets the node from the given path. 276 | /// 277 | /// The relative or absolute path. 278 | /// The node on the given path. 279 | /// Thrown when is invalid. 280 | /// Thrown when a part of the path is not found. 281 | public Node GetNode(string path) 282 | { 283 | if (!Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var uri)) 284 | { 285 | throw new ArgumentException("Provided path is not a URI.", nameof(path)); 286 | } 287 | 288 | if (uri.IsAbsoluteUri && uri.Scheme != node_scheme) 289 | { 290 | throw new ArgumentException("Absolute paths must start with the node scheme.", nameof(path)); 291 | } 292 | 293 | var current = uri.IsAbsoluteUri ? GetRoot() : this; 294 | string[] cm = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped).Split(Path.AltDirectorySeparatorChar, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); 295 | 296 | foreach (string part in cm) 297 | { 298 | if (!current.nodes.ContainsKey(part)) 299 | { 300 | throw new KeyNotFoundException($"The node \"{part}\" was not found."); 301 | } 302 | 303 | current = current.nodes[part]; 304 | } 305 | 306 | return current; 307 | } 308 | 309 | /// 310 | /// Gets the node from the given path. 311 | /// 312 | /// The type to cast the node as. 313 | /// The relative or absolute path. 314 | /// The node on the given path. 315 | /// Thrown when the returned node cannot be casted to . 316 | public T GetNode(string path) 317 | where T : Node 318 | { 319 | var node = GetNode(path); 320 | 321 | if (node is not T typed) 322 | { 323 | throw new InvalidCastException($"Cannot cast {typeof(T)} to the found node."); 324 | } 325 | 326 | return (T)node; 327 | } 328 | 329 | /// 330 | /// Gets an enumeration of the nodes of type . 331 | /// 332 | /// The type to filter the enumeration. 333 | /// An enumerable of nodes of type . 334 | public IEnumerable GetNodes() 335 | where T : Node 336 | { 337 | return this.OfType(); 338 | } 339 | 340 | public IEnumerator GetEnumerator() 341 | { 342 | return nodes.Values.GetEnumerator(); 343 | } 344 | 345 | public bool Equals(Node? node) 346 | { 347 | if (node is null) 348 | { 349 | return false; 350 | } 351 | 352 | if (node.Id.Equals(Id)) 353 | { 354 | return true; 355 | } 356 | 357 | if (ReferenceEquals(this, node)) 358 | { 359 | return true; 360 | } 361 | 362 | return false; 363 | } 364 | 365 | public override bool Equals([NotNullWhen(true)] object? obj) 366 | { 367 | return obj is Node node && Equals(node); 368 | } 369 | 370 | public override int GetHashCode() 371 | { 372 | return HashCode.Combine(Id); 373 | } 374 | 375 | private void raiseCollectionChanged(NotifyCollectionChangedEventArgs args) 376 | { 377 | CollectionChanged?.Invoke(this, args); 378 | } 379 | 380 | private void add(Node node) 381 | { 382 | if (Equals(node)) 383 | { 384 | throw new ArgumentException("Cannot add self as a child.", nameof(node)); 385 | } 386 | 387 | if (node.Parent is not null) 388 | { 389 | throw new ArgumentException("Cannot add a node that already has a parent.", nameof(node)); 390 | } 391 | 392 | if (nodes.ContainsKey(node.Name)) 393 | { 394 | throw new ArgumentException($"There is already a child with the name \"{node.Name}\".", nameof(node)); 395 | } 396 | 397 | node.Depth = Depth + 1; 398 | node.Parent = this; 399 | 400 | nodes.Add(node.Name, node); 401 | 402 | node.Enter(); 403 | } 404 | 405 | private bool remove(Node node) 406 | { 407 | if (!nodes.ContainsKey(node.Name)) 408 | { 409 | return false; 410 | } 411 | 412 | node.Leave(); 413 | 414 | node.Depth = 0; 415 | node.Parent = null; 416 | 417 | nodes.Remove(node.Name); 418 | 419 | return true; 420 | } 421 | 422 | void ICollection.CopyTo(Node[] array, int arrayIndex) 423 | { 424 | nodes.Values.CopyTo(array, arrayIndex); 425 | } 426 | 427 | IEnumerator IEnumerable.GetEnumerator() 428 | { 429 | return GetEnumerator(); 430 | } 431 | 432 | bool ICollection.IsReadOnly => false; 433 | Matrix4x4 IWorld.LocalMatrix => LocalMatrix; 434 | Matrix4x4 IWorld.WorldMatrix => WorldMatrix; 435 | 436 | private const string node_scheme = "node"; 437 | private static readonly NotifyCollectionChangedEventArgs reset_args = new(NotifyCollectionChangedAction.Reset); 438 | } 439 | -------------------------------------------------------------------------------- /source/Vignette/ServiceLocator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics.CodeAnalysis; 7 | using System.Runtime.CompilerServices; 8 | 9 | namespace Vignette; 10 | 11 | /// 12 | /// A collection of services. 13 | /// 14 | public sealed class ServiceLocator : IServiceLocator, IServiceProvider 15 | { 16 | private readonly Dictionary services = new(); 17 | 18 | /// 19 | /// Adds a service to this locator. 20 | /// 21 | /// The type of service. 22 | /// The service instance. 23 | /// Thrown when is already added to this locator. 24 | /// Thrown when cannot be assigned to . 25 | public void Add(Type type, object instance) 26 | { 27 | if (services.ContainsKey(type)) 28 | { 29 | throw new ArgumentException($"{type} already exists in this locator.", nameof(type)); 30 | } 31 | 32 | if (!instance.GetType().IsAssignableTo(type)) 33 | { 34 | throw new InvalidCastException($"The {nameof(instance)} cannot be casted to {type}."); 35 | } 36 | 37 | services.Add(type, instance); 38 | } 39 | 40 | /// 41 | /// Adds a service to this locator. 42 | /// 43 | /// The service instance. 44 | /// The type of service. 45 | /// Thrown when is already added to this locator. 46 | /// Thrown when cannot be assigned to . 47 | public void Add(T instance) 48 | where T : class 49 | { 50 | Add(typeof(T), instance); 51 | } 52 | 53 | /// 54 | /// Removes a service from this locator. 55 | /// 56 | /// The service type to remove. 57 | /// true when the service is removed. false otherwise. 58 | public bool Remove(Type type) 59 | { 60 | return services.Remove(type); 61 | } 62 | 63 | /// 64 | /// Removes a service from this locator. 65 | /// 66 | /// The service type to remove. 67 | /// true when the service is removed. false otherwise. 68 | public bool Remove() 69 | where T : class 70 | { 71 | return Remove(typeof(T)); 72 | } 73 | 74 | public object? Get(Type type, [DoesNotReturnIf(true)] bool required = true) 75 | { 76 | if (!services.TryGetValue(type, out object? instance) && required) 77 | { 78 | throw new ServiceNotFoundException(type); 79 | } 80 | 81 | return instance; 82 | } 83 | 84 | public T? Get([DoesNotReturnIf(true)] bool required = true) 85 | where T : class 86 | { 87 | return Unsafe.As(Get(typeof(T), required)); 88 | } 89 | 90 | object? IServiceProvider.GetService(Type type) => Get(type, false); 91 | } 92 | 93 | /// 94 | /// An interface for objects capable of locating services. 95 | /// 96 | public interface IServiceLocator 97 | { 98 | /// 99 | /// Gets the service of a given type. 100 | /// 101 | /// The object type to resolve. 102 | /// Whether the service is required or not. 103 | /// The service object of the given type or when is false and the service is not found. 104 | /// Thrown when is true and the service is not found. 105 | object? Get(Type type, [DoesNotReturnIf(true)] bool required = true); 106 | 107 | /// 108 | /// Gets the service of a given type. 109 | /// 110 | /// The object type to resolve. 111 | /// Whether the service is required or not. 112 | /// The service object of type or when is false and the service is not found. 113 | /// Thrown when is true and the service is not found. 114 | T? Get([DoesNotReturnIf(true)] bool required = true) where T : class; 115 | } 116 | 117 | /// 118 | /// Exception thrown when fails to locate a required service of a given type. 119 | /// 120 | public sealed class ServiceNotFoundException : Exception 121 | { 122 | internal ServiceNotFoundException(Type type) 123 | : base($"Failed to locate service of type {type}.") 124 | { 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /source/Vignette/Vignette.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /source/Vignette/VignetteGame.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using Sekai; 6 | using Vignette.Audio; 7 | using Vignette.Content; 8 | using Vignette.Graphics; 9 | 10 | namespace Vignette; 11 | 12 | public sealed class VignetteGame : Game 13 | { 14 | private Window root = null!; 15 | private Camera camera = null!; 16 | private Renderer renderer = null!; 17 | private AudioManager audio = null!; 18 | private ContentManager content = null!; 19 | private ServiceLocator services = null!; 20 | 21 | public override void Load() 22 | { 23 | audio = new(Audio); 24 | content = new(Storage); 25 | content.Add(new ShaderLoader(), ".hlsl"); 26 | content.Add(new TextureLoader(Graphics), ".png", ".jpg", ".jpeg", ".bmp", ".gif"); 27 | 28 | renderer = new(Graphics); 29 | 30 | services = new(); 31 | services.Add(audio); 32 | services.Add(content); 33 | 34 | root = new(services) 35 | { 36 | (camera = new Camera { ProjectionMode = CameraProjectionMode.OrthographicOffCenter }) 37 | }; 38 | } 39 | 40 | public override void Draw() 41 | { 42 | root.Draw(renderer); 43 | } 44 | 45 | public override void Update(TimeSpan elapsed) 46 | { 47 | camera.ViewSize = Window.Size; 48 | audio.Update(); 49 | root.Update(elapsed); 50 | } 51 | 52 | public override void Unload() 53 | { 54 | root.Clear(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /source/Vignette/Window.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | namespace Vignette; 5 | 6 | /// 7 | /// The root of . 8 | /// 9 | public sealed class Window : World 10 | { 11 | public override IServiceLocator Services { get; } 12 | 13 | internal Window(IServiceLocator services) 14 | { 15 | Services = services; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /source/Vignette/World.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Cosyne 2 | // Licensed under GPL 3.0 with SDK Exception. See LICENSE for details. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Collections.Specialized; 7 | using System.Linq; 8 | using System.Numerics; 9 | using Sekai.Mathematics; 10 | using Vignette.Collections; 11 | using Vignette.Graphics; 12 | 13 | namespace Vignette; 14 | 15 | /// 16 | /// A that presents and processes its children. 17 | /// 18 | public class World : Behavior 19 | { 20 | protected override Matrix4x4 WorldMatrix => LocalMatrix; 21 | 22 | private readonly SortedFilteredCollection behaviors = new 23 | ( 24 | Comparer.Default, 25 | (node) => node.Enabled, 26 | (node, handler) => node.OrderChanged += handler, 27 | (node, handler) => node.OrderChanged -= handler, 28 | (node, handler) => node.EnabledChanged += handler, 29 | (node, handler) => node.EnabledChanged -= handler 30 | ); 31 | 32 | private readonly SortedFilteredCollection drawables = new 33 | ( 34 | Comparer.Default, 35 | (node) => node.Visible, 36 | (node, handler) => node.OrderChanged += handler, 37 | (node, handler) => node.OrderChanged -= handler, 38 | (node, handler) => node.VisibleChanged += handler, 39 | (node, handler) => node.VisibleChanged -= handler 40 | ); 41 | 42 | private readonly SortedFilteredCollection worlds = new 43 | ( 44 | Comparer.Default, 45 | (node) => node.Enabled, 46 | (node, handler) => node.OrderChanged += handler, 47 | (node, handler) => node.OrderChanged -= handler, 48 | (node, handler) => node.EnabledChanged += handler, 49 | (node, handler) => node.EnabledChanged -= handler 50 | ); 51 | 52 | private readonly List lights = new(); 53 | private readonly List cameras = new(); 54 | 55 | private readonly RenderQueue renderQueue = new(); 56 | private readonly Queue behaviorLoadQueue = new(); 57 | private readonly Queue behaviorUnloadQueue = new(); 58 | 59 | public World() 60 | { 61 | CollectionChanged += handleCollectionChanged; 62 | } 63 | 64 | public override void Update(TimeSpan elapsed) 65 | { 66 | while (behaviorLoadQueue.TryDequeue(out var node)) 67 | { 68 | node.Load(); 69 | } 70 | 71 | while (behaviorUnloadQueue.TryDequeue(out var node)) 72 | { 73 | node.Unload(); 74 | } 75 | 76 | foreach (var behavior in behaviors) 77 | { 78 | behavior.Update(elapsed); 79 | } 80 | } 81 | 82 | public void Draw(Renderer renderer) 83 | { 84 | foreach (var world in worlds) 85 | { 86 | world.Draw(renderer); 87 | } 88 | 89 | // Shadow Map Pass 90 | 91 | foreach (var camera in cameras) 92 | { 93 | foreach (var light in lights) 94 | { 95 | if (BoundingFrustum.Contains(camera.Frustum, light.Frustum) == Containment.Disjoint) 96 | { 97 | continue; 98 | } 99 | 100 | renderQueue.Clear(); 101 | 102 | foreach (var drawable in drawables) 103 | { 104 | drawable.Draw(renderQueue.Begin(light, drawable)); 105 | } 106 | 107 | renderer.Draw(renderQueue); 108 | } 109 | } 110 | 111 | // Lighting Pass 112 | 113 | foreach (var camera in cameras) 114 | { 115 | renderQueue.Clear(); 116 | 117 | foreach (var drawable in drawables) 118 | { 119 | drawable.Draw(renderQueue.Begin(camera, drawable)); 120 | } 121 | 122 | renderer.Draw(renderQueue); 123 | } 124 | } 125 | 126 | private void handleCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) 127 | { 128 | if (args.Action == NotifyCollectionChangedAction.Add) 129 | { 130 | foreach (var node in args.NewItems!.OfType()) 131 | { 132 | load(node); 133 | } 134 | } 135 | 136 | if (args.Action == NotifyCollectionChangedAction.Remove) 137 | { 138 | foreach (var node in args.OldItems!.OfType()) 139 | { 140 | unload(node); 141 | } 142 | } 143 | 144 | if (args.Action == NotifyCollectionChangedAction.Reset) 145 | { 146 | foreach (var node in this) 147 | { 148 | unload(node); 149 | } 150 | } 151 | } 152 | 153 | private void load(Node node) 154 | { 155 | foreach (var child in node.GetNodes()) 156 | { 157 | load(child); 158 | } 159 | 160 | if (node is Behavior behavior) 161 | { 162 | behaviors.Add(behavior); 163 | behaviorLoadQueue.Enqueue(behavior); 164 | } 165 | 166 | if (node is Drawable drawable) 167 | { 168 | drawables.Add(drawable); 169 | } 170 | 171 | if (node is Light light) 172 | { 173 | lights.Add(light); 174 | } 175 | 176 | if (node is Camera camera) 177 | { 178 | cameras.Add(camera); 179 | } 180 | 181 | if (node is World world) 182 | { 183 | worlds.Add(world); 184 | } 185 | else 186 | { 187 | node.CollectionChanged += handleCollectionChanged; 188 | } 189 | } 190 | 191 | private void unload(Node node) 192 | { 193 | foreach (var child in node.GetNodes()) 194 | { 195 | unload(child); 196 | } 197 | 198 | if (node is Behavior behavior) 199 | { 200 | behaviors.Remove(behavior); 201 | behaviorUnloadQueue.Enqueue(behavior); 202 | } 203 | 204 | if (node is Drawable drawable) 205 | { 206 | drawables.Remove(drawable); 207 | } 208 | 209 | if (node is Light light) 210 | { 211 | lights.Remove(light); 212 | } 213 | 214 | if (node is Camera camera) 215 | { 216 | cameras.Remove(camera); 217 | } 218 | 219 | if (node is World world) 220 | { 221 | worlds.Add(world); 222 | } 223 | else 224 | { 225 | node.CollectionChanged -= handleCollectionChanged; 226 | } 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /tests/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | true 5 | 6 | 7 | 8 | runtime; build; native; contentfiles; analyzers; buildtransitive 9 | all 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | --------------------------------------------------------------------------------