CAST II Game Engine

   MAIN       FEATURES       SCREENSHOTS       FORUMS       MANUAL       DOWNLOADS       CONTACTS   
Units
Class Hierarchy
Classes, Interfaces and Objects
Types
Enumerations
Variables
Constants
Functions and Procedures
Identifiers

Class TTimer

Unit

Timer

Declaration

type TTimer = class(TSubsystem)

Description

Timer service class

The class can be used to measure time intervals as well as to bind a message generation or a delegate call.
Default implementation uses GetPerformanceCounter from OSUtils if available or less precise GetCurrentMs() otherwise. A custom implemetation can be easily connected.
ToDo: Make the class thread-safe.

Fields

 NameDescription
PublicMaxIntervalThis variable limits the time interval on which recurring events will be processed to prevent too much computations when a lot of time passed since last Process() call. Default value is 3 seconds.
PublicTimerQueryFuncTimer query delegate. Can be overwritten to use a custom timer implementation

Methods

Overview

Publicconstructor Create(AMessageHandler: TMessageHandler);
Publicfunction GetInterval(var TimeMark: TTimeMark; ModifyMark: Boolean): TSecond;
Publicprocedure HandleMessage(const Msg: TMessage); override;
Publicfunction IsIntervalPassed(var TimeMark: TTimeMark; ModifyMark: Boolean; Interval: TSecond): Boolean;
Publicfunction Process: TSecond;
Publicprocedure RemoveRecurringEvent(EventID: Integer);
Publicprocedure SetEvent(const Delay: TSecond; Delegate: TTimerDelegate; EventID: Integer); overload;
Publicprocedure SetEvent(const Delay: TSecond; MessageClass: CMessage); overload;
Publicfunction SetRecurringEvent(const Delay: TSecond; MessageClass: CMessage): Integer; overload;
Publicfunction SetRecurringEvent(const Delay: TSecond; Delegate: TTimerDelegate; EventID: Integer): Integer; overload;
Publicprocedure SetRecurringEventInterval(EventID: Integer; const Delay: TSecond);

Description

Publicconstructor Create(AMessageHandler: TMessageHandler);

 

Publicfunction GetInterval(var TimeMark: TTimeMark; ModifyMark: Boolean): TSecond;

Returns time passed from previous call of the method with the same TimeMark variable and ModifyMark set to True. First call (with uninitialized TimeMark) returns 0 and performs initialization of the TimeMark.

Publicprocedure HandleMessage(const Msg: TMessage); override;

Message handler. No messages need to be handled so it's empty.

Publicfunction IsIntervalPassed(var TimeMark: TTimeMark; ModifyMark: Boolean; Interval: TSecond): Boolean;

Returns True if more then Intervak time passed from previous call of the method with the same TimeMark variable and ModifyMark set to True. First call (with uninitialized TimeMark) returns True and performs initialization of the TimeMark.

Publicfunction Process: TSecond;

Processes timer events and returns delay to the nearest event. Events will be processed and therefore can emerge only within this method.

Publicprocedure RemoveRecurringEvent(EventID: Integer);

Removes the specified recurring event

Publicprocedure SetEvent(const Delay: TSecond; Delegate: TTimerDelegate; EventID: Integer); overload;

Sets (binds) the specified delegate to call in Delay seconds. EventID is an application-specific identification number to supply the delegate with.

Publicprocedure SetEvent(const Delay: TSecond; MessageClass: CMessage); overload;

Sets (binds) a message of the specified class to generate in Delay seconds

Publicfunction SetRecurringEvent(const Delay: TSecond; MessageClass: CMessage): Integer; overload;

Sets (binds) a message of the specified class to generate every Delay seconds starting from the moment of call. Returns an ID of the new event.

Publicfunction SetRecurringEvent(const Delay: TSecond; Delegate: TTimerDelegate; EventID: Integer): Integer; overload;

Sets (binds) the specified delegate to call every Delay seconds starting from the moment of call. EventID is an application-specific identification number to supply the delegate with. Returns an ID of the new event.

Publicprocedure SetRecurringEventInterval(EventID: Integer; const Delay: TSecond);

Changes interval of the specified recurring event

Properties

Overview

Publicproperty TotalEvents: Integer;
Publicproperty TotalRecurringEvents: Integer;

Description

Publicproperty TotalEvents: Integer;

Number of active events not including recurring ones

Publicproperty TotalRecurringEvents: Integer;

Number of active recurring events

Last modified: Jan 6, 2010
Copyright (C) 2006-2010, casteng.com