|
1 | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
2 | | -<class name="GFWorld" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd"> |
| 2 | +<class name="GFWorld" inherits="Object" |
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd"> |
3 | 4 | <brief_description> |
4 | 5 | An entity component system world. |
5 | 6 | </brief_description> |
|
51 | 52 | [/codeblock] |
52 | 53 | </description> |
53 | 54 | </method> |
| 55 | + <method name="get_default_world" qualifiers="static"> |
| 56 | + <return type="GFWorld" /> |
| 57 | + <description> |
| 58 | + Returns the current default world. If no default world is set then this method will return the world from [method get_singleton]. See [method set_default_world] for more information on default worlds. |
| 59 | + [b]NOTE:[/b] Default worlds are unique per thread. This method will only return worlds set in the same thread. |
| 60 | + </description> |
| 61 | + </method> |
54 | 62 | <method name="get_raw" qualifiers="const"> |
55 | 63 | <return type="int" /> |
56 | 64 | <description> |
|
63 | 71 |
|
64 | 72 | ecs_new(raw); // Create a new entity |
65 | 73 | [/codeblock] |
66 | | - WARNING: Do not call finish, or otherwise destruct the `ecs_world_t`. The world object is managed by [GFWorld] and freeing it separate from the [GFWorld] will cause undefined behavior or crashes. |
| 74 | + [b]WARNING:[/b] Do not call finish, or otherwise destruct the [code]ecs_world_t[/code]. The world object is managed by [GFWorld] and freeing it separate from the [GFWorld] will cause undefined behavior or crashes. |
| 75 | + </description> |
| 76 | + </method> |
| 77 | + <method name="get_singleton" qualifiers="static"> |
| 78 | + <return type="GFWorld" /> |
| 79 | + <description> |
| 80 | + Returns the global world of the program. |
| 81 | + Example: |
| 82 | + [codeblock] |
| 83 | + var world = GFWorld.get_singleton() |
| 84 | + GFEntity.new_in_world(world) |
| 85 | + [/codeblock] |
67 | 86 | </description> |
68 | 87 | </method> |
69 | 88 | <method name="lookup"> |
|
139 | 158 | [/codeblock] |
140 | 159 | </description> |
141 | 160 | </method> |
| 161 | + <method name="set_default_world" qualifiers="static"> |
| 162 | + <return type="void" /> |
| 163 | + <param index="0" name="world" type="GFWorld" /> |
| 164 | + <description> |
| 165 | + Sets the default world that methods like [method GFEntity.new] use to determine which world to create objects in. |
| 166 | + This method can be used as a means of switching the context (world) in which ECS operations take place. For example: |
| 167 | + [codeblock] |
| 168 | + var custom_default_world = GFWorld.new() |
| 169 | + |
| 170 | + var old_default_world = GFWorld.get_default_world() |
| 171 | + GFWorld.set_default_world(custom_default_world) |
| 172 | + |
| 173 | + # The following line creates an entity in |
| 174 | + # `custom_default_world` when it otherwise |
| 175 | + # would've been created in `old_default_world`. |
| 176 | + var entity = GFEntity.new() |
| 177 | + |
| 178 | + # It is a good practice to restore the default |
| 179 | + # world to whatever it was before you set it. |
| 180 | + GFWorld.set_default_world(old_default_world) |
| 181 | + [/codeblock] |
| 182 | + Changing the default world can be used as an alternative to [code]new_in_world[/code] methods such as [method GFSystemBuilder.new_in_world]. This method is called internally before [method GFRegisterableEntity._register] is called so that entities created during registration are created in the same world as the registered entity. This is particularly helpful when registering [GFModule]s where you may be creating many entities, systems, and observers. If [method set_default_world] wasn't called before registering modules then you would need to use [code]new_in_world[/code] methods instead of [code]new[/code] if you wanted your module to work in worlds other than the global returned from [method get_singleton]. |
| 183 | + [b]NOTE:[/b] Default worlds are unique per thread. This method will only affect the thread it was called in. |
| 184 | + </description> |
| 185 | + </method> |
142 | 186 | <method name="start_rest_api" qualifiers="const"> |
143 | 187 | <return type="void" /> |
144 | 188 | <description> |
|
0 commit comments