Browse Source

Dynamic Prototype

Björn Ritzl 2 năm trước cách đây
mục cha
commit
6e072f4ffc

+ 21 - 1
docs/en/manuals/factory.md

@@ -236,13 +236,33 @@ Asynchronous loading
   end
   ```
 
+## Dynamic prototype
+
+It is possible to change which *Prototype* a factory can create by checking the *Dynamic Prototype* checkbox in the factory properties.
+
+![Dynamic prototype](images/factory/dynamic_prototype.png)
+
+When the *Dynamic Prototype* option is checked the factory component can change prototype using the `factory.set_prototype()` function. Example:
+
+```lua
+factory.unload("#factory") -- unload the previous resources
+factory.set_prototype("#factory", "/main/levels/enemyA.goc")
+local enemy_id = factory.create("#factory")
+```
+
+::: important
+When the *Dynamic Prototype* option is set the collection component count cannot be optimized, and the owning collection will use the default component counts from the *game.project* file.
+:::
+
+
 ## Instance limits
 
 The project setting *max_instances* in *Collection related settings* limits the total number of game object instances that can exist in a world (the main.collection loaded at startup or any world loaded via a collection proxy). All game objects that exist in the world are counted agaist that limit and it does not matter if they are placed by hand in the editor or spawned in runtime through a script.
 
 ![Max instances](images/factory/factory_max_instances.png)
 
-So if you set *max_instances* to 1024 and have 24 manually placed game objects in your main collection, you can spawn an additional 1000 game objects. As soon as you delete a game object, you are free to spawn another instance.
+If you set *max_instances* to 1024 and have 24 manually placed game objects in your main collection, you can spawn an additional 1000 game objects. As soon as you delete a game object, you are free to spawn another instance.
+
 
 ## Pooling of game objects
 

BIN
docs/en/manuals/images/factory/dynamic_prototype.png


BIN
docs/en/manuals/images/factory/factory_collection.png


BIN
docs/en/manuals/images/factory/factory_component.png


BIN
docs/en/manuals/images/factory/load_dynamically.png


+ 1 - 10
docs/en/manuals/project-settings.md

@@ -619,16 +619,7 @@ local my_value = tonumber(sys.get_config("test.my_value"))
 ```
 
 
-## Component max count optimizations
-The `game.project` settings file contains many values specifying the maximum number of a certain resource that can exist at the same time, often counted per loaded collection (also called world). The Defold engine will use these max values to preallocate memory for this amount of memory to avoid dynamic allocations and memory fragmentation while the game is running.
-
-The Defold data structures used to represent components and other resources are optimized to use as little memory as possible but care should still be taken when setting the values to avoid allocating more memory than is actually necessary.
-
-To further optimize memory usage the Defold build process will analyse the content of the game and override the max counts if it is possible to know for certain the exact amount:
-
-* If a collection doesn't contain any factory components the exact amount of each component will be allocated and the max count values will be ignored.
-* If a collection contains a factory component the spawned objects will be analysed and the max count will be used for components that can be spawned from the factories.
-* If a collection contains a factory or a collection factory with activated "Dynamic Prototype" option, this collection will use the max counters.
+:[Component max count optimizations](../shared/component-max-count-optimizations.md)
 
 
 ## Custom project settings

+ 10 - 0
docs/en/shared/component-max-count-optimizations.md

@@ -0,0 +1,10 @@
+## Component max count optimizations
+The *game.project* settings file contains many values specifying the maximum number of a certain resource that can exist at the same time, often counted per loaded collection (also called world). The Defold engine will use these max values to preallocate memory for this amount of memory to avoid dynamic allocations and memory fragmentation while the game is running.
+
+The Defold data structures used to represent components and other resources are optimized to use as little memory as possible but care should still be taken when setting the values to avoid allocating more memory than is actually necessary.
+
+To further optimize memory usage the Defold build process will analyse the content of the game and override the max counts if it is possible to know for certain the exact amount:
+
+* If a collection doesn't contain any factory components the exact amount of each component will be allocated and the max count values will be ignored.
+* If a collection contains a factory component the spawned objects will be analysed and the max count will be used for components that can be spawned from the factories.
+* If a collection contains a factory or a collection factory with activated "Dynamic Prototype" option, this collection will use the max counters.