behavior_machines 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec761ecd4fe6d6f47c9441607ef0df573a49ec611d96f113f46547e7872b219d
4
- data.tar.gz: 16be482a97faa6d3807aa41cc66d4e1088a1e0732f11ad12cfcb53e70e0fdc32
3
+ metadata.gz: b1d28d3451daf3c9ee0e657cdb6275daaea60b11106ed9664dcc37f333f32a0e
4
+ data.tar.gz: f540b2225acde186a6a2388bf71f0675be690a3f14f2297c4e118627b18e86a8
5
5
  SHA512:
6
- metadata.gz: 446b75ee20966a1564d2669645018c06dab4a2ce535ae2f57a6bdb070d1ec628e99dd29812ca32168103da2f9cbcefb46311557d3631b718844fe49b8a230d79
7
- data.tar.gz: 3a0e4f7c47e9b787c95d1ab4a2c9dbe71205f46bedc291153a698093affc6d5d874789187fba678b7595ae1efe05e020236c48131889d63210adfd77be506266
6
+ metadata.gz: 05307bd138c558b175edac91f692a5cb281565a597e763cfb590c5183e0863a41708a588dc0594c1b20dcc6feb503f2be6456c470fb67fb457cf99c7c766c5bb
7
+ data.tar.gz: 57ca3bfe22f77525cd90738a5dab4dc0d8922c6bc7d6a8f4d7a8120e795e95f0ba58cca10d19ebdeb0c3122d766a4ad48b4c33b592ff932d230de636a701e4b3
data/README.md CHANGED
@@ -68,7 +68,8 @@ compiles them.
68
68
  Durations are seconds. The clock is an Integer count of nanoseconds, passed as
69
69
  `now:` and defaulting to `BehaviorMachines.now` (monotonic).
70
70
  `tree.next_deadline` returns when a running `sleep` or `timeout` next needs a
71
- tick, so a host can sleep until then.
71
+ tick, so a host can sleep until then. A looping decorator that finished a run
72
+ reports that tick's time, so its next run is due at once.
72
73
 
73
74
  ## Errors
74
75
 
@@ -121,6 +122,24 @@ $ BEHAVIOR_MACHINES_NATIVE=1 ruby app.rb
121
122
  Leaves stay Ruby, so the gain is limited to the tree walk itself. The test
122
123
  suite runs against both backends (`bundle exec rake test:both`).
123
124
 
125
+ ## Releases
126
+
127
+ Release Please manages the Ruby gem and both publishable Rust crates. Use
128
+ conventional commits and merge its release PR to update versions, changelogs,
129
+ the release manifest, and workspace dependency requirements. Do not push
130
+ hand-written version bumps or changelog entries.
131
+
132
+ The release manifest records the last released version of each package, not
133
+ the next planned version. Circuit is registered at its published `0.1.0`;
134
+ its one-time `release-as` override requests `0.3.0` in the next release PR.
135
+ Remove that override from `release-please-config.json` after the release so
136
+ later versions are calculated from conventional commits.
137
+
138
+ Crate-only releases do not trigger Ruby gem publishing. The workflow creates
139
+ GitHub releases for the crates but does not upload them to crates.io. After
140
+ merging the release PR and checking out its release tag, run the Rust tests
141
+ and a `cargo publish --dry-run` for the relevant crate before publishing.
142
+
124
143
  ## License
125
144
 
126
145
  BSD-3-Clause. See [LICENSE](LICENSE).
@@ -441,7 +441,7 @@ module BehaviorMachines
441
441
  end
442
442
 
443
443
  # Repeat, RetryUntilSuccessful, and KeepRunningUntilFailure: at most one
444
- # finished child run per tick.
444
+ # finished child run per tick; the next run is due at once.
445
445
  class LoopSlot < Slot
446
446
  def initialize(id, child, again_on, limit)
447
447
  super(id)
@@ -449,20 +449,28 @@ module BehaviorMachines
449
449
  @again_on = again_on
450
450
  @limit = limit
451
451
  @runs = 0
452
+ @due = nil
452
453
  end
453
454
 
454
455
  private
455
456
 
456
457
  def step(run, now, _starting)
458
+ @due = nil
457
459
  return @again_on if @limit&.zero?
458
460
 
459
461
  status = @child.tick(run, now)
460
462
  return status if status == :running
461
463
  return finish(status) unless status == @again_on
462
- return :running if @limit.nil?
464
+ return again(now) if @limit.nil?
463
465
  return finish(status) if @runs + 1 == @limit
464
466
 
465
467
  @runs += 1
468
+ again(now)
469
+ end
470
+
471
+ # A run finished and the next waits for a tick: due at once.
472
+ def again(now)
473
+ @due = now
466
474
  :running
467
475
  end
468
476
 
@@ -476,7 +484,7 @@ module BehaviorMachines
476
484
  @runs = 0
477
485
  end
478
486
 
479
- def running_deadline = @child.next_deadline
487
+ def running_deadline = earliest([@due, @child.next_deadline])
480
488
  end
481
489
  end
482
490
  end
@@ -37,6 +37,7 @@ module BehaviorMachines
37
37
  # `ticked(node_id, status)` and `halted(node_id)`; node ids number the
38
38
  # definition in pre-order, and children report before their parent.
39
39
  def tick(ctx = nil, now: BehaviorMachines.now, observer: nil)
40
+ DeadlineMachines.check!
40
41
  now = BehaviorMachines.check_time(now)
41
42
  exclusive { @engine.tick(ctx, now, Observers.wrap(observer)) }
42
43
  end
@@ -53,7 +54,8 @@ module BehaviorMachines
53
54
  @engine.running?
54
55
  end
55
56
 
56
- # The earliest time, in nanoseconds, a running Sleep or Timeout will fire.
57
+ # The earliest time, in nanoseconds, a running Sleep or Timeout will fire,
58
+ # or a looping decorator wants its next run (already due).
57
59
  def next_deadline
58
60
  check_idle
59
61
  @engine.next_deadline
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BehaviorMachines
4
- VERSION = '0.1.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -7,6 +7,8 @@ require_relative 'behavior_machines/definition'
7
7
  require_relative 'behavior_machines/engine'
8
8
  require_relative 'behavior_machines/tree'
9
9
  require_relative 'behavior_machines/machine'
10
+ require 'deadline_machines'
11
+
10
12
  require_relative 'behavior_machines/native_extension'
11
13
 
12
14
  # Behavior trees with explicit halt semantics, following the behavior-tree
@@ -15,8 +17,8 @@ module BehaviorMachines
15
17
  STATUSES = %i[success failure running].freeze
16
18
 
17
19
  class << self
18
- # The current monotonic time in nanoseconds.
19
- def now = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
20
+ # The current monotonic time in nanoseconds, from the family's clock.
21
+ def now = DeadlineMachines.clock.now_ns
20
22
 
21
23
  # Whether the native backend is loaded (opt-in, see NativeExtension).
22
24
  def native_available? = NativeExtension.loaded?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: behavior_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -9,6 +9,20 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: deadline_machines
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0.1'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: state_machines
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -16,7 +30,7 @@ dependencies:
16
30
  - - ">="
17
31
  - !ruby/object:Gem::Version
18
32
  version: '0.202'
19
- type: :runtime
33
+ type: :development
20
34
  prerelease: false
21
35
  version_requirements: !ruby/object:Gem::Requirement
22
36
  requirements:
@@ -102,13 +116,13 @@ files:
102
116
  - lib/behavior_machines/node.rb
103
117
  - lib/behavior_machines/tree.rb
104
118
  - lib/behavior_machines/version.rb
105
- homepage: https://github.com/seuros/behavior-machines
119
+ homepage: https://github.com/seuros/behavior_machines
106
120
  licenses:
107
121
  - BSD-3-Clause
108
122
  metadata:
109
- homepage_uri: https://github.com/seuros/behavior-machines
110
- source_code_uri: https://github.com/seuros/behavior-machines
111
- bug_tracker_uri: https://github.com/seuros/behavior-machines/issues
123
+ homepage_uri: https://github.com/seuros/behavior_machines
124
+ source_code_uri: https://github.com/seuros/behavior_machines
125
+ bug_tracker_uri: https://github.com/seuros/behavior_machines/issues
112
126
  rubygems_mfa_required: 'true'
113
127
  cargo_crate_name: behavior_machines_native
114
128
  cargo_manifest_path: ext/behavior_machines_native/ffi/Cargo.toml