1 /************************************************************************************************************************ 2 This module contain main helper templates for user. 3 There are three structure templates (mixins) which can be added on top of structure: 4 $(LIST 5 * System: make system structure 6 * Component: make component structure 7 * Event: make event structure 8 ) 9 This mixins are optional and are used to adding some additional capabilities, e.g. ECS.System is used to configuring default number of jobs for system. 10 11 --- 12 Struct System1 13 { 14 mixin!ECS.System; 15 } 16 17 Struct System2 18 { 19 mixin!ECS.System(16);//set number of jobs generated for system by multithreaded update 20 } 21 22 Struct Component1 23 { 24 mixin!ECS.Component; 25 } 26 27 Struct Event1 28 { 29 mixin!ECS.Event; 30 } 31 --- 32 33 There is also template for generating list of excluded components "ExcludedComponets(T...)". 34 This template takes component structure types and making list of excluded components used in "registerSystem" function. 35 36 --- 37 Struct System1 38 { 39 mixin!ECS.System; 40 41 struct EntitiesData 42 { 43 ... //used components 44 } 45 46 ExcludedComponets!(Comp1, Comp2); 47 } 48 --- 49 50 Templates ReadOnlyDependencies nad WritableDependencies are used to create list of dependencies for System. 51 Writable dependencies are bloking parallel execution of system which has same dependency (as writable or readonly). 52 This dependencies works same as Component dependencies but can be used for creating external dependencies (e.g. dependency on spatial partitioning tree access). 53 54 --- 55 enum ExternalDependency1 = "ExternalDependency1"; 56 57 Struct System1 58 { 59 mixin!ECS.System; 60 61 struct EntitiesData 62 { 63 ... //used components 64 } 65 66 ReadOnlyDependencies!(ExternalDependency1); 67 } 68 --- 69 70 Copyright: Copyright © 2018-2023, Dawid Masiukiewicz, Michał Masiukiewicz 71 License: BSD 3-clause, see LICENSE file in project root folder. 72 */ 73 module bubel.ecs.core; 74 75 public import bubel.ecs.manager; 76 public import bubel.ecs.entity; 77 public import bubel.ecs.traits : becsID; 78 79 /************************************************************************************************************************ 80 Main struct used as namespace for templates. 81 */ 82 static struct ECS 83 { 84 /************************************************************************************************************************ 85 Set default system parameters (number of parallel jobs) 86 */ 87 mixin template System(uint jobs_count = 32) 88 { 89 __gshared uint __becs_jobs_count = jobs_count; 90 } 91 92 /************************************************************************************************************************ 93 Mark structure as Component 94 */ 95 mixin template Component() 96 { 97 deprecated ComponentRef ref_() @nogc nothrow return 98 { 99 return ComponentRef(&this, becsID!(typeof(this))); 100 } 101 } 102 103 /************************************************************************************************************************ 104 Mark structure as Event 105 */ 106 mixin template Event() 107 { 108 109 } 110 111 /************************************************************************************************************************ 112 Make list of excluded components. This template get structure types as argument. Should be added inside System structure. 113 */ 114 mixin template ExcludedComponents(T...) 115 { 116 alias ExcludedComponents = T; 117 } 118 119 /************************************************************************************************************************ 120 Make list of readonly ependencies. This template get strings as arguments. Should be added inside System structure. 121 */ 122 mixin template ReadOnlyDependencies(T...) 123 { 124 alias ReadOnlyDependencies = T; 125 } 126 127 /************************************************************************************************************************ 128 Make list of writable ependencies. This template get strings as arguments. Should be added inside System structure. 129 */ 130 mixin template WritableDependencies(T...) 131 { 132 alias WritableDependencies = T; 133 } 134 }