this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #539 from MonstersGoBoom/master

textri clipping works .

authored by

Vadim Grigoruk and committed by
GitHub
69f55b9f ce83d422

+69 -50
+69 -50
src/tic.c
··· 845 845 846 846 static void setSideTexPixel(s32 x, s32 y, float u, float v) 847 847 { 848 - s32 yy = (s32)y; 848 + s32 yy = y; 849 849 if (yy >= 0 && yy < TIC80_HEIGHT) 850 850 { 851 851 if (x < SidesBuffer.Left[yy]) ··· 967 967 } 968 968 969 969 float dy = bot->y - top->y; 970 - if ((s32)dy == 0) return; 971 - 972 - float step_x = (bot->x - top->x) / dy; 973 - float step_u = (bot->u - top->u) / dy; 974 - float step_v = (bot->v - top->v) / dy; 970 + float step_x = (bot->x - top->x); 971 + float step_u = (bot->u - top->u); 972 + float step_v = (bot->v - top->v); 973 + 974 + if ((s32)dy != 0) 975 + { 976 + step_x /= dy; 977 + step_u /= dy; 978 + step_v /= dy; 979 + } 975 980 976 981 float x = top->x; 977 982 float y = top->y; ··· 993 998 if(botY > TIC80_HEIGHT) 994 999 botY = TIC80_HEIGHT; 995 1000 996 - for (; y < botY; y++) 1001 + for (; y <botY; ++y) 997 1002 { 998 1003 setSideTexPixel(x, y, u, v); 999 1004 x += step_x; ··· 1009 1014 const u8* ptr = memory->ram.tiles.data[0].data; 1010 1015 const u8* map = memory->ram.map.data; 1011 1016 1012 - V0.x = (float)x1; V0.y = (float)y1; V0.u = (float)u1; V0.v = (float)v1; 1013 - V1.x = (float)x2; V1.y = (float)y2; V1.u = (float)u2; V1.v = (float)v2; 1014 - V2.x = (float)x3; V2.y = (float)y3; V2.u = (float)u3; V2.v = (float)v3; 1017 + V0.x = x1; V0.y = y1; V0.u = u1; V0.v = v1; 1018 + V1.x = x2; V1.y = y2; V1.u = u2; V1.v = v2; 1019 + V2.x = x3; V2.y = y3; V2.u = u3; V2.v = v3; 1015 1020 1016 1021 // calculate the slope of the surface 1017 1022 // use floats here ··· 1028 1033 // convert to fixed 1029 1034 s32 dudxs = dudx * 65536.0f; 1030 1035 s32 dvdxs = dvdx * 65536.0f; 1031 - 1036 + // fill the buffer 1032 1037 initSidesBuffer(); 1033 - 1038 + // parse each line and decide where in the buffer to store them ( left or right ) 1034 1039 ticTexLine(memory, &V0, &V1); 1035 1040 ticTexLine(memory, &V1, &V2); 1036 1041 ticTexLine(memory, &V2, &V0); 1037 - 1042 + 1043 + for (s32 y = 0; y < TIC80_HEIGHT; y++) 1038 1044 { 1039 - for (s32 y = 0; y < TIC80_HEIGHT; y++) 1045 + // if it's backwards skip it 1046 + s32 width = SidesBuffer.Right[y] - SidesBuffer.Left[y]; 1047 + // if it's off top or bottom , skip this line 1048 + if ((y < machine->state.clip.t) || (y > machine->state.clip.b)) 1049 + width = 0; 1050 + if (width > 0) 1040 1051 { 1041 - float width = SidesBuffer.Right[y] - SidesBuffer.Left[y]; 1042 - if (width > 0) 1052 + s32 u = SidesBuffer.ULeft[y]; 1053 + s32 v = SidesBuffer.VLeft[y]; 1054 + s32 left = SidesBuffer.Left[y]; 1055 + s32 right = SidesBuffer.Right[y]; 1056 + // check right edge, and clamp it 1057 + if (right > machine->state.clip.r) 1058 + right = machine->state.clip.r; 1059 + // check left edge and offset UV's if we are off the left 1060 + if (left < machine->state.clip.l) 1043 1061 { 1044 - s32 u = SidesBuffer.ULeft[y]; 1045 - s32 v = SidesBuffer.VLeft[y]; 1062 + s32 dist = machine->state.clip.l - SidesBuffer.Left[y]; 1063 + u += dudxs * dist; 1064 + v += dvdxs * dist; 1065 + left = machine->state.clip.l; 1066 + } 1067 + // are we drawing from the map . ok then at least check before the inner loop 1068 + if (use_map == true) 1069 + { 1070 + for (s32 x = left; x <= right; ++x) 1071 + { 1072 + enum { MapWidth = TIC_MAP_WIDTH * TIC_SPRITESIZE, MapHeight = TIC_MAP_HEIGHT * TIC_SPRITESIZE }; 1073 + s32 iu = (u >> 16) % MapWidth; 1074 + s32 iv = (v >> 16) % MapHeight; 1046 1075 1047 - for (s32 x = (s32)SidesBuffer.Left[y]; x <= (s32)SidesBuffer.Right[y]; ++x) 1076 + while (iu < 0) iu += MapWidth; 1077 + while (iv < 0) iv += MapHeight; 1078 + u8 tile = map[(iv >> 3) * TIC_MAP_WIDTH + (iu >> 3)]; 1079 + const u8 *buffer = &ptr[tile << 5]; 1080 + u8 color = tic_tool_peek4(buffer, (iu & 7) + ((iv & 7) << 3)); 1081 + if (color != chroma) 1082 + setPixel(machine, x, y, color); 1083 + u += dudxs; 1084 + v += dvdxs; 1085 + } 1086 + } 1087 + else 1088 + { 1089 + // direct from tile ram 1090 + for (s32 x = left; x <= right; ++x) 1048 1091 { 1049 - if ((x >= 0) && (x < TIC80_WIDTH)) 1050 - { 1051 - if (use_map == true) 1052 - { 1053 - enum {MapWidth = TIC_MAP_WIDTH * TIC_SPRITESIZE, MapHeight = TIC_MAP_HEIGHT * TIC_SPRITESIZE}; 1054 - 1055 - s32 iu = (u >> 16) % MapWidth; 1056 - s32 iv = (v >> 16) % MapHeight; 1057 - 1058 - while (iu < 0) iu += MapWidth; 1059 - while (iv < 0) iv += MapHeight; 1060 - 1061 - u8 tile = map[(iv>>3) * TIC_MAP_WIDTH + (iu>>3)]; 1062 - const u8 *buffer = &ptr[tile << 5]; 1063 - u8 color = tic_tool_peek4(buffer, (iu & 7) + ((iv & 7) << 3)); 1064 - if (color != chroma) 1065 - setPixel(machine, x, y, color); 1066 - } 1067 - else 1068 - { 1069 - enum{SheetWidth = TIC_SPRITESHEET_SIZE, SheetHeight = TIC_SPRITESHEET_SIZE * TIC_SPRITE_BANKS}; 1070 - 1071 - s32 iu = (u>>16) & (SheetWidth - 1); 1072 - s32 iv = (v>>16) & (SheetHeight - 1); 1073 - const u8 *buffer = &ptr[((iu >> 3) + ((iv >> 3) << 4)) << 5]; 1074 - u8 color = tic_tool_peek4(buffer, (iu & 7) + ((iv & 7) << 3)); 1075 - if (color != chroma) 1076 - setPixel(machine, x, y, color); 1077 - } 1078 - } 1092 + enum{SheetWidth = TIC_SPRITESHEET_SIZE, SheetHeight = TIC_SPRITESHEET_SIZE * TIC_SPRITE_BANKS}; 1093 + s32 iu = (u>>16) & (SheetWidth - 1); 1094 + s32 iv = (v>>16) & (SheetHeight - 1); 1095 + const u8 *buffer = &ptr[((iu >> 3) + ((iv >> 3) << 4)) << 5]; 1096 + u8 color = tic_tool_peek4(buffer, (iu & 7) + ((iv & 7) << 3)); 1097 + if (color != chroma) 1098 + setPixel(machine, x, y, color); 1079 1099 u += dudxs; 1080 1100 v += dvdxs; 1081 1101 } ··· 1083 1103 } 1084 1104 } 1085 1105 } 1086 - 1087 1106 1088 1107 1089 1108 static void api_sprite(tic_mem* memory, const tic_tiles* src, s32 index, s32 x, s32 y, u8* colors, s32 count)