Skip to content

Commit 53b4ae3

Browse files
authored
Merge pull request #3 from dev-masih/dev (merge for DefGraph version 3)
merge for DefGraph version 3
2 parents 192b565 + 9d66ff6 commit 53b4ae3

36 files changed

Lines changed: 913 additions & 176 deletions

Migrate_v2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* `move_player` function now returns two things, first is new movement data as a table that you should overwrite the old one and second is move result table with the structure like { `position`: next position of game object as vector3, `is_reached`: is game object reached the destination as boolean }
77
* `debug_draw_player_move` function now draw game object route through the destination.
88

9-
<img src="example/debug_draw_player_move.png" alt="routing gif" style="max-width:100%;" />
9+
<img src="examples/raw/debug_draw_player_move.png" alt="player move" style="max-width:100%;" />
1010

1111
* version 2 is tagged as `v2` in GitHub repository.

Migrate_v3.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Changelog and migration guild from version 2 to 3
2+
3+
* Added ability for game objects to have curved corner paths.
4+
* Added ability to track game object rotation as move result.
5+
* Added only one ways routes, and added separate arguments `two_way_route_color` and `one_way_route_color` in `debug_draw_map_nodes` function.
6+
7+
<img src="examples/raw/debug_draw_one_way_route.jpg" alt="one way route" style="max-width:100%;" />
8+
9+
In the above image green line is a two-way path and the light blue line is a one-way path, a little square is placed on a one-way route near the destination, for example in this image the route is one way from node 5 to 6.
10+
11+
* Added separate examples of static and dynamic map nodes.
12+
* Added documentation for module settings.
13+
* Added `is_one_way` argument to `map_add_route` function, to able to add just one-way route.
14+
* Added `is_remove_one_way` argument to `map_remove_route` function, to able to remove just one-way route or both between two nodes.
15+
* Added `map_remove_node` function to remove a node and it's connected routes to it.
16+
* Added `map_update_node_position` function to update node positions. now the entire map can move dynamically.
17+
* Added `map_set_properties` function to replace module default settings.
18+
* `move_initialize` function gets `initial_face_vector` as a vector3 to calculate game object face direction based on this value. setting this value to `nil` will disable rotation tracking system and `rotation` field in move result table will always be `nil`.
19+
* `move_player` function no longer needs `threshold` as an argument.
20+
* `move_initialize` function now gets `settings_go_threshold` as a number and you do need to call `move_initialize` if you want to change it. This allows us to prevent situations that a game object always moves with a moving destination node without reaching it, forever. setting this value to `nil` will fall back to the module default value.
21+
* Adding `settings_path_curve_tightness`, `settings_path_curve_roundness`, `settings_path_curve_max_distance_from_corner` and `settings_allow_enter_on_route` to `move_initialize` arguments. you can overwrite these values for a single game object by them. setting these values to `nil` will fall back to the module default value.
22+
* Added `rotation` to move result table that returned from function `move_player` and you can set game object rotation to it.
23+
* Fixed bug that caused a game object to get stuck in a complex intersection.
24+
* Added `is_show_intersection` argument to `debug_draw_player_move` function to allow debugger mark/not mark intersections of game object path.
25+
* version 3 is tagged as `v3` in GitHub repository.

README.md

Lines changed: 134 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
# DefGraph v2
1+
# DefGraph v3
22

3-
<img src="example/banner.jpg" alt="routing gif" style="max-width:100%;" />
3+
<img src="examples/raw/banner.jpg" alt="routing gif" style="max-width:100%;" />
44

5+
* <a href="https://github.com/dev-masih/defgraph/blob/master/Migrate_v3.md">**Changelog and migration guild from version 2 to 3**</a>
56
* <a href="https://github.com/dev-masih/defgraph/blob/master/Migrate_v2.md">**Changelog and migration guild from version 1 to 2**</a>
67

78
This module contains functions to create a world map as a shape of a graph and the ability to manipulate it at any time, easily see debug drawing of this graph and move go's inside of this graph with utilizing auto pathfinder.
89

910
You can define a graph with several nodes and routes between them and the extension takes care of finding and moving your go inside this graph with just one call inside player update function.
1011
the gif bellow shows you this exactly when the destination for all red circles is node number 6.
1112

12-
<img src="example/routing.gif" alt="routing gif" style="max-width:100%;" />
13+
<img src="examples/raw/static_routing_v3.gif" alt="static routing gif" style="max-width:100%;" />
1314

1415
As you can see staying on the routes is the number one rule for red circles and they are going to the destination with minimum distance. all you have seen in this gif except for red circles, drawn by defGraph module and all of them are customizable.
1516
defGraph is adaptable to map change so even if you add or remove routes in the middle of the game extension tries to find the better road for you.
17+
also, you can update nodes positions, another word you can have dynamically moving routes ;)
1618

17-
<img src="example/dynamic-routing.gif" alt="routing gif" style="max-width:100%;" />
19+
<img src="examples/raw/dynamic_routing_v3.gif" alt="dynamic routing gif" style="max-width:100%;" />
1820

1921
This is a community project you are welcome to contribute to it, sending PR, suggest a feature or report a bug.
2022

@@ -30,45 +32,139 @@ local defgraph = require("defgraph.defgraph")
3032
```
3133
Then you can use the DefGraph functions using this module.
3234

35+
[Official Defold game asset page for DefGraph](https://defold.com/assets/defgraph/)
36+
37+
## Module Settings
38+
There are several parameters for the module to works with, you can change these parameters one time for the entire module with `map_set_properties` and let each game object inherit those or set these parameters or each game object with `move_initialize` function. If you choose to not change any of them, the module uses it's own default values.
39+
#### **Threshold:**
40+
This `number` value used as detection that an object is on a route or not. It's better to use a bigger value as object speed is getting higher to have better movement experience. The module default value is `1` and minimum for this value should be `1`.
41+
#### **Path Curve Tightness:**
42+
This `number` value determines how tight a turn on the path should be. The module default value is `4` and minimum for this value should be `2`.
43+
44+
<img src="examples/raw/tness_2.jpg" alt="Tightness 2"/> | <img src="examples/raw/tness_3.jpg" alt="Tightness 3"/> | <img src="examples/raw/tness_8.jpg" alt="Tightness 8"/>
45+
:-------------: | :-------------: | :-------------:
46+
Tightness: 2 | Tightness: 3 | Tightness: 8
47+
48+
#### **Path Curve Roundness:**
49+
This `number` value determines how round a turn on a path should be. The module default value is `3`. If this value equals `0` the path will not have any curve and the value of `settings_path_curve_tightness` and `settings_path_curve_max_distance_from_corner` will get ignored. The higher value for roundness will need more processing power especially when your map nodes are dynamically moving.
50+
51+
<img src="examples/raw/round_0.jpg" alt="Roundness 0"/> | <img src="examples/raw/round_1.jpg" alt="Roundness 1"/> | <img src="examples/raw/round_5.jpg" alt="Roundness 5"/>
52+
:-------------: | :-------------: | :-------------:
53+
Roundness: 0 | Roundness: 1 | Roundness: 5
54+
55+
#### **Path Curve Max Distance From Corner:**
56+
This `number` value determines the maximum value of a turn distance to a corner. The module default value is `10`. If this value equals `0` the path will not have any curve but you should set `settings_path_curve_roundness` to `0` if this is what you want.
57+
58+
<img src="examples/raw/max_10.jpg" alt="Max 10"/> | <img src="examples/raw/max_30.jpg" alt="Max 30"/> | <img src="examples/raw/max_50.jpg" alt="Max 50"/>
59+
:-------------: | :-------------: | :-------------:
60+
Max: 10 | Max: 30 | Max: 50
61+
62+
#### **Allow Enter on Route:**
63+
This `boolean` value determines is a game object can enter a map in the middle of a route or is should enter it from corners only. The module default value is `true`.
64+
65+
<img src="examples/raw/allow_false.jpg" alt="False"/> | <img src="examples/raw/allow_true.jpg" alt="True"/>
66+
:-------------: | :-------------:
67+
False | True
68+
3369
## Functions
3470
These are the list of available functions to use, for better understanding of how this module works, please take a look at project example.
3571

72+
---
73+
### map_set_properties([settings_go_threshold], [settings_path_curve_tightness], [settings_path_curve_roundness], [settings_path_curve_max_distance_from_corner], [settings_allow_enter_on_route])
74+
Set the main path and move calculation properties, nil inputs will fall back to module default values. These values will overwrite default module values.
75+
#### **arguments:**
76+
* `optional number` settings_go_threshold `[default = 1]`
77+
* `optional number` settings_path_curve_tightness `[default = 4]`
78+
* `optional number` settings_path_curve_roundness `[default = 3]`
79+
* `optional number` settings_path_curve_max_distance_from_corner `[default = 10]`
80+
* `optional boolean` settings_allow_enter_on_route `[default = true]`
81+
---
3682
### map_add_node(position)
37-
Adding a node at the given position (position.z will get ignored)
38-
**arguments:** position as vector3
39-
**return:** Newly added node id as number
40-
41-
### map_add_route(source_id, destination_id)
42-
Adding a two-way route between nodes with ids of source_id and destination_id
43-
**arguments:** source_id as number, destination_id as number
44-
45-
### map_remove_route(source_id, destination_id)
46-
Removing an existing route between nodes with ids of source_id and destination_id
47-
**arguments:** source_id as number, destination_id as number
48-
49-
### move_initialize(source_position, destination_id)
50-
initialize moves from source_position to a node with an id of destination_id inside the created map
51-
**arguments:** source_position as vector3, destination_id as number
52-
**return:** special movement data as table
83+
Adding a node at the given position (position.z will get ignored).
84+
#### **arguments:**
85+
* `vector3` position
86+
#### **return:**
87+
* `number` Newly added node id
88+
89+
> **Note:** Single nodes with no route attached to them are not participating in any routing calculations and it's better to remove them if you are not using them.
90+
---
91+
### map_add_route(source_id, destination_id, is_one_way)
92+
Adding a two-way route between two nodes, you can set it as one way or two way.
93+
#### **arguments:**
94+
* `number` source_id
95+
* `number` destination_id
96+
* `optional boolean` is_one_way `[false]`
97+
98+
> **Note:** If you never need to get pathfinding result in two way it's better to use a one-way path because it will be a bit computationally lighter.
99+
---
100+
### map_remove_route(source_id, destination_id, is_remove_one_way)
101+
Removing an existing route between two nodes, you can set it to remove just one way or both ways.
102+
#### **arguments:**
103+
* `number` source_id
104+
* `number` destination_id
105+
* `optional boolean` is_remove_one_way `[false]`
106+
---
107+
### map_remove_node(node_id)
108+
Removing an existing node, attached routes to this node will remove.
109+
#### **arguments:**
110+
* `number` node_id
111+
---
112+
### map_update_node_position(node_id, position)
113+
Update an existing node position.
114+
#### **arguments:**
115+
* `number` node_id
116+
* `vector3` position
117+
---
118+
### move_initialize(source_position, destination_id, initial_face_vector, settings_go_threshold, settings_path_curve_tightness, settings_path_curve_roundness, settings_path_curve_max_distance_from_corner, settings_allow_enter_on_route)
119+
Initialize moves from a source position to destination node inside the created map and using given threshold and initial face vector as game object initial face direction and path calculate settings, **the optional value will fall back to module default values.**
120+
#### **arguments:**
121+
* `vector3` source_position
122+
* `number` destination_id
123+
* `optional vecotr3` initial_face_vector
124+
* `optional number` settings_go_threshold
125+
* `optional number` settings_path_curve_tightness
126+
* `optional number` settings_path_curve_roundness
127+
* `optional number` settings_path_curve_max_distance_from_corner
128+
* `optional boolean` settings_allow_enter_on_route
129+
#### **return:**
130+
* `table` special movement data
53131
> **Note:** The returned special table consists of combined data to use later in `move_player` and `debug_draw_player_move` functions. If at any time you decided to change the destination of game object you have to call this function and overwrite old movement data with returned one.
54-
55-
### move_player(current_position, speed, threshold, move_data)
56-
calculate movements from current_position of the game object inside the created map considering given speed and threshold, using last calculated movement data
57-
**arguments:** current_position as vector3, speed as number, threshold as number, move_data as table
58-
**return:** new movement data as table, move result table like { `position`: next position of game object as vector3, `is_reached`: is game object reached the destination as boolean }
59-
> **Note:** The returned new movement data should overwrite old movement data. normally this function is placed inside go update function and you can set go position to `position` that is inside move result table. also, you should multiply `dt` with speed yourself before passing it to function.
60-
61-
### debug_set_properties(node_color, route_color, draw_scale)
132+
---
133+
### move_player(current_position, speed, move_data)
134+
Calculate movements from current position of the game object inside the created map considering given speed, using last calculated movement data.
135+
#### **arguments:**
136+
* `vector3` current_position
137+
* `number` speed
138+
* `table` move_data
139+
#### **return:**
140+
* `table` new movement data
141+
* `table` move result
142+
* `position`: `vector3` next position of game object
143+
* `rotation`: `quat` next rotation of game object
144+
* `is_reached`: `boolean` is game object reached the destination
145+
> **Note:** The returned new movement data should overwrite old movement data. normally this function is placed inside go update function and you can set go position to `position` and rotation to `rotation` that is inside move result table. also, you should multiply `dt` with speed yourself before passing it to function.
146+
---
147+
### debug_set_properties(node_color, two_way_route_color, one_way_route_color, draw_scale)
62148
set debug drawing properties
63-
**arguments:** node_color as vector4, route_color as vector4, draw_scale as number
64-
149+
#### **arguments:**
150+
* `optional vector4` node_color `[vector4(1, 0, 1, 1)]`
151+
* `optional vector4` two_way_route_color `[vector4(0, 1, 0, 1)]`
152+
* `optional vector4` one_way_route_color `[vector4(0, 1, 1, 1)]`
153+
* `optional number` draw_scale `[5]`
154+
---
65155
### debug_draw_map_nodes(is_show_ids)
66-
debug draw all map nodes and choose to show node ids or not
67-
**arguments:** is_show_ids as boolean
68-
156+
Debug draw all map nodes and choose to show node ids or not.
157+
#### **arguments:**
158+
* `optional boolean` is_show_ids `[false]`
159+
---
69160
### debug_draw_map_routes()
70-
debug draw all map routes
71-
72-
### debug_draw_player_move(movement_data, color)
73-
debug draw player route to destination with given color
74-
**arguments:** movement_data as table, color as vector4
161+
Debug draw all map routes.
162+
163+
---
164+
### debug_draw_player_move(movement_data, color, is_show_intersection)
165+
Debug draw player specific path with given color.
166+
#### **arguments:**
167+
* `table` movement_data
168+
* `vector4` color
169+
* `optional boolean` is_show_intersection `[false]`
170+
---

0 commit comments

Comments
 (0)