Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added physics, fixed update and ssl certs #259

Merged
merged 6 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/en/manuals/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,17 @@ It is not uncommon for games to have some kind of connection to a backend servic
* [Socket connections](/manuals/socket-connections)
* [WebSocket connections](/manuals/websocket-connections)
* [Online services](/manuals/online-services)


## Technical details

### IPv4 and IPv6

Defold supports IPv4 and IPv6 connections for sockets and HTTP requests.

### Secure connections

Defold supports secure SSL connections for sockets and HTTP requests.

Defold can optionally also verify the SSL certificate of any secure connection. SSL verification will be enabled when a PEM file containing public CA-root certificate keys or a self-signed certificate public key is provided in the [SSL Certificates setting](/manuals/project-settings/#network)) field of the Network section in *game.project*. A list of CA-root certificates is included in `builtins/ca-certificates`, but it is recommended to create a new PEM file and copy-paste the needed CA-root certificates depending on the server(s) the game conects to.

5 changes: 5 additions & 0 deletions docs/en/manuals/physics.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ The physics engine simulates Newtonian physics and it is designed to work well w
In general it is required that the physics simulation is scaled for it to work well with the typical size of objects in a game. The scale of the physics simulation can be changed in `game.project` via the [physics scale setting](/manuals/project-settings/#physics). Setting this value to for instance 0.02 would mean that 200 pixels would be treated as a 4 meters. Do note that the gravity (also changed in `game.project`) has to be increased to accommodate for the change in scale.


## Physics updates

It is recommended to update the physics engine at regular intervals to ensure a stable simulation (as opposed to updating at possibly irregular frame-rate dependent intervals). You can use a fixed update for physics by checking the [Use Fixed Timestep setting](/manuals/project-settings/#physics) of the Physics section in the *game.project* file. The update frequency is controlled by the [Fixed Update Frequency setting](/manuals/project-settings/#engine) of the Engine section in the *game.project* file. When using a fixed timestep for physics it is also recommended to use the `fixed_update(self, dt)` lifecycle function to interact with the collision objects of your game, for instance when applying forces to them.


## Caveats and common issues

Collection proxies
Expand Down
18 changes: 18 additions & 0 deletions docs/en/manuals/project-defignore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Defold project ignores
brief: This manual describes how to ignore files and folders in Defold.
---

# Ignoring files

It is possible to configure the Defold editor and tools to ignore files and folders in a project. This can be useful if the project contains files with file extensions which conflict with file extensions used by Defold. One such example is Go language files with the .go file extension which is the same as the editor uses for game object files.

## The .defignore file
The files and folders to exclude are defined in a file named `.defignore` in the project root. The file should list files and folders to exclude, one per line. Example:

```
/path/to/file.png
/otherpath
```

This will exclude the file `/path/to/file.png` and anything in the path `/otherpath`.
68 changes: 39 additions & 29 deletions docs/en/manuals/project-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ Check to share a single Lua state between all script types, unchecked by default
#### Run While Iconified
Allow the engine to continue running while the application window is iconified (desktop platforms only), `false` by default.

#### Fixed Update Frequency
The update frequency of the `fixed_update(self, dt)` lifecycle function. In Hertz. 60 by default.

---

### Display

#### Width
Expand All @@ -104,11 +109,11 @@ How many samples to use for super sampling anti-aliasing. It sets the GLFW_FSAA_
#### Fullscreen
Check if the application should start full screen. If unchecked, the application runs windowed.

#### Frame Cap
If `Vsync` checked, snaps to the closest matching swap interval for the set frame cap if a monitor is detected. Otherwise uses timers to respect the set value, 0 means no cap. This setting maps to `display.update_frequency`. ([See below](#vsync-frame-cap-and-swap-interval)).

#### Vsync
Vertical sync, rely on hardware vsync for frame timing. Can be overridden depending on graphics driver and platform specifics. ([See below](#vsync-frame-cap-and-swap-interval)).
#### Update Frequency
The desired frame rate in Hertz. Set to 0 for variable frame rate. A value larger than 0 will result in a fixed frame rate capped at runtime towards the actual frame rate (which means that you cannot update the game loop twice in an engine frame). Use [`sys.set_update_frequency(hz)`](https://defold.com/ref/stable/sys/?q=set_update_frequency#sys.set_update_frequency:frequency) to change this value at runtime.
#### Swap interval
An integer setting that sets the [OpenGL swap interval](https://www.khronos.org/opengl/wiki/Swap_Interval). Does not work with Vulkan. 0 disables vsync. Default is 1.

#### Display Profiles
Specifies which display profiles file to use, `/builtins/render/default.display_profilesc` by default. Learn more in the [GUI Layouts manual](/manuals/gui-layouts/#creating-display-profiles).
Expand Down Expand Up @@ -163,6 +168,9 @@ Tells the physics engine how to scale the physics worlds in relation to the game
#### Allow Dynamic Transforms
Check if the physics engine should apply the transform of a game object to any attached collision object components. This can be used to move, scale and rotate collision shapes, even those that are dynamic. `true` by default.

#### Use Fixed Timestep
Check if the physics engine should use fixed and framerate independent updates. Use this setting in combination with the `fixed_update(self, dt)` lifecycle function and the `engine.fixed_update_frequency` project setting to interact with the physics engine at regular intervals. For new projects the recommended setting is `true`. `false` by default

#### Debug Scale
How big to draw unit objects in physics, like triads and normals, `30` by default.

Expand Down Expand Up @@ -603,34 +611,36 @@ To further optimize memory usage the Defold build process will analyse the conte
* 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.


## Vsync, frame cap, and swap interval
The first thing of note is that on desktop platforms vsync can be controlled globally by graphics card settings. If for example vsync is force-enabled in the graphics control panel it is not user controllable, e.g. the setting cannot be accessed or modified from Defold. Most mobile devices also has vsync enabled by default.
## Custom project settings

It is possible to define custom settings for the main project or for a [native extension](/manuals/extensions/). Custom settings for the main project must be defined in a `game.properties` file in the root of the project. For a native extension they should be defined in an `ext.properties` file next to the `ext.manifest` file.

The settings file uses the same INI format as *game.project* and property attributes are defined using a dot notation with a suffix:

With `Vsync` checked in `game.project` the engine relies on hardware vsync and uses a fixed time step `dt` based on any detected monitor refresh rate. This is the default setting. With `Vsync` checked and `Frame cap` > 0, the rate will be clamped to a swap interval that matches any detected main monitor refresh rate. With `Vsync` unchecked and `Frame cap` 0, the time step is not fixed but instead uses actual elapsed time difference for `dt`. With `Vsync` unchecked and `Frame cap` > 0, timers are used to respect the set frame cap value. There is no guarantee that the frame cap will be achieved depending on platform specifics and hardware settings.
```
[my_category]
my_property.private = 1
...
```

The default meta file that is always applied is available [here](https://github.com/defold/defold/blob/dev/com.dynamo.cr/com.dynamo.cr.bob/src/com/dynamo/bob/meta.properties)

The following attributes are currently available:

```
// `type` - used for the value string parsing (only in bob.jar for now)
my_property.type = string // one of the follwoing values: bool, string, number, integer, string_array, resource

Swap interval is the interval with which to swap the front and back buffers in sync with vertical blanks (v-blank), the hardware event where the screen image is updated with data from the front buffer. A value of 1 swaps the buffers at every v-blank, a value of 2 swaps the buffers every other v-blank and so on. A value of 0 disables waiting for v-blank before swapping the buffers\*. Setting `swap_interval` is done by calling the [```set_vsync_swap_interval```](/ref/sys/#sys.set_vsync_swap_interval:swap_interval) function.
// `help` - used as help tip in the editor (not used for now)
my_property.help = string

// `default` - value used as default if user didn't set value manually (only in bob.jar for now)
my_property.default = string

### Caveat
Currently, Defold queries for monitor refresh rate at init and uses that as a basis for picking a fixed `dt`. If you want to support monitors using variable refresh rate (GSync or FreeSync for example) or other scenarios where the refresh rate might not be trivial to query, uncheck `Vsync`to let the engine measure actual `dt` each frame instead of relying on a fixed time step.
// `private` - private value used during the bundle process but will be removed from the bundle itself
my_property.private = 1 // boolean value 1 or 0

```

### Vsync and frame cap in Defold

<table>
<tr>
<th></th>
<th><b>Frame cap 0 (default)</b></th>
<th><b>Frame cap > 0</b></th>
</tr>
<tr>
<td><b>Vsync checked (default)</b></td>
<td>Relies on hardware vsync. Fixed <code>dt</code> of <code>1/(detected monitor refresh rate)</code>.</td>
<td>Fixed <code>dt</code> of <code>(swap interval)/(detected monitor refresh rate)</code> where swap interval is clamped to the closest matching monitor refresh rate frame cap multiple.</td>
</tr>
<tr>
<td><b>Vsync unchecked</b></td>
<td>Calculates <code>dt</code> each frame based on elapsed system time. Vsync might still be enabled in driver settings.</td>
<td>Uses a fixed <code>dt</code> of <code>1 / (Frame cap)</code>. Uses timers and sleeps to respect the set frame cap.</td>
</tr>
</table>
At the moment meta properties are used only in `bob.jar` when bundling application, but later will be parsed by the editor and represented in the `game.project` viewer.
9 changes: 9 additions & 0 deletions docs/en/manuals/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ Defold executes Lua scripts as part of the engine lifecycle and exposes the life
end
```

`fixed_update(self, dt)`
: Frame-rate independent update. `dt` contains the delta time since the last update. Useful when you wish to manipulate physics objects at regular intervals to achieve a stable physics simulation. Requires that `physics.use_fixed_timestep` is enabled in *game.project*.

```lua
function fixed_update(self, dt)
msg.post("#co", "apply_force", {force = vmath.vector3(1, 0, 0), position = go.get_world_position()})
end
```

`on_message(self, message_id, message, sender)`
: When messages are sent to the script component through [`msg.post()`](/ref/msg#msg.post) the engine calls this function of the receiver component. Learn [more about message passing](/manuals/message-passing).

Expand Down