浏览代码

Merge branch '16bit'

Mikael Säker 8 年之前
父节点
当前提交
2ddc43c7e9

+ 106 - 0
docs/en/manuals/addressing.md

@@ -0,0 +1,106 @@
+---
+title: Addressing in Defold
+brief: This manual explains how Defold has solved the problem of addressing.
+---
+
+# Addressing
+
+Every game object and component that exist in runtime must be possible to address. This manual describes how Defold solves the addressing problem.
+
+## Identifiers
+
+When you create a new game object or component in the editor, a unique *Id* property is automatically set. Game objects automatically get an id called "go" with an enumerator ("go2", "go3" etc) and components get an id corresponding to the component type ("sprite", "sprite2" etc). All these identifiers can be modified and you are encouraged to pick good, descriptive names for your game objects and components.
+
+![identifiers](images/addressing/identifiers.png)
+
+Suppose you have created a collection file containing two separate game objects. You have given the game objects the identifiers "soldier" and "shield". Each game object also contains a single sprite component. The sprites are both named "sprite". There is also a script component in the "shield" game object that you have named "controller".
+
+Let's look a bit closer at the "shield" game object:
+
+![shield flip](images/addressing/shield_script.png)
+
+First, let's see how you can move the whole game object 10 pixels to the left:
+
+```lua
+local pos = go.get_position()
+pos.x = pos.x + 10
+go.set_position(pos)
+```
+
+Notice that there are no address identifiers in this code at all. Defold knows that the script is running in a component inside the "shield" game object. By omitting an address, the current game object is implied. The above code snippet is equivalent to the following where the game object id is explicitly specified:
+
+```lua
+local pos = go.get_position("shield")
+pos.x = position.x + 10
+go.set_position(pos, "shield")
+```
+
+Now suppose you want to write code in the script that disables the shield sprite only. The script and the sprite lives in the same game object so the game object id "shield" is implied:
+
+```lua
+msg.post("#sprite", "disable")
+```
+
+Notice the initial character '#' before the component id. The hash sign is used to separate the game object id from the component id. Since you don't have a game object id before the hash sign, it starts the address string.
+
+If the script wants to disable the sprite in the "soldier" game object, it is no longer possible to leave out the game object id:
+
+```lua
+msg.post("soldier#sprite", "disable")
+```
+
+Without the "soldier" part in the address, the runtime cannot separate the component "sprite" in the "shield" game object from the component "sprite" in the "soldier" game object. Defold combines the identity of the game object with that of the component which is why you can have two components named "sprite" without violating the requirement for identity uniqueness.
+
+![sprite identifiers](images/addressing/sprites.png)
+
+## Collections and game object ids
+
+Suppose now that you need more than one bean soldiers in your game. You don't want to duplicate the "soldier" and "shield" game objects, so instead you create a new collection called "bean.collection". You put the two game objects in the collection and then, in "main.collection" you add two copies of "bean.collection":
+
+![collections](images/addressing/collections.png)
+
+You also add a game object called "commander" containing a script. The idea is that the "commander" script should be responsible for giving orders to the bean soldiers. In order for this to work, the "commander" script needs to be able to send messages to each bean.
+
+Within the context of "bean.collection", each game object still has the ids "soldier" and "shield". However, since we added several instances of this collection, each instance defines a new namespace with a unique id (in this case "bean1" and "bean2"). When the game data is compiled, the collection hierarchy is flattened and identities are combined down the collection hierarchy to each game object and they are given their full ids:
+
+- /bean1/soldier
+- /bean1/shield
+- /bean2/soldier
+- /bean2/shield
+- /commander
+
+## Absolute and relative ids
+
+Addressing works a bit like directory paths. A script in a game object can reference any object at the same namespace level and deeper. A script that is attached to the "soldier" game object instances can address its corresponding "shield" game object by the id that is local to "bean.collection":
+
+```lua
+msg.post("shield#sprite", "disable")
+```
+
+![relative id](images/addressing/relative_same.png)
+
+If you want the "commander" script to send messages to the two "soldier" script instances, you you must specify which one to address. You do that by providing the combined ids:
+
+```lua
+msg.post("bean1/soldier#script", "be_alert")
+msg.post("bean2/soldier#script", "stay_frosty")
+```
+
+![relative id](images/addressing/relative.png)
+
+But what if you want the soldier in "bean1" to send a message to the "commander" script? The "soldier" object and "commander" are not in the same namespace. In this case you must provide an *absolute* address, one that starts from the root:
+
+```lua
+msg.post("/commander#script", "i_need_medic") -- Note the leading '/'!
+```
+
+If you would have provided the address `commander#script` *without* the leading slash, that would have resolved to `/bean1/commander#script`.
+
+![absolute id](images/addressing/absolute.png)
+
+Any address that starts with a '/' will be resolved from the root namespace of the game world. This corresponds to the root of the *bootstrap collection* that is loaded on game start.
+
+## Identities are static
+
+We have seen how every object in Defold can uniquely addressed any other object through an absolute or relative address. These addresses are set at *compile time* and stays fixed throughout the object’s lifetime. There is *no way* an object can change its identity. This means that if you save the address to an object that address will stay valid for as long as the object exists; you never have to worry about updating object references that you store.
+

二进制
docs/en/manuals/images/addressing/absolute.png


二进制
docs/en/manuals/images/addressing/bean.png


二进制
docs/en/manuals/images/addressing/bean_buddy.png


二进制
docs/en/manuals/images/addressing/bean_editor.png


二进制
docs/en/manuals/images/addressing/bean_shield.png


二进制
docs/en/manuals/images/addressing/collections.png


二进制
docs/en/manuals/images/addressing/identifiers.png


二进制
docs/en/manuals/images/addressing/relative.png


二进制
docs/en/manuals/images/addressing/relative_same.png


二进制
docs/en/manuals/images/addressing/shield_script.png


二进制
docs/en/manuals/images/addressing/sprites.png


+ 18 - 13
docs/en/manuals/texture-profiles.md

@@ -95,7 +95,7 @@ The *formats* added to a profile each have the following properties:
 : Selects the quality level for the resulting compressed image. The values range from `FAST` (low quality, fast compression) to `NORMAL`, `HIGH` and `BEST` (highest quality, slowest compression).
 
 *compression_type*
-: Selects the type of compression used for the resulting compressed image, `COMPRESSION_TYPE_DEFAULT`, `COMPRESSION_TYPE_WEBP` or `COMPRESSION_TYPE_WEBP_LOSSY`. See <a href="https://www.defold.com/manuals/texture-profiles/#_compression_types">Compression Types</a> below for more details.
+: Selects the type of compression used for the resulting compressed image, `COMPRESSION_TYPE_DEFAULT`, `COMPRESSION_TYPE_WEBP` or `COMPRESSION_TYPE_WEBP_LOSSY`. See [Compression Types](#_compression_types) below for more details.
 
 ## Texture formats
 
@@ -114,16 +114,19 @@ PVRTC
 ETC
 : Ericsson Texture Compression. Blocks of 4×4 pixels are compressed into a single 64-bit word. The 4×4 block is divided in half and each half is assigned a base color. Each pixel is then encoded as one of four offset values from the base color of its half. Android supports ETC1 since version 2.2 (Froyo). Defold compresses ETC1 textures.
 
-| Format                            | Compression | Color                            | Note |
+| Format                            | Compression | Details  |
 | --------------------------------- | ----------- | -------------------------------- | ---- |
-| `TEXTURE_FORMAT_LUMINANCE`        | none        | One channel gray-scale, no alpha | RGB channels multiplied into one. Alpha is discarded. |
-| `TEXTURE_FORMAT_RGB`              | none        | 3 channel color                  | Alpha is discarded |
-| `TEXTURE_FORMAT_RGBA`             | none        | 3 channel color and full alpha   | |
-| `TEXTURE_FORMAT_RGB_PVRTC2BPPV1`  | 1:16 fixed. | No alpha                         | Requires square images. Non square images will be resized. |
-| `TEXTURE_FORMAT_RGB_PVRTC4BPPV1`  | 1:8 fixed   | No alpha                         | Requires square images. Non square images will be resized. |
-| `TEXTURE_FORMAT_RGBA_PVRTC2BPPV1` | 1:16 fixed | Pre-multiplied alpha | Requires square images. Non square images will be resized. |
-| `TEXTURE_FORMAT_RGBA_PVRTC4BPPV1` | 1:8 fixed. | Pre-multiplied alpha | Requires square images. Non square images will be resized. |
-| `TEXTURE_FORMAT_RGB_ETC1`         | 1:6 fixed  | No alpha | |
+| `TEXTURE_FORMAT_RGB`              | none        | 3 channel color. Alpha is discarded |
+| `TEXTURE_FORMAT_RGBA`             | none        | 3 channel color and full alpha.    |
+| `TEXTURE_FORMAT_RGB_16BPP`        | none        | 3 channel color. 5+6+5 bits. |
+| `TEXTURE_FORMAT_RGBA_16BPP`       | none        | 3 channel color and full alpha. 4+4+4+4 bits. |
+| `TEXTURE_FORMAT_LUMINANCE`        | none        | 1 channel gray-scale, no alpha. RGB channels multiplied into one. Alpha is discarded. |
+| `TEXTURE_FORMAT_LUMINANCE_ALPHA`  | none        | 1 channel gray-scale and full alpha. RGB channels multiplied into one. |
+| `TEXTURE_FORMAT_RGB_PVRTC2BPPV1`  | 1:16 fixed. | No alpha. Requires square images. Non square images will be resized. |
+| `TEXTURE_FORMAT_RGB_PVRTC4BPPV1`  | 1:8 fixed   | No alpha. Requires square images. Non square images will be resized. |
+| `TEXTURE_FORMAT_RGBA_PVRTC2BPPV1` | 1:16 fixed | Pre-multiplied alpha. Requires square images. Non square images will be resized. |
+| `TEXTURE_FORMAT_RGBA_PVRTC4BPPV1` | 1:8 fixed. | Pre-multiplied alpha. Requires square images. Non square images will be resized. |
+| `TEXTURE_FORMAT_RGB_ETC1`         | 1:6 fixed  | No alpha |
 
 <!---
 | TEXTURE_FORMAT_RGB_DTX1
@@ -153,6 +156,8 @@ The following software image compression types are supported. The data is uncomp
 
 | Type                              | Formats                   | Note |
 | --------------------------------- | ------------------------- | ---- |
-| `COMPRESSION_TYPE_DEFAULT`        | All formats               | Generic lossless data compression. Default |
-| `COMPRESSION_TYPE_WEBP`           | All formats               | WebP lossless compression. Higher quality level results in smaller size. For hardware compressed texture formats PVRTC or ETC, the compression process transforms the compressed hardware texture format data into data more suitable for WebP image compression using an internal intermediate format. This is then transformed back into the compressed hardware texture format when loaded by the run-time. |
-| `COMPRESSION_TYPE_WEBP_LOSSY`     | TEXTURE_FORMAT_LUMINANCE TEXTURE_FORMAT_RGB TEXTURE_FORMAT_RGBA | WebP lossy compression. Lower quality level results in smaller size. WebP lossy type is currently not supported for hardware compressed texture formats. |
+| `COMPRESSION_TYPE_DEFAULT`        | All formats               | Generic lossless data compression. Default. |
+| `COMPRESSION_TYPE_WEBP`           | All formats               | WebP lossless compression. Higher quality level results in smaller size. |
+| `COMPRESSION_TYPE_WEBP_LOSSY`     | All non hardware compressed formats. | WebP lossy compression. Lower quality level results in smaller size. |
+
+For hardware compressed texture formats PVRTC or ETC, the WebP lossless compression process transforms the compressed hardware texture format data into data more suitable for WebP image compression using an internal intermediate format. This is then transformed back into the compressed hardware texture format when loaded by the run-time. WebP lossy type is currently not supported for hardware compressed texture formats PVRTC and ETC.