Oolite
Loading...
Searching...
No Matches
OOJSClock.m File Reference
Include dependency graph for OOJSClock.m:

Go to the source code of this file.

Enumerations

enum  {
  kClock_absoluteSeconds , kClock_seconds , kClock_minutes , kClock_hours ,
  kClock_days , kClock_secondsComponent , kClock_minutesComponent , kClock_hoursComponent ,
  kClock_daysComponent , kClock_clockString , kClock_isAdjusting , kClock_adjustedSeconds ,
  kClock_legacy_scriptTimer
}

Functions

static JSValue ClockGetProperty (OOJS_GETTER_ARGS)
static JSValue JSClockToString (OOJS_NATIVE_ARGS)
static JSValue ClockClockStringForTime (OOJS_NATIVE_ARGS)
static JSValue ClockAddSeconds (OOJS_NATIVE_ARGS)
void InitOOJSClock (JSContext *context, JSValueConst global)

Variables

static JSClassID sClockClassID
static JSClassDef sClockClass
static const JSCFunctionListEntry sClockProperties []
static const JSCFunctionListEntry sClockMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kClock_absoluteSeconds 
kClock_seconds 
kClock_minutes 
kClock_hours 
kClock_days 
kClock_secondsComponent 
kClock_minutesComponent 
kClock_hoursComponent 
kClock_daysComponent 
kClock_clockString 
kClock_isAdjusting 
kClock_adjustedSeconds 
kClock_legacy_scriptTimer 

Definition at line 47 of file OOJSClock.m.

47 {
48 // Property IDs
49 kClock_absoluteSeconds, // game real time clock, double, read-only
50 kClock_seconds, // game clock time, double, read-only
51 kClock_minutes, // game clock time minutes (rounded down), integer double, read-only
52 kClock_hours, // game clock time hours (rounded down), integer double, read-only
53 kClock_days, // game clock time days (rounded down), int, read-only
54 kClock_secondsComponent, // second component of game clock time, double, read-only
55 kClock_minutesComponent, // minute component of game clock time (rounded down), int, read-only
56 kClock_hoursComponent, // hour component of game clock time (rounded down), int, read-only
57 kClock_daysComponent, // day component of game clock time (rounded down), int, read-only
58 kClock_clockString, // game clock time as display string, string, read-only
59 kClock_isAdjusting, // clock is adjusting, boolean, read-only
60 kClock_adjustedSeconds, // game clock time, including adjustments, double, read-only
61 kClock_legacy_scriptTimer // legacy scriptTimer_number, double, read-only
62};
@ kClock_absoluteSeconds
Definition OOJSClock.m:59
@ kClock_isAdjusting
Definition OOJSClock.m:69
@ kClock_daysComponent
Definition OOJSClock.m:67
@ kClock_adjustedSeconds
Definition OOJSClock.m:70
@ kClock_days
Definition OOJSClock.m:63
@ kClock_seconds
Definition OOJSClock.m:60
@ kClock_clockString
Definition OOJSClock.m:68
@ kClock_hours
Definition OOJSClock.m:62
@ kClock_secondsComponent
Definition OOJSClock.m:64
@ kClock_hoursComponent
Definition OOJSClock.m:66
@ kClock_minutes
Definition OOJSClock.m:61
@ kClock_minutesComponent
Definition OOJSClock.m:65
@ kClock_legacy_scriptTimer
Definition OOJSClock.m:71

Function Documentation

◆ ClockAddSeconds()

JSValue ClockAddSeconds ( OOJS_NATIVE_ARGS )
static

Definition at line 190 of file OOJSClock.m.

191{
192 OOJS_NATIVE_ENTER(context)
193
194 double time;
195 const double kMaxTime = 30.0 * 24.0 * 3600.0; // 30 days
196
197 if (EXPECT_NOT(argc < 1 || JS_ToFloat64(context, &time, OOJS_ARGV[0]) < 0)) {
198 if (JS_HasException(context))
199 JS_FreeValue(context, JS_GetException(context));
200 JSValueConst arg = JS_UNDEFINED;
201 if (argc > 0)
202 arg = OOJS_ARGV[0];
203 OOJSReportBadArguments(context, @"Clock", @"addSeconds", 1, &arg, nil, @"number");
204 return JS_EXCEPTION;
205 }
206
207 if (time > kMaxTime || time < 1.0 || !isfinite(time)) {
209 }
210
212
213 OOJS_RETURN_BOOL(YES);
214
216}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_RETURN_BOOL(v)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
return nil
void addToAdjustTime:(double seconds)

References PlayerEntity::addToAdjustTime:, EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ClockClockStringForTime()

JSValue ClockClockStringForTime ( OOJS_NATIVE_ARGS )
static

Definition at line 168 of file OOJSClock.m.

169{
170 OOJS_NATIVE_ENTER(context)
171
172 double time;
173
174 if (EXPECT_NOT(argc < 1 || JS_ToFloat64(context, &time, OOJS_ARGV[0]) < 0)) {
175 if (JS_HasException(context))
176 JS_FreeValue(context, JS_GetException(context));
177 JSValueConst arg = JS_UNDEFINED;
178 if (argc > 0)
179 arg = OOJS_ARGV[0];
180 OOJSReportBadArguments(context, @"Clock", @"clockStringForTime", 1, &arg, nil, @"number");
181 return JS_EXCEPTION;
182 }
183
185
187}
#define OOJS_RETURN_OBJECT(o)
NSString * ClockToString(double clock, BOOL adjusting)

References ClockToString(), EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ClockGetProperty()

JSValue ClockGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 96 of file OOJSClock.m.

97{
98 OOJS_NATIVE_ENTER(context)
99
101 double clockTime;
102
103 clockTime = [player clockTime];
104
105 /* INT_TO_JSVAL() truncated its (double) argument to an integer; JS_NewInt32()
106 does the same through the implicit conversion.
107 */
108 switch (magic) {
110 return JS_NewNumber(context, [UNIVERSE getTime]);
111
112 case kClock_seconds:
113 return JS_NewNumber(context, clockTime);
114
115 case kClock_minutes:
116 return JS_NewNumber(context, floor(clockTime / 60.0));
117
118 case kClock_hours:
119 return JS_NewNumber(context, floor(clockTime / 3600.0));
120
122 return JS_NewInt32(context, fmod(clockTime, 60.0));
123
125 return JS_NewInt32(context, fmod(floor(clockTime / 60.0), 60.0));
126
128 return JS_NewInt32(context, fmod(floor(clockTime / 3600.0), 24.0));
129
130 case kClock_days:
132 return JS_NewInt32(context, floor(clockTime / 86400.0));
133
135 return OOJSValueFromNativeObject(context, [player dial_clock]);
136
138 return OOJSValueFromBOOL([player clockAdjusting]);
139
141 return JS_NewNumber(context, [player clockTimeAdjusted]);
142
144 OOStandardsDeprecated(@"The legacy_scriptTimer property is deprecated");
145 return JS_NewNumber(context, [player scriptTimer]);
146
147 default:
149 return JS_EXCEPTION;
150 }
151
153}
void OOStandardsDeprecated(NSString *message)
static JSPropertySpec sClockProperties[]
Definition OOJSClock.m:74
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:175
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
#define OOJS_COUNT(array)
#define UNIVERSE
Definition Universe.h:827

References PlayerEntity::clockTime, kClock_absoluteSeconds, kClock_adjustedSeconds, kClock_clockString, kClock_days, kClock_daysComponent, kClock_hours, kClock_hoursComponent, kClock_isAdjusting, kClock_legacy_scriptTimer, kClock_minutes, kClock_minutesComponent, kClock_seconds, kClock_secondsComponent, OOJS_COUNT, OOJS_GETTER_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), OOPlayerForScripting(), OOStandardsDeprecated(), sClockProperties, and UNIVERSE.

Here is the call graph for this function:

◆ InitOOJSClock()

void InitOOJSClock ( JSContext * context,
JSValueConst global )

Definition at line 88 of file OOJSClock.m.

89{
91 JSValueConst clockPrototype = OOJSInitClass(context, global, sClockClassID, JS_UNDEFINED, OOJSUnconstructableConstruct, 0,
93 JS_DefinePropertyValueStr(context, global, "clock", JS_NewObjectProtoClass(context, clockPrototype, sClockClassID), OOJS_PROP_READONLY);
94}
static JSClass sClockClass
Definition OOJSClock.m:42
static JSFunctionSpec sClockMethods[]
Definition OOJSClock.m:92
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
static JSClassID sClockClassID
Definition OOJSClock.m:42
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
Definition OOJSClasses.m:61
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)

References OOJS_COUNT, OOJS_PROP_READONLY, OOJSInitClass(), OOJSRegisterClass(), OOJSUnconstructableConstruct(), sClockClass, sClockClassID, sClockMethods, and sClockProperties.

Here is the call graph for this function:

◆ JSClockToString()

JSValue JSClockToString ( OOJS_NATIVE_ARGS )
static

Definition at line 158 of file OOJSClock.m.

159{
160 OOJS_NATIVE_ENTER(context)
161
163
165}

References OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and OOPlayerForScripting().

Here is the call graph for this function:

Variable Documentation

◆ sClockClass

JSClassDef sClockClass
static
Initial value:
= {
.class_name = "Clock",
}

Definition at line 43 of file OOJSClock.m.

43 {
44 .class_name = "Clock",
45};

◆ sClockClassID

JSClassID sClockClassID
static

Definition at line 42 of file OOJSClock.m.

Referenced by InitOOJSClock().

◆ sClockMethods

const JSCFunctionListEntry sClockMethods[]
static
Initial value:
= {
JS_CFUNC_DEF("toString", 0, JSClockToString),
JS_CFUNC_DEF("clockStringForTime", 1, ClockClockStringForTime),
JS_CFUNC_DEF("addSeconds", 1, ClockAddSeconds),
}
static JSBool ClockClockStringForTime(JSContext *context, uintN argc, jsval *vp)
Definition OOJSClock.m:185
static JSBool ClockAddSeconds(JSContext *context, uintN argc, jsval *vp)
Definition OOJSClock.m:205
static JSBool JSClockToString(JSContext *context, uintN argc, jsval *vp)
Definition OOJSClock.m:175

Definition at line 81 of file OOJSClock.m.

81 {
82 // JS name Function min args
83 JS_CFUNC_DEF("toString", 0, JSClockToString),
84 JS_CFUNC_DEF("clockStringForTime", 1, ClockClockStringForTime),
85 JS_CFUNC_DEF("addSeconds", 1, ClockAddSeconds),
86};

◆ sClockProperties

const JSCFunctionListEntry sClockProperties[]
static
Initial value:

Definition at line 64 of file OOJSClock.m.