45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
-
+
-
-
-
-
+
+
+
+
-
+
-
+
-
+
-
-
+
+
-
+
|
conoutf(@"sound init failed (SDL_mixer): %s",
(size_t)Mix_GetError());
nosound = true;
}
Mix_AllocateChannels(MAXCHAN);
}
COMMAND(music, ARG_1STR, (^(OFString *name) {
COMMAND(music, ARG_1STR, (^ (OFString *name) {
if (nosound)
return;
stopsound();
if (soundvol && musicvol) {
name = [name stringByReplacingOccurrencesOfString:@"\\"
withString:@"/"];
OFString *path =
[OFString stringWithFormat:@"packages/%@", name];
name = [name stringByReplacingOccurrencesOfString: @"\\"
withString: @"/"];
OFString *path = [OFString stringWithFormat:
@"packages/%@", name];
OFIRI *IRI = [Cube.sharedInstance.gameDataIRI
IRIByAppendingPathComponent:path];
IRIByAppendingPathComponent: path];
if ((mod = Mix_LoadMUS(
IRI.fileSystemRepresentation.UTF8String)) != NULL) {
Mix_PlayMusic(mod, -1);
Mix_VolumeMusic((musicvol * MAXVOL) / 255);
}
}
}))
static OFMutableData *samples;
static OFMutableArray<OFString *> *snames;
COMMAND(registersound, ARG_1EST, ^int(OFString *name) {
int i = 0;
for (OFString *iter in snames) {
if ([iter isEqual:name])
if ([iter isEqual: name])
return i;
i++;
}
if (snames == nil)
snames = [[OFMutableArray alloc] init];
if (samples == nil)
samples = [[OFMutableData alloc]
initWithItemSize:sizeof(Mix_Chunk *)];
initWithItemSize: sizeof(Mix_Chunk *)];
[snames addObject:[name stringByReplacingOccurrencesOfString:@"\\"
withString:@"/"]];
[snames addObject: [name stringByReplacingOccurrencesOfString: @"\\"
withString: @"/"]];
Mix_Chunk *sample = NULL;
[samples addItem:&sample];
[samples addItem: &sample];
return samples.count - 1;
})
void
cleansound()
{
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
-
+
-
-
+
+
-
+
-
+
|
return;
if (n < 0 || n >= samples.count) {
conoutf(@"unregistered sound: %d", n);
return;
}
Mix_Chunk **sample = (Mix_Chunk **)[samples mutableItemAtIndex:n];
Mix_Chunk **sample = (Mix_Chunk **)[samples mutableItemAtIndex: n];
if (*sample == NULL) {
OFString *path = [OFString
stringWithFormat:@"packages/sounds/%@.wav", snames[n]];
OFString *path = [OFString stringWithFormat:
@"packages/sounds/%@.wav", snames[n]];
OFIRI *IRI = [Cube.sharedInstance.gameDataIRI
IRIByAppendingPathComponent:path];
IRIByAppendingPathComponent: path];
*sample = Mix_LoadWAV(IRI.fileSystemRepresentation.UTF8String);
if (*sample == NULL) {
conoutf(@"failed to load sample: %@", IRI.string);
return;
}
}
int chan = Mix_PlayChannel(-1, *sample, 0);
if (chan < 0)
return;
if (loc)
newsoundloc(chan, loc);
updatechanvol(chan, loc);
}
COMMAND(sound, ARG_1INT, ^(int n) {
COMMAND(sound, ARG_1INT, ^ (int n) {
playsound(n, NULL);
})
|