GithubHelp home page GithubHelp logo

stereoket / tiaccuratetimer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jaraen/tiaccuratetimer

1.0 2.0 0.0 194 KB

An accurate iOS timer module for Titanium that improves the JavaScript setInterval and setTimeout functions. Valid for basic media applications and games.

License: Apache License 2.0

JavaScript 7.11% Objective-C 39.85% Python 53.04%

tiaccuratetimer's Introduction

Accurate Timer Module

version 1.2, 2015, jan: open sourced
version 1.0, 2012, jun

Description

An accurate timer module for iOS with milliseconds precision, mostly written in pure C.

JavaScript's setInterval() function has a low precision timer and, even worst, accumulates its time error on each iteration, which results in a total lost of synchronization on any timing operation in just a few seconds (think in a metronome or similar).

AccurateTimer solves this and ensures that your callback function is called with the delay you expect, executed from a low level high priority function.

AccurateTimer has been developed with accuracy and performance in mind. The user callback function is executed with the minimum load to avoid undesired delays. However, keep in mind that once the Titanium callback function is executed, performance depends on Javascript runtime machine and therefore on the complexity of your function. Keep your callback function lightweight, loading previously into memory resources such as images and sounds you will manage from the callback function.

The module internally works with a unit slower than miliseconds (actually, at microseconds) so, even if your function introduces any delay on its execution, AccurateTimer should keep calling the interval callback with a precission of milliseconds.

Accessing the timer Module

Include it in you tiapp.xml file

<module platform="iphone">com.accuratetimer</module>

To access this module from JavaScript, you would do the following:

	var timer = require("com.accuratetimer");

The timer variable is a reference to the Module object.

Reference

accurateTimer.setInterval()

Configures the timer for interval operations. Receives a dictionary with two objects: callback and delay.

SetInterval does not start automatically the timer. Call start() method to run the timer.

	timer.setInterval({
		callback: yourCallbackFunction,
		delay: delayInMilliSeconds
	});

note that delay is an integer number of milliseconds between each interval.

accurateTimer.setTimeout()

Configures the timer for a timeout operation, calling the callback function after the delay time. Receives a dictionary with two objects: callback and delay.

setTimeout starts automatically, so there's no need to call start()

	timer.setTimeout({
		callback: yourCallbackFunction,
		delay: delayInMilliSeconds
	});

note that delay is an integer number of milliseconds between each interval.

accurateTimer.start()

starts the timer calling the callback function each delay milliseconds defined with setInterval()

accurateTimer.stop()

stops the timer.

accurateTimer.logTimeStamp()

Prints in console the current time system since 00:00:00 1 January 2001 in seconds with 6 decimals (microseconds precision)

accurateTimer.getTimeStamp()

Returns a double number with the current time system since 00:00:00 1 January 2001 in seconds with 6 decimals (microseconds precision)

accurateTimer.delay

Delay property in milliseconds.

Usage

see example folder.

Author

Javier Rayon, 2012-2015 (Criteria Studio) Twitter: @jrayon

License

Code released under Apache license 2.0 (formerly was under commercial license).

You can use it for commercial projects, open source projects, or really just about whatever you want.

Code is provided as it is, no support or maitainance is guaranteed.

tiaccuratetimer's People

Contributors

jaraen avatar

Stargazers

Ket Majmudar avatar

Watchers

Ket Majmudar avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.