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 JSValue SoundGetProperty (OOJS_GETTER_ARGS)
static JSValue SoundStaticLoad (OOJS_NATIVE_ARGS)
static JSValue SoundStaticMusicSoundSource (OOJS_NATIVE_ARGS)
static JSValue SoundStaticPlayMusic (OOJS_NATIVE_ARGS)
static JSValue SoundStaticStopMusic (OOJS_NATIVE_ARGS)
void InitOOJSSound (JSContext *context, JSValueConst global)
OOSound * SoundFromJSValue (JSContext *context, JSValueConst value)

Variables

static JSClassID sSoundClassID
static JSClassDef sSoundClass
static const JSCFunctionListEntry sSoundProperties []
static const JSCFunctionListEntry sSoundMethods []
static const JSCFunctionListEntry sSoundStaticMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSound_name 

Definition at line 48 of file OOJSSound.m.

48 {
49 // Property IDs
51};
@ kSound_name
Definition OOJSSound.m:60

Function Documentation

◆ GetNamedSound()

OOSound * GetNamedSound ( NSString * name)
static

Definition at line 129 of file OOJSSound.m.

130{
131 OOSound* sound = nil;
132
133 if ([name hasPrefix:@"["] && [name hasSuffix:@"]"]) {
134 sound = [OOSound soundWithCustomSoundKey:name];
135 } else {
136 sound = [ResourceManager ooSoundNamed:name inFolder:@"Sounds"];
137 }
138
139 return sound;
140}
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:.

Here is the call graph for this function:

◆ InitOOJSSound()

void InitOOJSSound ( JSContext * context,
JSValueConst global )

Definition at line 75 of file OOJSSound.m.

76{
78 OOJSInitClass(context, global, sSoundClassID, JS_UNDEFINED, OOJSUnconstructableConstruct, 0,
82}
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)
static JSClassID sSoundClassID
Definition OOJSSound.m:31
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)
#define OOJS_COUNT(array)

References InitOOJSSound(), OOJS_COUNT, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), OOJSUnconstructableConstruct(), sSoundClass, sSoundClassID, sSoundMethods, sSoundProperties, and sSoundStaticMethods.

Here is the call graph for this function:

◆ SoundFromJSValue()

OOSound * SoundFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 84 of file OOJSSound.m.

85{
87
88 OOSound* result = nil;
89
90 /* The SpiderMonkey version returned before resuming the time limiter,
91 leaving it paused; the pause is balanced here.
92 */
94 if ([PLAYER status] != STATUS_START_GAME && JS_IsString(value)) {
95 result = GetNamedSound(OOStringFromJSValue(context, value));
96 } else {
97 result = OOJSNativeObjectOfClassFromJSValue(context, value, [OOSound class]);
98 }
100
101 return result;
102
104}
#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(), nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSNativeObjectOfClassFromJSValue(), OOJSPauseTimeLimiter(), OOJSResumeTimeLimiter(), OOStringFromJSValue(), and PLAYER.

Here is the call graph for this function:

◆ SoundGetProperty()

JSValue SoundGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 108 of file OOJSSound.m.

109{
110 OOJS_NATIVE_ENTER(context)
111
112 OOSound* sound = nil;
113
114 if (EXPECT_NOT(!JSSoundGetSound(context, this, &sound)))
115 return OOJSNativeFailure(context);
116
117 switch (magic) {
118 case kSound_name:
119 return OOJSValueFromNativeObject(context, [sound name]);
120
121 default:
123 return OOJSNativeFailure(context);
124 }
125
127}
#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)
JSValue OOJSNativeFailure(JSContext *context)

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

Here is the call graph for this function:

◆ SoundStaticLoad()

JSValue SoundStaticLoad ( OOJS_NATIVE_ARGS )
static

Definition at line 145 of file OOJSSound.m.

146{
147 OOJS_NATIVE_ENTER(context)
148
149 NSString* name = nil;
150 OOSound* sound = nil;
151
152 if (argc > 0)
153 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
154 if (name == nil) {
155 OOJSReportBadArguments(context, @"Sound", @"load", MIN(argc, 1), OOJS_ARGV, nil, @"string");
156 return OOJSNativeFailure(context);
157 }
158
160 sound = GetNamedSound(name);
162
163 OOJS_RETURN_OBJECT(sound);
164
166}
#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_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSNativeFailure(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ SoundStaticMusicSoundSource()

JSValue SoundStaticMusicSoundSource ( OOJS_NATIVE_ARGS )
static

Definition at line 168 of file OOJSSound.m.

169{
170 OOJS_NATIVE_ENTER(context)
171 OOSoundSource* musicSource = nil;
175 OOJS_RETURN_OBJECT(musicSource);
177}
OOMusicController * sharedController()
OOSoundSource * soundSource()

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

Here is the call graph for this function:

◆ SoundStaticPlayMusic()

JSValue SoundStaticPlayMusic ( OOJS_NATIVE_ARGS )
static

Definition at line 180 of file OOJSSound.m.

181{
182 OOJS_NATIVE_ENTER(context)
183
184 NSString* name = nil;
185 BOOL loop = NO;
186 double gain = OO_DEFAULT_SOUNDSOURCE_GAIN;
187
188 if (argc > 0)
189 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
190 if (name == nil) {
191 OOJSReportBadArguments(context, @"Sound", @"playMusic", MIN(argc, 1), OOJS_ARGV, nil, @"string");
192 return OOJSNativeFailure(context);
193 }
194 if (argc > 1) {
195 int b = JS_ToBool(context, OOJS_ARGV[1]);
196 if (b < 0) {
197 OOJSReportBadArguments(context, @"Sound", @"playMusic", 1, OOJS_ARGV + 1, nil, @"boolean");
198 return OOJSNativeFailure(context);
199 }
200 loop = b;
201 }
202
203 if (argc > 2) {
204 if (!OOJSArgumentListGetNumber(context, @"Sound", @"playMusic", 2, OOJS_ARGV + 2, &gain, NULL)) {
205 OOJSReportBadArguments(context, @"Sound", @"playMusic", 1, OOJS_ARGV + 2, nil, @"float");
206 return OOJSNativeFailure(context);
207 }
208 }
209
213
215
217}
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_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSArgumentListGetNumber(), OOJSNativeFailure(), OOJSReportBadArguments(), OOStringFromJSValue(), OOMusicController::playMusicNamed:loop:gain:, and OOMusicController::sharedController.

Here is the call graph for this function:

◆ SoundStaticStopMusic()

JSValue SoundStaticStopMusic ( OOJS_NATIVE_ARGS )
static

Definition at line 220 of file OOJSSound.m.

221{
222 OOJS_NATIVE_ENTER(context)
223
224 NSString* name = nil;
225
226 if (argc > 0) {
227 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
228 if (EXPECT_NOT(name == nil)) {
229 OOJSReportBadArguments(context, @"Sound", @"stopMusic", argc, OOJS_ARGV, nil, @"string or no argument");
230 return OOJSNativeFailure(context);
231 }
232 }
233
236 if (name == nil || [name isEqualToString:[controller playingMusic]]) {
238 }
240
242
244}

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

Here is the call graph for this function:

Variable Documentation

◆ sSoundClass

JSClassDef sSoundClass
static
Initial value:
= {
.class_name = "Sound",
}
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 43 of file OOJSSound.m.

43 {
44 .class_name = "Sound",
45 .finalizer = OOJSObjectWrapperFinalize,
46};

◆ sSoundClassID

JSClassID sSoundClassID
static

Definition at line 31 of file OOJSSound.m.

Referenced by InitOOJSSound().

◆ sSoundMethods

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

Definition at line 58 of file OOJSSound.m.

58 {
59 // JS name, min args, function
60 JS_CFUNC_DEF("toString", 0, OOJSObjectWrapperToString),
61};

◆ sSoundProperties

const JSCFunctionListEntry sSoundProperties[]
static
Initial value:
= {
}
static JSBool SoundGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSSound.m:131
#define OOJS_PROPERTY_RO(name, getter, magic)

Definition at line 53 of file OOJSSound.m.

53 {
54 // JS name, getter, ID
56};

◆ sSoundStaticMethods

const JSCFunctionListEntry sSoundStaticMethods[]
static
Initial value:
= {
JS_CFUNC_DEF("load", 1, SoundStaticLoad),
JS_CFUNC_DEF("musicSoundSource", 0, SoundStaticMusicSoundSource),
JS_CFUNC_DEF("playMusic", 1, SoundStaticPlayMusic),
JS_CFUNC_DEF("stopMusic", 0, SoundStaticStopMusic),
}
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 63 of file OOJSSound.m.

63 {
64 // JS name, min args, function
65 JS_CFUNC_DEF("load", 1, SoundStaticLoad),
66 JS_CFUNC_DEF("musicSoundSource", 0, SoundStaticMusicSoundSource),
67 JS_CFUNC_DEF("playMusic", 1, SoundStaticPlayMusic),
68 JS_CFUNC_DEF("stopMusic", 0, SoundStaticStopMusic),
69};