Figments-of-the-Night/addons/inkgd/runtime/extra/stopwatch.gd
Gerard Gascón b99855351d init
2025-04-24 17:23:34 +02:00

34 lines
1 KiB
GDScript

# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
# Simple replacement of the Stopwatch class from the .NET Framework.
# Less accurate than the original implemntation, but good enough for
# the use-case.
class_name InkStopWatch
# ############################################################################ #
var _start_time: int = -1
var elapsed_milliseconds : get = get_elapsed_milliseconds
func get_elapsed_milliseconds() -> int:
if _start_time == -1:
return 0
return Time.get_ticks_msec() - _start_time
# ############################################################################ #
func start() -> void:
_start_time = Time.get_ticks_msec()
func stop() -> void:
_start_time = -1