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

Go to the source code of this file.

Enumerations

enum  { kSound_name }

Functions

static OOSound * GetNamedSound (NSString *name)
static JSBool SoundGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool SoundStaticLoad (JSContext *context, uintN argc, jsval *vp)
static JSBool SoundStaticMusicSoundSource (JSContext *context, uintN argc, jsval *vp)
static JSBool SoundStaticPlayMusic (JSContext *context, uintN argc, jsval *vp)
static JSBool SoundStaticStopMusic (JSContext *context, uintN argc, jsval *vp)
void InitOOJSSound (JSContext *context, JSObject *global)
OOSound * SoundFromJSValue (JSContext *context, jsval value)

Variables

static JSObject * sSoundPrototype
static JSClass sSoundClass
static JSPropertySpec sSoundProperties []
static JSFunctionSpec sSoundMethods []
static JSFunctionSpec sSoundStaticMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSound_name 

Definition at line 58 of file OOJSSound.m.

58 {
59 // Property IDs
61};
@ kSound_name
Definition OOJSSound.m:60

Function Documentation

◆ GetNamedSound()

OOSound * GetNamedSound ( NSString * name)
static

Definition at line 156 of file OOJSSound.m.

157{
158 OOSound* sound = nil;
159
160 if ([name hasPrefix:@"["] && [name hasSuffix:@"]"]) {
161 sound = [OOSound soundWithCustomSoundKey:name];
162 } else {
163 sound = [ResourceManager ooSoundNamed:name inFolder:@"Sounds"];
164 }
165
166 return sound;
167}
return nil
id soundWithCustomSoundKey:(NSString *key)
Definition Universe.m:9950
OOSound * ooSoundNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

References nil, ResourceManager::ooSoundNamed:inFolder:, and OOSound::soundWithCustomSoundKey:.

Referenced by SoundFromJSValue(), SoundFromJSValue(), SoundStaticLoad(), and SoundStaticLoad().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitOOJSSound()

void InitOOJSSound ( JSContext * context,
JSObject * global )

Definition at line 108 of file OOJSSound.m.

109{
112}
static JSObject * sSoundPrototype
Definition OOJSSound.m:31
static JSPropertySpec sSoundProperties[]
Definition OOJSSound.m:63
static JSFunctionSpec sSoundMethods[]
Definition OOJSSound.m:69
static JSFunctionSpec sSoundStaticMethods[]
Definition OOJSSound.m:79
static JSClass sSoundClass
Definition OOJSSound.m:43
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)

References InitOOJSSound(), OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSUnconstructableConstruct(), sSoundClass, sSoundMethods, sSoundProperties, sSoundPrototype, and sSoundStaticMethods.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext, InitOOJSSound(), and InitOOJSSound().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SoundFromJSValue()

OOSound * SoundFromJSValue ( JSContext * context,
jsval value )

Definition at line 114 of file OOJSSound.m.

115{
117
119 if ([PLAYER status] != STATUS_START_GAME && JSVAL_IS_STRING(value)) {
120 return GetNamedSound(OOStringFromJSValue(context, value));
121 } else {
122 return OOJSNativeObjectOfClassFromJSValue(context, value, [OOSound class]);
123 }
125
127}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
static OOSound * GetNamedSound(NSString *name)
Definition OOJSSound.m:156
void OOJSPauseTimeLimiter(void)
id OOJSNativeObjectOfClassFromJSValue(JSContext *context, jsval value, Class requiredClass)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
#define PLAYER

References GetNamedSound(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSNativeObjectOfClassFromJSValue(), OOJSPauseTimeLimiter(), OOJSResumeTimeLimiter(), OOStringFromJSValue(), and PLAYER.

Here is the call graph for this function:

◆ SoundGetProperty()

JSBool SoundGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 131 of file OOJSSound.m.

132{
133 if (!JSID_IS_INT(propID))
134 return YES;
135
136 OOJS_NATIVE_ENTER(context)
137
138 OOSound* sound = nil;
139
140 if (EXPECT_NOT(!JSSoundGetSound(context, this, &sound)))
141 return NO;
142
143 switch (JSID_TO_INT(propID)) {
144 case kSound_name:
145 *value = OOJSValueFromNativeObject(context, [sound name]);
146 return YES;
147
148 default:
149 OOJSReportBadPropertySelector(context, this, propID, sSoundProperties);
150 return NO;
151 }
152
154}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)

References EXPECT_NOT, kSound_name, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromNativeObject(), and sSoundProperties.

Here is the call graph for this function:

◆ SoundStaticLoad()

JSBool SoundStaticLoad ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 172 of file OOJSSound.m.

173{
174 OOJS_NATIVE_ENTER(context)
175
176 NSString* name = nil;
177 OOSound* sound = nil;
178
179 if (argc > 0)
180 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
181 if (name == nil) {
182 OOJSReportBadArguments(context, @"Sound", @"load", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
183 return NO;
184 }
185
187 sound = GetNamedSound(name);
189
190 OOJS_RETURN_OBJECT(sound);
191
193}
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_RETURN_OBJECT(o)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define MIN(A, B)
Definition OOMaths.h:91

References GetNamedSound(), MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ SoundStaticMusicSoundSource()

JSBool SoundStaticMusicSoundSource ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 195 of file OOJSSound.m.

196{
197 OOJS_NATIVE_ENTER(context)
198 OOSoundSource* musicSource = nil;
202 OOJS_RETURN_OBJECT(musicSource);
204}
OOMusicController * sharedController()
OOSoundSource * soundSource()

References nil, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOMusicController::sharedController, and OOMusicController::soundSource.

Here is the call graph for this function:

◆ SoundStaticPlayMusic()

JSBool SoundStaticPlayMusic ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 207 of file OOJSSound.m.

208{
209 OOJS_NATIVE_ENTER(context)
210
211 NSString* name = nil;
212 JSBool loop = NO;
213 double gain = OO_DEFAULT_SOUNDSOURCE_GAIN;
214
215 if (argc > 0)
216 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
217 if (name == nil) {
218 OOJSReportBadArguments(context, @"Sound", @"playMusic", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
219 return NO;
220 }
221 if (argc > 1) {
222 if (!JS_ValueToBoolean(context, OOJS_ARGV[1], &loop)) {
223 OOJSReportBadArguments(context, @"Sound", @"playMusic", 1, OOJS_ARGV + 1, nil, @"boolean");
224 return NO;
225 }
226 }
227
228 if (argc > 2) {
229 if (!OOJSArgumentListGetNumber(context, @"Sound", @"playMusic", 2, OOJS_ARGV + 2, &gain, NULL)) {
230 OOJSReportBadArguments(context, @"Sound", @"playMusic", 1, OOJS_ARGV + 2, nil, @"float");
231 return NO;
232 }
233 }
234
238
240
242}
BOOL OOJSArgumentListGetNumber(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
#define OOJS_RETURN_VOID
void playMusicNamed:loop:gain:(NSString *name,[loop] BOOL loop,[gain] float gain)

References MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSArgumentListGetNumber(), OOJSReportBadArguments(), OOStringFromJSValue(), OOMusicController::playMusicNamed:loop:gain:, and OOMusicController::sharedController.

Here is the call graph for this function:

◆ SoundStaticStopMusic()

JSBool SoundStaticStopMusic ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 245 of file OOJSSound.m.

246{
247 OOJS_NATIVE_ENTER(context)
248
249 NSString* name = nil;
250
251 if (argc > 0) {
252 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
253 if (EXPECT_NOT(name == nil)) {
254 OOJSReportBadArguments(context, @"Sound", @"stopMusic", argc, OOJS_ARGV, nil, @"string or no argument");
255 return NO;
256 }
257 }
258
261 if (name == nil || [name isEqualToString:[controller playingMusic]]) {
263 }
265
267
269}

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSReportBadArguments(), OOStringFromJSValue(), OOMusicController::sharedController, and OOMusicController::stop.

Here is the call graph for this function:

Variable Documentation

◆ sSoundClass

JSClass sSoundClass
static
Initial value:
= {
"Sound",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool SoundGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSSound.m:131
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 43 of file OOJSSound.m.

43 {
44 "Sound",
45 JSCLASS_HAS_PRIVATE,
46
47 JS_PropertyStub, // addProperty
48 JS_PropertyStub, // delProperty
49 SoundGetProperty, // getProperty
50 JS_StrictPropertyStub, // setProperty
51 JS_EnumerateStub, // enumerate
52 JS_ResolveStub, // resolve
53 JS_ConvertStub, // convert
54 OOJSObjectWrapperFinalize, // finalize
55 JSCLASS_NO_OPTIONAL_MEMBERS
56};

Referenced by InitOOJSSound(), InitOOJSSound(), and OOSound(OOJavaScriptExtentions)::oo_jsValueInContext:.

◆ sSoundMethods

JSFunctionSpec sSoundMethods[]
static
Initial value:
= {
{
"toString",
0,
},
{ 0 }
}
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)

Definition at line 69 of file OOJSSound.m.

69 {
70 // JS name Function min args
71 {
72 "toString",
74 0,
75 },
76 { 0 }
77};

Referenced by InitOOJSSound(), and InitOOJSSound().

◆ sSoundProperties

JSPropertySpec sSoundProperties[]
static
Initial value:
= {
{ 0 }
}
#define OOJS_PROP_READONLY_CB

Definition at line 63 of file OOJSSound.m.

63 {
64 // JS name ID flags
66 { 0 }
67};

Referenced by InitOOJSSound(), InitOOJSSound(), SoundGetProperty(), and SoundGetProperty().

◆ sSoundPrototype

JSObject* sSoundPrototype
static

◆ sSoundStaticMethods

JSFunctionSpec sSoundStaticMethods[]
static
Initial value:
= {
{
"load",
1,
},
{
"musicSoundSource",
0,
},
{
"playMusic",
1,
},
{
"stopMusic",
0,
},
{ 0 }
}
static JSBool SoundStaticStopMusic(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSound.m:245
static JSBool SoundStaticPlayMusic(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSound.m:207
static JSBool SoundStaticLoad(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSound.m:172
static JSBool SoundStaticMusicSoundSource(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSound.m:195

Definition at line 79 of file OOJSSound.m.

79 {
80 // JS name Function min args
81 {
82 "load",
84 1,
85 },
86 {
87 "musicSoundSource",
89 0,
90 },
91 {
92 "playMusic",
94 1,
95 },
96 {
97 "stopMusic",
99 0,
100 },
101 { 0 }
102};

Referenced by InitOOJSSound(), and InitOOJSSound().