this repo has no description
0
fork

Configure Feed

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

added pixelcenter=false argument to the textri() api #1862

nesbox d3eaca16 803a9114

+50 -21
+3 -2
demos/wasm/src/tic80.zig
··· 133 133 extern fn sfx(id: i32, note: i32, octave: i32, duration: i32, channel: i32, volumeLeft: i32, volumeRight: i32, speed: i32) void; 134 134 extern fn spr(id: i32, x: i32, y: i32, trans_colors: ?[*]const u8, color_count: i32, scale: i32, flip: i32, rotate: i32, w: i32, h: i32) void; 135 135 extern fn sync(mask: i32, bank: i32, tocart: bool) void; 136 - extern fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, u1: f32, v1: f32, u2: f32, v2: f32, u3: f32, v3: f32, texsrc: i32, trans_colors: ?[*]const u8, color_count: i32) void; 136 + extern fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, u1: f32, v1: f32, u2: f32, v2: f32, u3: f32, v3: f32, texsrc: i32, trans_colors: ?[*]const u8, color_count: i32, pixelcenter: bool) void; 137 137 extern fn tri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: i32) void; 138 138 extern fn trib(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: i32) void; 139 139 extern fn time() f32; ··· 263 263 const TextriArgs = struct { 264 264 texsrc : i32 = 0, 265 265 transparent: []const u8 = .{}, 266 + pixelcenter: bool = false, 266 267 }; 267 268 268 269 pub fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, @"u1": f32, v1: f32, @"u2": f32, v2: f32, @"u3": f32, v3: f32, args: TextriArgs) void { 269 270 const color_count = @intCast(u8,args.transparent.len); 270 271 const trans_colors = args.transparent.ptr; 271 - raw.textri(x1, y1, x2, y2, x3, y3, @"u1", v1, @"u2", v2, @"u3", v3, args.texsrc, trans_colors, color_count); 272 + raw.textri(x1, y1, x2, y2, x3, y3, @"u1", v1, @"u2", v2, @"u3", v3, args.texsrc, trans_colors, color_count, args.pixelcenter); 272 273 } 273 274 274 275 // ----
+4 -3
src/api.h
··· 682 682 \ 683 683 \ 684 684 macro(textri, \ 685 - "textri(x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 texsrc=0 chromakey=-1)", \ 685 + "textri(x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 texsrc=0 chromakey=-1 pixelcenter=false)", \ 686 686 \ 687 687 "It renders a triangle filled with texture from image ram, map ram or vbank.\n" \ 688 688 "Use in 3D graphics.\n" \ ··· 693 693 "Note that the sprite sheet or map in this case is treated as a single large image, " \ 694 694 "with U and V addressing its pixels directly, rather than by sprite ID.\n" \ 695 695 "So for example the top left corner of sprite #2 would be located at u=16, v=0.", \ 696 - 14, \ 696 + 15, \ 697 697 12, \ 698 698 0, \ 699 699 void, \ 700 700 tic_mem*, float x1, float y1, float x2, float y2, float x3, float y3, \ 701 - float u1, float v1, float u2, float v2, float u3, float v3, tic_texture_src texsrc, u8* colors, s32 count) \ 701 + float u1, float v1, float u2, float v2, float u3, float v3, tic_texture_src texsrc, u8* colors, s32 count, \ 702 + bool pixelcenter) \ 702 703 \ 703 704 \ 704 705 macro(clip, \
+4 -1
src/api/js.c
··· 847 847 } 848 848 } 849 849 850 + bool pixelcenter = duk_is_null_or_undefined(duk, 14) ? false : duk_to_boolean(duk, 14); 851 + 850 852 tic_api_textri(tic, pt[0], pt[1], // xy 1 851 853 pt[2], pt[3], // xy 2 852 854 pt[4], pt[5], // xy 3 ··· 854 856 pt[8], pt[9], // uv 2 855 857 pt[10], pt[11], // uv 3 856 858 src, // texture source 857 - colors, count); // chroma 859 + colors, count, // chroma 860 + pixelcenter); // pixelcenter 858 861 859 862 return 0; 860 863 }
+7 -2
src/api/lua.c
··· 435 435 static u8 colors[TIC_PALETTE_SIZE]; 436 436 s32 count = 0; 437 437 tic_texture_src src = tic_tiles_texture; 438 + bool pixelcenter = false; 438 439 439 440 // check for texture src 440 441 if (top >= 13) ··· 471 472 } 472 473 } 473 474 475 + if(top >= 15) 476 + pixelcenter = lua_toboolean(lua, 15); 477 + 474 478 tic_api_textri(tic, pt[0], pt[1], // xy 1 475 479 pt[2], pt[3], // xy 2 476 480 pt[4], pt[5], // xy 3 ··· 478 482 pt[8], pt[9], // uv 2 479 483 pt[10], pt[11], // uv 3 480 484 src, // texture source 481 - colors, count); // chroma 485 + colors, count, // chroma 486 + pixelcenter); // pixelcenter 482 487 } 483 - else luaL_error(lua, "invalid parameters, textri(x1,y1,x2,y2,x3,y3,u1,v1,u2,v2,u3,v3,[src=0],[chroma=off])\n"); 488 + else luaL_error(lua, "invalid parameters, textri(x1,y1,x2,y2,x3,y3,u1,v1,u2,v2,u3,v3,[src=0],[chroma=off],[pixelcenter=false])\n"); 484 489 return 0; 485 490 } 486 491
+4 -3
src/api/mruby.c
··· 301 301 { 302 302 mrb_value chroma = mrb_fixnum_value(0xff); 303 303 mrb_int src = tic_tiles_texture; 304 + mrb_bool pixelcenter = false; 304 305 305 306 mrb_float x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3; 306 - mrb_int argc = mrb_get_args(mrb, "ffffffffffff|io", 307 + mrb_int argc = mrb_get_args(mrb, "ffffffffffff|iob", 307 308 &x1, &y1, &x2, &y2, &x3, &y3, 308 309 &u1, &v1, &u2, &v2, &u3, &v3, 309 - &src, &chroma); 310 + &src, &chroma, &pixelcenter); 310 311 311 312 mrb_int count; 312 313 u8 *chromas; ··· 332 333 tic_api_textri(memory, 333 334 x1, y1, x2, y2, x3, y3, 334 335 u1, v1, u2, v2, u3, v3, 335 - src, chromas, count); 336 + src, chromas, count, pixelcenter); 336 337 337 338 free(chromas); 338 339
+12 -2
src/api/squirrel.c
··· 516 516 count = 1; 517 517 } 518 518 519 + bool pixelcenter = false; 520 + // check for pixel center 521 + if (top >= 15) 522 + { 523 + SQBool b = SQFalse; 524 + sq_getbool(vm, 15, &b); 525 + pixelcenter = (b != SQFalse); 526 + } 527 + 519 528 tic_api_textri(tic, pt[0], pt[1], // xy 1 520 529 pt[2], pt[3], // xy 2 521 530 pt[4], pt[5], // xy 3 ··· 523 532 pt[8], pt[9], // uv 2 524 533 pt[10], pt[11], // uv 3 525 534 src, // texture source 526 - colors, count); // chroma 535 + colors, count, // chroma 536 + pixelcenter); // pixel center 527 537 } 528 - else return sq_throwerror(vm, "invalid parameters, textri(x1,y1,x2,y2,x3,y3,u1,v1,u2,v2,u3,v3,[texsrc=0],[chroma=off])\n"); 538 + else return sq_throwerror(vm, "invalid parameters, textri(x1,y1,x2,y2,x3,y3,u1,v1,u2,v2,u3,v3,[texsrc=0],[chroma=off],[pixelcenter=false])\n"); 529 539 return 0; 530 540 } 531 541
+3 -2
src/api/wasm.c
··· 280 280 m3ApiGetArg (int32_t, texsrc) 281 281 m3ApiGetArgMem (u8*, trans_colors) 282 282 m3ApiGetArg (int8_t, colorCount) 283 + m3ApiGetArg (bool, pixelcenter) 283 284 if (trans_colors == NULL) { 284 285 colorCount = 0; 285 286 } ··· 287 288 tic_mem* tic = (tic_mem*)getWasmCore(runtime); 288 289 289 290 tic_api_textri(tic, x1, y1, x2, y2, x3, y3, 290 - u1, v1, u2, v2, u3, v3, texsrc, trans_colors, colorCount); 291 + u1, v1, u2, v2, u3, v3, texsrc, trans_colors, colorCount, pixelcenter != 0); 291 292 292 293 m3ApiSuccess(); 293 294 } ··· 991 992 _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "trace", "v(*i)", &wasmtic_trace))); 992 993 _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "tri", "v(iiiiiii)", &wasmtic_tri))); 993 994 _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "trib", "v(iiiiiii)", &wasmtic_trib))); 994 - _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "textri", "v(iiiiiiiiiiiiiii)", &wasmtic_textri))); 995 995 _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "vbank", "i(i)", &wasmtic_vbank))); 996 + _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "textri", "v(iiiiiiiiiiiiiiii)", &wasmtic_textri))); 996 997 997 998 _catch: 998 999 return result;
+6 -1
src/api/wren.c
··· 76 76 foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3)\n\ 77 77 foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src)\n\ 78 78 foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src, alpha_color)\n\ 79 + foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src, alpha_color, pixelcenter)\n\ 79 80 foreign static pix(x, y)\n\ 80 81 foreign static pix(x, y, color)\n\ 81 82 foreign static line(x0, y0, x1, y1, color)\n\ ··· 774 775 count = 1; 775 776 } 776 777 778 + bool pixelcenter = top > 15 ? wrenGetSlotBool(vm, 15) : 0; 779 + 777 780 tic_api_textri(tic, pt[0], pt[1], // xy 1 778 781 pt[2], pt[3], // xy 2 779 782 pt[4], pt[5], // xy 3 ··· 781 784 pt[8], pt[9], // uv 2 782 785 pt[10], pt[11], // uv 3 783 786 src, // texture source 784 - colors, count); // chroma 787 + colors, count, // chroma 788 + pixelcenter); // pixelcenter 785 789 } 786 790 787 791 static void wren_pix(WrenVM* vm) ··· 1376 1380 if (strcmp(signature, "static TIC.textri(_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; 1377 1381 if (strcmp(signature, "static TIC.textri(_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; 1378 1382 if (strcmp(signature, "static TIC.textri(_,_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; 1383 + if (strcmp(signature, "static TIC.textri(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; 1379 1384 1380 1385 if (strcmp(signature, "static TIC.pix(_,_)" ) == 0) return wren_pix; 1381 1386 if (strcmp(signature, "static TIC.pix(_,_,_)" ) == 0) return wren_pix;
+7 -5
src/core/draw.c
··· 635 635 return (b->x - a->x) * (c->y - a->y) - (b->y - a->y) * (c->x - a->x); 636 636 } 637 637 638 - static void drawTri(tic_mem* tic, const Vec2* v0, const Vec2* v1, const Vec2* v2, PixelShader shader, void* data) 638 + static void drawTri(tic_mem* tic, const Vec2* v0, const Vec2* v1, const Vec2* v2, PixelShader shader, void* data, bool pixelcenter) 639 639 { 640 640 ShaderAttr a = {data, v0, v1, v2}; 641 641 ··· 666 666 for(s32 i = 0; i != 3; ++i) 667 667 { 668 668 // pixel center 669 - const double Center = 0.5 - 1e-07; 669 + const double Center = pixelcenter ? 0.5 - 1e-07 : 0.0; 670 670 Vec2 p = {min.x + Center, min.y + Center}; 671 671 672 672 s32 c = (i + 1) % 3, n = (i + 2) % 3; ··· 708 708 &(Vec2){x1, y1}, 709 709 &(Vec2){x2, y2}, 710 710 &(Vec2){x3, y3}, 711 - triColorShader, &color); 711 + triColorShader, &color, 712 + true); 712 713 } 713 714 714 715 void tic_api_trib(tic_mem* tic, float x1, float y1, float x2, float y2, float x3, float y3, u8 color) ··· 799 800 return data->mapping[tic_tool_peek4(data->vram->data, v * TIC80_WIDTH + u)]; 800 801 } 801 802 802 - void tic_api_textri(tic_mem* tic, float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, tic_texture_src texsrc, u8* colors, s32 count) 803 + void tic_api_textri(tic_mem* tic, float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, tic_texture_src texsrc, u8* colors, s32 count, bool pixelcenter) 803 804 { 804 805 TexData texData = 805 806 { ··· 817 818 ? triTexVbankShader 818 819 : texsrc == tic_map_texture 819 820 ? triTexMapShader 820 - : triTexTileShader, &texData); 821 + : triTexTileShader, &texData, 822 + pixelcenter); 821 823 } 822 824 823 825 void tic_api_map(tic_mem* memory, s32 x, s32 y, s32 width, s32 height, s32 sx, s32 sy, u8* colors, u8 count, s32 scale, RemapFunc remap, void* data)