Merge branch 'master' into sdl-gpu_test
This commit is contained in:
		@@ -1183,7 +1183,11 @@ static void onConsoleNewCommandConfirmed(Console* console, const char* param)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_LUA)
 | 
					#if defined(TIC_BUILD_WITH_LUA)
 | 
				
			||||||
	else loadDemo(console, LuaScript);
 | 
						else
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							loadDemo(console, LuaScript);
 | 
				
			||||||
 | 
							done = true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(done) printBack(console, "\nnew cart is created");
 | 
						if(done) printBack(console, "\nnew cart is created");
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										124
									
								
								src/tic.c
									
									
									
									
									
								
							
							
						
						
									
										124
									
								
								src/tic.c
									
									
									
									
									
								
							@@ -845,7 +845,7 @@ static void setSidePixel(s32 x, s32 y)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void setSideTexPixel(s32 x, s32 y, float u, float v)
 | 
					static void setSideTexPixel(s32 x, s32 y, float u, float v)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	s32 yy = (s32)y;
 | 
						s32 yy = y;
 | 
				
			||||||
	if (yy >= 0 && yy < TIC80_HEIGHT)
 | 
						if (yy >= 0 && yy < TIC80_HEIGHT)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (x < SidesBuffer.Left[yy])
 | 
							if (x < SidesBuffer.Left[yy])
 | 
				
			||||||
@@ -939,8 +939,9 @@ static void api_tri(tic_mem* memory, s32 x1, s32 y1, s32 x2, s32 y2, s32 x3, s32
 | 
				
			|||||||
	ticLine(memory, x3, y3, x1, y1, color, triPixelFunc);
 | 
						ticLine(memory, x3, y3, x1, y1, color, triPixelFunc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	u8 final_color = mapColor(&machine->memory, color);
 | 
						u8 final_color = mapColor(&machine->memory, color);
 | 
				
			||||||
	s32 yt = max(0, min(y1, min(y2, y3)));
 | 
						s32 yt = max(machine->state.clip.t, min(y1, min(y2, y3)));
 | 
				
			||||||
	s32 yb = min(TIC80_HEIGHT, max(y1, max(y2, y3)) + 1);
 | 
						s32 yb = min(machine->state.clip.b, max(y1, max(y2, y3)) + 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(s32 y = yt; y < yb; y++) {
 | 
						for(s32 y = yt; y < yb; y++) {
 | 
				
			||||||
		s32 xl = max(SidesBuffer.Left[y], machine->state.clip.l);
 | 
							s32 xl = max(SidesBuffer.Left[y], machine->state.clip.l);
 | 
				
			||||||
		s32 xr = min(SidesBuffer.Right[y]+1, machine->state.clip.r);
 | 
							s32 xr = min(SidesBuffer.Right[y]+1, machine->state.clip.r);
 | 
				
			||||||
@@ -967,11 +968,16 @@ static void ticTexLine(tic_mem* memory, TexVert *v0, TexVert *v1)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float dy = bot->y - top->y;
 | 
						float dy = bot->y - top->y;
 | 
				
			||||||
	if ((s32)dy == 0)	return;
 | 
						float step_x = (bot->x - top->x);
 | 
				
			||||||
	
 | 
						float step_u = (bot->u - top->u);
 | 
				
			||||||
	float step_x = (bot->x - top->x) / dy;
 | 
						float step_v = (bot->v - top->v);
 | 
				
			||||||
	float step_u = (bot->u - top->u) / dy;
 | 
					
 | 
				
			||||||
	float step_v = (bot->v - top->v) / dy;
 | 
						if ((s32)dy != 0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							step_x /= dy;
 | 
				
			||||||
 | 
							step_u /= dy;
 | 
				
			||||||
 | 
							step_v /= dy;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float x = top->x;
 | 
						float x = top->x;
 | 
				
			||||||
	float y = top->y;
 | 
						float y = top->y;
 | 
				
			||||||
@@ -993,7 +999,7 @@ static void ticTexLine(tic_mem* memory, TexVert *v0, TexVert *v1)
 | 
				
			|||||||
	if(botY > TIC80_HEIGHT)
 | 
						if(botY > TIC80_HEIGHT)
 | 
				
			||||||
		botY = TIC80_HEIGHT;
 | 
							botY = TIC80_HEIGHT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (; y < botY; y++)
 | 
						for (; y <botY; ++y)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		setSideTexPixel(x, y, u, v);
 | 
							setSideTexPixel(x, y, u, v);
 | 
				
			||||||
		x += step_x;
 | 
							x += step_x;
 | 
				
			||||||
@@ -1009,9 +1015,9 @@ static void api_textri(tic_mem* memory, float x1, float y1, float x2, float y2,
 | 
				
			|||||||
	const u8* ptr = memory->ram.tiles.data[0].data;
 | 
						const u8* ptr = memory->ram.tiles.data[0].data;
 | 
				
			||||||
	const u8* map = memory->ram.map.data;
 | 
						const u8* map = memory->ram.map.data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	V0.x = (float)x1; 	V0.y = (float)y1; 	V0.u = (float)u1; 	V0.v = (float)v1;
 | 
						V0.x = x1; 	V0.y = y1; 	V0.u = u1; 	V0.v = v1;
 | 
				
			||||||
	V1.x = (float)x2; 	V1.y = (float)y2; 	V1.u = (float)u2; 	V1.v = (float)v2;
 | 
						V1.x = x2; 	V1.y = y2; 	V1.u = u2; 	V1.v = v2;
 | 
				
			||||||
	V2.x = (float)x3; 	V2.y = (float)y3; 	V2.u = (float)u3; 	V2.v = (float)v3;
 | 
						V2.x = x3; 	V2.y = y3; 	V2.u = u3; 	V2.v = v3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//	calculate the slope of the surface 
 | 
						//	calculate the slope of the surface 
 | 
				
			||||||
	//	use floats here 
 | 
						//	use floats here 
 | 
				
			||||||
@@ -1028,54 +1034,69 @@ static void api_textri(tic_mem* memory, float x1, float y1, float x2, float y2,
 | 
				
			|||||||
	//	convert to fixed
 | 
						//	convert to fixed
 | 
				
			||||||
	s32 dudxs = dudx * 65536.0f;
 | 
						s32 dudxs = dudx * 65536.0f;
 | 
				
			||||||
	s32 dvdxs = dvdx * 65536.0f;
 | 
						s32 dvdxs = dvdx * 65536.0f;
 | 
				
			||||||
 | 
						//	fill the buffer 
 | 
				
			||||||
	initSidesBuffer();
 | 
						initSidesBuffer();
 | 
				
			||||||
 | 
						//	parse each line and decide where in the buffer to store them ( left or right ) 
 | 
				
			||||||
	ticTexLine(memory, &V0, &V1);
 | 
						ticTexLine(memory, &V0, &V1);
 | 
				
			||||||
	ticTexLine(memory, &V1, &V2);
 | 
						ticTexLine(memory, &V1, &V2);
 | 
				
			||||||
	ticTexLine(memory, &V2, &V0);
 | 
						ticTexLine(memory, &V2, &V0);
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
 | 
						for (s32 y = 0; y < TIC80_HEIGHT; y++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		for (s32 y = 0; y < TIC80_HEIGHT; y++)
 | 
							//	if it's backwards skip it
 | 
				
			||||||
 | 
							s32 width = SidesBuffer.Right[y] - SidesBuffer.Left[y];
 | 
				
			||||||
 | 
							//	if it's off top or bottom , skip this line
 | 
				
			||||||
 | 
							if ((y < machine->state.clip.t) || (y > machine->state.clip.b))
 | 
				
			||||||
 | 
								width = 0;
 | 
				
			||||||
 | 
							if (width > 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			float width = SidesBuffer.Right[y] - SidesBuffer.Left[y];
 | 
								s32 u = SidesBuffer.ULeft[y];
 | 
				
			||||||
			if (width > 0)
 | 
								s32 v = SidesBuffer.VLeft[y];
 | 
				
			||||||
 | 
								s32 left = SidesBuffer.Left[y];
 | 
				
			||||||
 | 
								s32 right = SidesBuffer.Right[y];
 | 
				
			||||||
 | 
								//	check right edge, and clamp it
 | 
				
			||||||
 | 
								if (right > machine->state.clip.r)
 | 
				
			||||||
 | 
									right = machine->state.clip.r;
 | 
				
			||||||
 | 
								//	check left edge and offset UV's if we are off the left 
 | 
				
			||||||
 | 
								if (left < machine->state.clip.l)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				s32 u = SidesBuffer.ULeft[y];
 | 
									s32 dist = machine->state.clip.l - SidesBuffer.Left[y];
 | 
				
			||||||
				s32 v = SidesBuffer.VLeft[y];
 | 
									u += dudxs * dist;
 | 
				
			||||||
 | 
									v += dvdxs * dist;
 | 
				
			||||||
				for (s32 x = (s32)SidesBuffer.Left[y]; x <= (s32)SidesBuffer.Right[y]; ++x)
 | 
									left = machine->state.clip.l;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								//	are we drawing from the map . ok then at least check before the inner loop
 | 
				
			||||||
 | 
								if (use_map == true)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									for (s32 x = left; x <= right; ++x)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					if ((x >= 0) && (x < TIC80_WIDTH))
 | 
										enum { MapWidth = TIC_MAP_WIDTH * TIC_SPRITESIZE, MapHeight = TIC_MAP_HEIGHT * TIC_SPRITESIZE };
 | 
				
			||||||
					{
 | 
										s32 iu = (u >> 16) % MapWidth;
 | 
				
			||||||
						if (use_map == true)
 | 
										s32 iv = (v >> 16) % MapHeight;
 | 
				
			||||||
						{
 | 
					 | 
				
			||||||
							enum {MapWidth = TIC_MAP_WIDTH * TIC_SPRITESIZE, MapHeight = TIC_MAP_HEIGHT * TIC_SPRITESIZE};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
							s32 iu = (u >> 16) % MapWidth;
 | 
										while (iu < 0) iu += MapWidth;
 | 
				
			||||||
							s32 iv = (v >> 16) % MapHeight;
 | 
										while (iv < 0) iv += MapHeight;
 | 
				
			||||||
 | 
										u8 tile = map[(iv >> 3) * TIC_MAP_WIDTH + (iu >> 3)];
 | 
				
			||||||
							while (iu < 0) iu += MapWidth;
 | 
										const u8 *buffer = &ptr[tile << 5];
 | 
				
			||||||
							while (iv < 0) iv += MapHeight;
 | 
										u8 color = tic_tool_peek4(buffer, (iu & 7) + ((iv & 7) << 3));
 | 
				
			||||||
 | 
										if (color != chroma)
 | 
				
			||||||
							u8 tile = map[(iv>>3) * TIC_MAP_WIDTH + (iu>>3)];
 | 
											setPixel(machine, x, y, color);
 | 
				
			||||||
							const u8 *buffer = &ptr[tile << 5];
 | 
										u += dudxs;
 | 
				
			||||||
							u8 color = tic_tool_peek4(buffer, (iu & 7) + ((iv & 7) << 3));
 | 
										v += dvdxs;
 | 
				
			||||||
							if (color != chroma)
 | 
									}
 | 
				
			||||||
								setPixel(machine, x, y, color);
 | 
								}
 | 
				
			||||||
						}
 | 
								else
 | 
				
			||||||
						else
 | 
								{
 | 
				
			||||||
						{
 | 
									//	direct from tile ram 
 | 
				
			||||||
							enum{SheetWidth = TIC_SPRITESHEET_SIZE, SheetHeight = TIC_SPRITESHEET_SIZE * TIC_SPRITE_BANKS};
 | 
									for (s32 x = left; x <= right; ++x)
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
							s32 iu = (u>>16) & (SheetWidth - 1);
 | 
										enum{SheetWidth = TIC_SPRITESHEET_SIZE, SheetHeight = TIC_SPRITESHEET_SIZE * TIC_SPRITE_BANKS};
 | 
				
			||||||
							s32 iv = (v>>16) & (SheetHeight - 1);
 | 
										s32 iu = (u>>16) & (SheetWidth - 1);
 | 
				
			||||||
							const u8 *buffer = &ptr[((iu >> 3) + ((iv >> 3) << 4)) << 5];
 | 
										s32 iv = (v>>16) & (SheetHeight - 1);
 | 
				
			||||||
							u8 color = tic_tool_peek4(buffer, (iu & 7) + ((iv & 7) << 3));
 | 
										const u8 *buffer = &ptr[((iu >> 3) + ((iv >> 3) << 4)) << 5];
 | 
				
			||||||
							if (color != chroma)
 | 
										u8 color = tic_tool_peek4(buffer, (iu & 7) + ((iv & 7) << 3));
 | 
				
			||||||
								setPixel(machine, x, y, color);
 | 
										if (color != chroma)
 | 
				
			||||||
						}
 | 
											setPixel(machine, x, y, color);
 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					u += dudxs;
 | 
										u += dudxs;
 | 
				
			||||||
					v += dvdxs;
 | 
										v += dvdxs;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -1085,7 +1106,6 @@ static void api_textri(tic_mem* memory, float x1, float y1, float x2, float y2,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
static void api_sprite(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count)
 | 
					static void api_sprite(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	drawSprite(memory, src, index, x, y, colors, count, 1, tic_no_flip, tic_no_rotate);
 | 
						drawSprite(memory, src, index, x, y, colors, count, 1, tic_no_flip, tic_no_rotate);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user