Cube  Diff

Differences From Artifact [ed4ed00e36]:

To Artifact [f024dcac09]:


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
	}
}

// management of texture slots
// each texture slot can have multople texture frames, of which currently only
// the first is used additional frames can be used for various shaders

const int MAXTEX = 1000;
int texx[MAXTEX]; // ( loaded texture ) -> ( name, size )
int texy[MAXTEX];
string texname[MAXTEX];
int curtex = 0;
const int FIRSTTEX = 1000; // opengl id = loaded id + FIRSTTEX
// std 1+, sky 14+, mdls 20+

const int MAXFRAMES = 2;     // increase to allow more complex shader defs

int mapping[256][MAXFRAMES]; // ( cube texture, frame ) -> ( opengl id, name )
string mapname[256][MAXFRAMES];

void
purgetextures()
{
	loopi(256) loop(j, MAXFRAMES) mapping[i][j] = 0;
}








|
|
|
|
|
|


|
>
|
|







159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
	}
}

// management of texture slots
// each texture slot can have multople texture frames, of which currently only
// the first is used additional frames can be used for various shaders

static const int MAXTEX = 1000;
static int texx[MAXTEX]; // ( loaded texture ) -> ( name, size )
static int texy[MAXTEX];
static OFString *texname[MAXTEX];
static int curtex = 0;
static const int FIRSTTEX = 1000; // opengl id = loaded id + FIRSTTEX
// std 1+, sky 14+, mdls 20+

static const int MAXFRAMES = 2; // increase to allow more complex shader defs
static int mapping[256]
                  [MAXFRAMES]; // ( cube texture, frame ) -> ( opengl id, name )
static OFString *mapname[256][MAXFRAMES];

void
purgetextures()
{
	loopi(256) loop(j, MAXFRAMES) mapping[i][j] = 0;
}

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
texture(OFString *aframe, OFString *name)
{
	@autoreleasepool {
		int num = curtexnum++, frame = (int)aframe.longLongValue;
		if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
			return;
		mapping[num][frame] = 1;
		char *n = mapname[num][frame];
		strcpy_s(n, name.UTF8String);
	}
}
COMMAND(texture, ARG_2STR)

int
lookuptexture(int tex, int *xs, int *ys)
{







|
<







195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
texture(OFString *aframe, OFString *name)
{
	@autoreleasepool {
		int num = curtexnum++, frame = (int)aframe.longLongValue;
		if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
			return;
		mapping[num][frame] = 1;
		mapname[num][frame] = name;

	}
}
COMMAND(texture, ARG_2STR)

int
lookuptexture(int tex, int *xs, int *ys)
{
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

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

	loopi(curtex) // lazily happens once per "texture" command, basically
	{
		if (strcmp(mapname[tex][frame], texname[i]) == 0) {
			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;
	strcpy_s(texname[curtex], mapname[tex][frame]);

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

		if (installtex(tnum,
		        [Cube.sharedInstance.gameDataIRI
		            IRIByAppendingPathComponent:path],
		        xs, ys, false)) {
			mapping[tex][frame] = tnum;
			texx[curtex] = *xs;







|











|



|







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

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

	loopi(curtex) // lazily happens once per "texture" command, basically
	{
		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];

	@autoreleasepool {
		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;