Cube  Diff

Differences From Artifact [a52bf36780]:

To Artifact [8875dffa42]:


186
187
188
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
	for (int i = 0; i < 256; i++)
		for (int j = 0; j < MAXFRAMES; j++)
			mapping[i][j] = 0;
}

int curtexnum = 0;

COMMAND(texturereset, ARG_NONE, ^{
	curtexnum = 0;
})

COMMAND(texture, ARG_2STR, (^(OFString *aframe, OFString *name) {
	int num = curtexnum++, frame = aframe.cube_intValue;

	if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
		return;

	mapping[num][frame] = 1;
	mapname[num][frame] = [name stringByReplacingOccurrencesOfString:@"\\"
	                                                      withString:@"/"];
}))

int
lookuptexture(int tex, int *xs, int *ys)
{
	int frame = 0; // other frames?
	int tid = mapping[tex][frame];

	if (tid >= FIRSTTEX) {
		*xs = texx[tid - FIRSTTEX];
		*ys = texy[tid - FIRSTTEX];
		return tid;
	}

	*xs = *ys = 16;
	if (tid == 0)
		return 1; // crosshair :)

	// lazily happens once per "texture" command, basically
	for (int i = 0; i < curtex; i++) {
		if ([mapname[tex][frame] isEqual:texname[i]]) {
			mapping[tex][frame] = tid = i + FIRSTTEX;
			*xs = texx[i];
			*ys = texy[i];
			return tid;
		}
	}

	if (curtex == MAXTEX)
		fatal(@"loaded too many textures");

	int tnum = curtex + FIRSTTEX;
	texname[curtex] = mapname[tex][frame];

	OFString *path =
	    [OFString stringWithFormat:@"packages/%@", texname[curtex]];

	if (installtex(tnum,
	        [Cube.sharedInstance.gameDataIRI
	            IRIByAppendingPathComponent:path],
	        xs, ys, false)) {
		mapping[tex][frame] = tnum;
		texx[curtex] = *xs;
		texy[curtex] = *ys;
		curtex++;
		return tnum;
	} else {
		return mapping[tex][frame] = FIRSTTEX; // temp fix







|



|






|
|




















|













|
|

|
<
|
<







186
187
188
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

244

245
246
247
248
249
250
251
	for (int i = 0; i < 256; i++)
		for (int j = 0; j < MAXFRAMES; j++)
			mapping[i][j] = 0;
}

int curtexnum = 0;

COMMAND(texturereset, ARG_NONE, ^ {
	curtexnum = 0;
})

COMMAND(texture, ARG_2STR, (^ (OFString *aframe, OFString *name) {
	int num = curtexnum++, frame = aframe.cube_intValue;

	if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
		return;

	mapping[num][frame] = 1;
	mapname[num][frame] = [name stringByReplacingOccurrencesOfString: @"\\"
	                                                      withString: @"/"];
}))

int
lookuptexture(int tex, int *xs, int *ys)
{
	int frame = 0; // other frames?
	int tid = mapping[tex][frame];

	if (tid >= FIRSTTEX) {
		*xs = texx[tid - FIRSTTEX];
		*ys = texy[tid - FIRSTTEX];
		return tid;
	}

	*xs = *ys = 16;
	if (tid == 0)
		return 1; // crosshair :)

	// lazily happens once per "texture" command, basically
	for (int i = 0; i < curtex; i++) {
		if ([mapname[tex][frame] isEqual: texname[i]]) {
			mapping[tex][frame] = tid = i + FIRSTTEX;
			*xs = texx[i];
			*ys = texy[i];
			return tid;
		}
	}

	if (curtex == MAXTEX)
		fatal(@"loaded too many textures");

	int tnum = curtex + FIRSTTEX;
	texname[curtex] = mapname[tex][frame];

	OFString *path = [OFString stringWithFormat: @"packages/%@",
						     texname[curtex]];

	if (installtex(tnum, [Cube.sharedInstance.gameDataIRI

	    IRIByAppendingPathComponent: path], xs, ys, false)) {

		mapping[tex][frame] = tnum;
		texx[curtex] = *xs;
		texy[curtex] = *ys;
		curtex++;
		return tnum;
	} else {
		return mapping[tex][frame] = FIRSTTEX; // temp fix
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
}

void
addstrip(int tex, int start, int n)
{
	if (strips == nil)
		strips = [[OFMutableData alloc]
		    initWithItemSize:sizeof(struct strip)];

	struct strip s = { .tex = tex, .start = start, .num = n };
	[strips addItem:&s];
}

#undef gamma

VARFP(gamma, 30, 100, 300, {
	float f = gamma / 100.0f;
	Uint16 ramp[256];







|


|







316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
}

void
addstrip(int tex, int start, int n)
{
	if (strips == nil)
		strips = [[OFMutableData alloc]
		    initWithItemSize: sizeof(struct strip)];

	struct strip s = { .tex = tex, .start = start, .num = n };
	[strips addItem: &s];
}

#undef gamma

VARFP(gamma, 30, 100, 300, {
	float f = gamma / 100.0f;
	Uint16 ramp[256];