delti 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: baa8b546cdb627f698c3ded90cb339d699ce3942c543a3364537e06debef989f
4
+ data.tar.gz: 1ba0362cf4f2200a51c2b5294e70c18bf7b2491078acc92f725dfd7340fde331
5
+ SHA512:
6
+ metadata.gz: 37eca05705283867e2e93eae1ce765a3d4841339889500252e5587c1dd8a20a17bb79582f391c8138f7a502910a485ccae92623d05505831a918fe74934f5dc6
7
+ data.tar.gz: ecb1aade7e3e1f2104bef919c821491ccfe5835afbd6f1cf504fbdf2db861cb339fd78fab6765e09fe797aa47be5b4c5bf4e5b7bde1f414c2c12315aa2e47ab9
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in delti.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Aaron Christiansen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Delti
2
+
3
+ Delti is a tiny library which provides you with the
4
+ **easiest imaginable delta time calculation for your loops**.
5
+
6
+ Writing a game engine, UI library, or intensive routine task, and need a delta
7
+ time? All you need to do is:
8
+
9
+ 1. `require 'delti'` in your file
10
+ 2. `include Delti` in your class or module
11
+ 3. Call `dt!` to get the time since the last `dt!` call in that location
12
+
13
+ The first call will always return nil, and subsequent calls return a Float of
14
+ the number of seconds since the last call.
15
+
16
+ You can use more than one `dt!` call at a time, and it'll always give you the
17
+ **delta time since THAT last call, indexed by source line and file**.
18
+
19
+ # Example
20
+
21
+ With just one use of `dt!`:
22
+
23
+ ```ruby
24
+ include Delti
25
+
26
+ loop do
27
+ sleep 1
28
+ p dt!
29
+ end
30
+
31
+ # Output:
32
+ # nil
33
+ # 1.0012476179981604
34
+ # 1.0011373269990145
35
+ # 1.0011775080020016
36
+ # 1.0012207549989398
37
+ # 1.0012018039997201
38
+ # 1.001209079000546
39
+ ```
40
+
41
+ With multiple uses of `dt!`, each keeping track of their own time:
42
+
43
+ ```ruby
44
+ include Delti
45
+
46
+ Thread.new do
47
+ loop do
48
+ sleep 2
49
+ p dt!
50
+ end
51
+ end
52
+
53
+ Thread.new do
54
+ loop do
55
+ sleep 1
56
+ p dt!
57
+ end
58
+ end
59
+
60
+ loop {} # to prevent exit
61
+
62
+ # Output:
63
+ # nil
64
+ # nil
65
+ # 1.100102615000651
66
+ # 1.0001914450003824
67
+ # 2.0021415269984573
68
+ # 1.1020770069990249
69
+ # 1.1002259790002427
70
+ # 2.101181769001414
71
+ ```
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/AaronC81/delti.
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/delti.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "delti"
3
+ spec.version = "1.0.0"
4
+ spec.authors = ["Aaron Christiansen"]
5
+ spec.email = ["hello@aaronc.cc"]
6
+
7
+ spec.summary = "Effortless delta time calculation within loops"
8
+ spec.homepage = "https://github.com/AaronC81/delti"
9
+ spec.license = "MIT"
10
+
11
+ spec.metadata["homepage_uri"] = spec.homepage
12
+ spec.metadata["source_code_uri"] = spec.homepage
13
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 2.0"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
data/lib/delti.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Delti
2
+ def dt!
3
+ @_delta_table ||= {}
4
+ key = Kernel.caller.first
5
+
6
+ last = @_delta_table[key]
7
+ if last.nil?
8
+ @_delta_table[key] = Process.clock_gettime(Process::CLOCK_MONOTONIC)
9
+ nil
10
+ else
11
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
12
+ delta = now - last
13
+ @_delta_table[key] = now
14
+ delta
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delti
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Christiansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - hello@aaronc.cc
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - delti.gemspec
54
+ - lib/delti.rb
55
+ homepage: https://github.com/AaronC81/delti
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ homepage_uri: https://github.com/AaronC81/delti
60
+ source_code_uri: https://github.com/AaronC81/delti
61
+ changelog_uri: https://github.com/AaronC81/delti/CHANGELOG.md
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.0.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Effortless delta time calculation within loops
81
+ test_files: []