Cube  Diff

Differences From Artifact [4ad5c2248e]:

To Artifact [24cd809ba3]:


1
2

3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10


+







#include "cube.h"

#import "Command.h"
#import "DynamicEntity.h"

#include <SDL_mixer.h>

VARP(soundvol, 0, 255, 255);
VARP(musicvol, 0, 128, 255);
bool nosound = false;
43
44
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
103
104
105
106
107
108
109
44
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
103
104







-
-
+
-



















-
+
-




-
-
+
-




















-
+
-







		conoutf(@"sound init failed (SDL_mixer): %s",
		    (size_t)Mix_GetError());
		nosound = true;
	}
	Mix_AllocateChannels(MAXCHAN);
}

void
music(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];
		OFIRI *IRI = [Cube.sharedInstance.gameDataIRI
		    IRIByAppendingPathComponent:path];

		if ((mod = Mix_LoadMUS(
		         IRI.fileSystemRepresentation.UTF8String)) != NULL) {
			Mix_PlayMusic(mod, -1);
			Mix_VolumeMusic((musicvol * MAXVOL) / 255);
		}
	}
}
}))
COMMAND(music, ARG_1STR)

static OFMutableData *samples;
static OFMutableArray<OFString *> *snames;

int
registersound(OFString *name)
COMMAND(registersound, ARG_1EST, ^int(OFString *name) {
{
	int i = 0;
	for (OFString *iter in snames) {
		if ([iter isEqual:name])
			return i;

		i++;
	}

	if (snames == nil)
		snames = [[OFMutableArray alloc] init];
	if (samples == nil)
		samples = [[OFMutableData alloc]
		    initWithItemSize:sizeof(Mix_Chunk *)];

	[snames addObject:[name stringByReplacingOccurrencesOfString:@"\\"
	                                                  withString:@"/"]];
	Mix_Chunk *sample = NULL;
	[samples addItem:&sample];

	return samples.count - 1;
}
})
COMMAND(registersound, ARG_1EST)

void
cleansound()
{
	if (nosound)
		return;
	stopsound();
212
213
214
215
216
217
218
219
220

221
222
223

224
207
208
209
210
211
212
213


214

215

216








-
-
+
-

-
+
-

	if (loc)
		newsoundloc(chan, loc);

	updatechanvol(chan, loc);
}

void
sound(int n)
COMMAND(sound, ARG_1INT, ^(int n) {
{
	playsound(n, NULL);
}
})
COMMAND(sound, ARG_1INT)