From 07ccc15fc2f0f2abc7f67b51bbfcdc673f6b2869 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 16 Jun 2012 18:02:56 +0300 Subject: [PATCH] Allow node cracking animations of any length --- games/minimal/mods/default/textures/crack.png | Bin 1076 -> 0 bytes .../mods/default/textures/crack_anylength.png | Bin 0 -> 686 bytes src/game.cpp | 18 +++++++-- src/tile.cpp | 38 ++++++++++++++++-- 4 files changed, 49 insertions(+), 7 deletions(-) delete mode 100644 games/minimal/mods/default/textures/crack.png create mode 100644 games/minimal/mods/default/textures/crack_anylength.png diff --git a/games/minimal/mods/default/textures/crack.png b/games/minimal/mods/default/textures/crack.png deleted file mode 100644 index 499783982d553bfecbc596175b492dd0f2346a32..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1076 zcmZvaTS$~q5XZ+YwIp5ZA+bWNP6dWN`A`qqZMU2fSwyIZS|XA%8?t(dZiHqLRIo!m zWCj&>p{O2|fi%0QU7+X&J`HRnl0`)YU7&|fvm3;&+Xv^IIUi@v??3-JM^Yfk(&CjZGCe1m(?5CLW&0z`2CJEWij!oUQCfX;5pNXx`~5oH!4MkMDvvl0m+TTG;gVgaJsY*M|7 z3JVhx5;}C^g_TJN867$HOiC!|*pVkxJK@lyOXjPNp`l1BkeL55&7Z$m(~=+?Khr$# zMU_P?5sB;stC9#ZTTH5UzXhmjv-271y?A965=JJ|%U($Zg{=N&nLm;a&{WTz@_s2wnG6;bk_aF)^Ky1%eJg}MsFi`S)UKSW{!DkFD ztzSFvY0Z;@fznB>jj#J!W4|e%UnlRBzYS>^H?DMeo+{`1b5pVfMt)bzRL*KkhzT(%n;7aUrm}q5thr ze#ND5Zu6pJb6NseURPaI+&)k>Yu=Ad16h?z8v8rix|=&YkH@Fv#sjB=cVgFeHBMgK z9`EfBmmTQ4dh_SHoEha&3@!`@cNU+Uda$jgH2X!*p3*ArDcKdBA9;2A%>FI0D?`hE zpD+1RPYb@BqWLp&QFK GwEO`}y7WW< diff --git a/games/minimal/mods/default/textures/crack_anylength.png b/games/minimal/mods/default/textures/crack_anylength.png new file mode 100644 index 0000000000000000000000000000000000000000..031888a4b45338619071adfae7dd13c61d1ec7a1 GIT binary patch literal 686 zcmV;f0#W^mP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iyh_ z4lxbH1A@)~00J&aL_t(o!|hl*ZUQk7on7S^xr58p8@cmo5OuZ~q;z!DL_*q%n$CiH zOR8KTDNqhEX>2qxW3O!}h=iq;z^tF=_nyZ9JjVSG3ckPBEToc!;VyJ*7plhl-GDsC zzZ@7&SZlj*uDxalYi-v|@SqW_>SNaAkck|~*}bQU-4_gGAy@Q$_5J?$Ui3(dhsZ4F6Sb8?SDB1ZU$Ei4ol~@$%oL#aqQJb#zru+?a zZ>=3AT2EQfyHdu}>GT|=Gd~Wi)rzX!aHdm^O2t4vSuDbmrWnw9a=l&?nG4BuQ2YASN{pN%n_Vm)BR6S`7d%8h5HQtCP`9FNDwxr5pM=Q8%TZ1h(6 zr$#q01RI9oI|Ov`NP>_A>VdY~?N9E(Dn*?bV~g8d4CH?-wZQM*N#GNu5C{m}6^#EORlV5HK}2QId_6^?T5dk+B3d_Lb- z>w#byT5CtG^-DGzm&@g=)_TwT#ORQS!ehWiSL_pKv)RXPw@cCZD-{EbbSz!&F^57b zNyvLr8^f}d0H)6h2ZB?J+k}(@?~$45P076(1M#3z_3>;R1Gbjwf$JA2=VniWn4nYR zE~ruj0BnR?3a@u^jdm}UwQq@2cY?b6g0Qd{geLx!!BPN7rLVM^q+CghjX&3)Unp^N UoYAfR+5i9m07*qoM6N<$f>o$5Gynhq literal 0 HcmV?d00001 diff --git a/src/game.cpp b/src/game.cpp index ac6d13af..83e853b9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1225,6 +1225,16 @@ void the_game( */ Inventory local_inventory(itemdef); + /* + Find out size of crack animation + */ + int crack_animation_length = 5; + { + video::ITexture *t = tsrc->getTextureRaw("crack_anylength.png"); + v2u32 size = t->getOriginalSize(); + crack_animation_length = size.Y / size.X; + } + /* Add some gui stuff */ @@ -2271,20 +2281,20 @@ void the_game( if(dig_time_complete >= 0.001) { - dig_index = (u16)((float)CRACK_ANIMATION_LENGTH + dig_index = (u16)((float)crack_animation_length * dig_time/dig_time_complete); } // This is for torches else { - dig_index = CRACK_ANIMATION_LENGTH; + dig_index = crack_animation_length; } // Don't show cracks if not diggable if(dig_time_complete >= 100000.0) { } - else if(dig_index < CRACK_ANIMATION_LENGTH) + else if(dig_index < crack_animation_length) { //TimeTaker timer("client.setTempMod"); //infostream<<"dig_index="<getOrLoad("crack.png", device); + video::IImage *img_crack = sourcecache->getOrLoad( + "crack_anylength.png", device); if(img_crack && progression >= 0) { @@ -1305,11 +1311,13 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, } else { - img_crack_scaled->copyToWithAlpha( + /*img_crack_scaled->copyToWithAlpha( baseimg, v2s32(0,0), core::rect(v2s32(0,0), dim_base), - video::SColor(255,255,255,255)); + video::SColor(255,255,255,255));*/ + blit_with_alpha(img_crack_scaled, baseimg, + v2s32(0,0), v2s32(0,0), dim_base); } } @@ -1721,6 +1729,30 @@ void overlay(video::IImage *image, video::IImage *overlay) } } +/* + Draw an image on top of an another one, using the alpha channel of the + source image + + This exists because IImage::copyToWithAlpha() doesn't seem to always + work. +*/ +static void blit_with_alpha(video::IImage *src, video::IImage *dst, + v2s32 src_pos, v2s32 dst_pos, v2u32 size) +{ + for(u32 y0=0; y0getPixel(src_x, src_y); + video::SColor dst_c = dst->getPixel(dst_x, dst_y); + dst_c = src_c.getInterpolated(dst_c, (float)src_c.getAlpha()/255.0f); + dst->setPixel(dst_x, dst_y, dst_c); + } +} + void brighten(video::IImage *image) { if(image == NULL) -- 2.30.2