From: DeaDDooMER Date: Fri, 8 Sep 2017 18:20:19 +0000 (+0300) Subject: Rewrited module for particles X-Git-Url: https://deadsoftware.ru/gitweb?p=cavecraft.git;a=commitdiff_plain;h=9115be0a19d5716f33a2e2cba76f3447ce0f4c2f Rewrited module for particles --- diff --git a/BUGS b/BUGS index d57ab45..cd5974e 100644 --- a/BUGS +++ b/BUGS @@ -22,10 +22,11 @@ - Предметы не сгорают в лаве (и никогда не сгорали, но всё же) - Не сбрасывается анимация игрока при старте новой игры - Кактусы не убивают +- Динамит не взравется - просто мигает - Запилить блочный формат сохранений с переменным числом записей и версионированием блоков. - Перепроверить генерацию предметов в cокровищницах -- Перепроверить рост деревьев +- Перепроверить рост деревьев -- cм items_logic.updateBlock -> *_RND - Курсор на ремне должен быть чётче - В бете 8 была поддержка звука, надо вернуть. diff --git a/libs/Lib_particles_store.class b/libs/Lib_particles_store.class deleted file mode 100644 index 53fce20..0000000 Binary files a/libs/Lib_particles_store.class and /dev/null differ diff --git a/libs/Lib_particles_store.java b/libs/Lib_particles_store.java deleted file mode 100644 index 606d3df..0000000 --- a/libs/Lib_particles_store.java +++ /dev/null @@ -1,63 +0,0 @@ -class Lib_particles_store - { - static byte[] particle_type; - static byte[] particle_ani; - static short[] particle_x; - static short[] particle_y; - - public static void reset_particles(int len) - { - particle_type = new byte[len]; - particle_ani = new byte[len]; - particle_x = new short[len]; - particle_y = new short[len]; - } - - public static void set_particle(int id, int type, int ani, int x, int y) - { - particle_type[id] = (byte) type; - particle_ani[id] = (byte) ani; - particle_x[id] = (short) x; - particle_y[id] = (short) y; - } - - public static void set_particle_type(int id, int type) - { - particle_type[id] = (byte) type; - } - - public static void set_particle_ani(int id, int ani) - { - particle_ani[id] = (byte) ani; - } - - public static void set_particle_x(int id, int x) - { - particle_x[id] = (short) x; - } - - public static void set_particle_y(int id, int y) - { - particle_y[id] = (short) y; - } - - public static int get_particle_type(int id) - { - return particle_type[id] & 0xFF; - } - - public static int get_particle_ani(int id) - { - return particle_ani[id] & 0xFF; - } - - public static int get_particle_x(int id) - { - return particle_x[id]; - } - - public static int get_particle_y(int id) - { - return particle_y[id]; - } -} \ No newline at end of file diff --git a/src/CAVE.mpsrc b/src/CAVE.mpsrc index 4f61a7d..0d30584 100644 --- a/src/CAVE.mpsrc +++ b/src/CAVE.mpsrc @@ -6,7 +6,6 @@ uses drop, invui, vars, - particles_store, randoms, memory, worldgen, @@ -146,19 +145,8 @@ procedure ClearTextures; for ix := 0 to 15 do light[ix] := no; - for ix := 0 to 7 do - begin - pr_1[ix] := no; - pr_2[ix] := no; - pr_3[ix] := no; - pr_4[ix] := no; - pr_5[ix] := no; - end; - - bubble := no; - for ix := 0 to 15 do - pr_boom[ix] := no; + Particles.FreeTextures; Mobs.FreeTextures; sky := no; @@ -208,7 +196,7 @@ procedure loadtexture(path:string); console.exec('textures.cfg', 'AUTO'); - player.loadSkin('char_ani.png', path); + Player.LoadSkin('char_ani.png', path); Mobs.LoadTextures(path); im:=ld_tex('gui.png',path,'gui/'); @@ -258,22 +246,7 @@ procedure loadtexture(path:string); for ix:=0 to 15 do light[ix]:=rotate_image_from_image(im,16*ix,0,16,16,0); end; - if load_particles_tex then - begin - im:=ld_tex('particles.png',path,'terrain/'); - for ix:=0 to 7 do - begin - pr_1[ix]:=rotate_image_from_image(im,8*ix,0,8,8,0); - pr_2[ix]:=rotate_image_from_image(im,8*ix,8,8,8,0); - pr_3[ix]:=rotate_image_from_image(im,8*ix,16,8,8,0); - pr_4[ix]:=rotate_image_from_image(im,8*ix,24,8,8,0); - pr_5[ix]:=rotate_image_from_image(im,8*ix,32,8,8,0); - end; - bubble:=rotate_image_from_image(im,0,40,8,8,0); - im:=ld_tex('explosion.png',path,'terrain/'); - for ix:=0 to 15 do - pr_boom[ix]:=rotate_image_from_image(im,32*ix,0,32,32,0); - end; + Particles.LoadTextures(path); im:=ld_tex('partition.png',path,'gui/'); gui[18]:=rotate_image_from_image(im,0,0,84,42,0); @@ -338,18 +311,12 @@ procedure cleargame; //anim_del2:=0; - inv.resetData; - - chest.resetData; - - furnace.resetData; - - drop.resetData; - + Inv.ResetData; + Chest.ResetData; + Furnace.ResetData; + Drop.ResetData; Mobs.ResetData; - - //gb_up_pa:=0; - reset_particles(max_particles+1); + Particles.ResetData; for ix:=0 to 255 do begin @@ -516,31 +483,19 @@ procedure saveworld(path:string); write_byte(getBackMap(ix)); write_byte(getBiomMap(ix)); end; - drw_load_line('Chests',55); - //Chests - chest.saveData; - drw_load_line('Furnaces',60); - //Furnaces - furnace.saveData; - drw_load_line('Mobs',70); - //Mobs + + drw_load_line('Chests', 55); + Chest.SaveData; + drw_load_line('Furnaces', 60); + Furnace.SaveData; + drw_load_line('Mobs', 70); Mobs.SaveData; - drw_load_line('Drop',80); - //Drop - drop.saveData; - drw_load_line('Particles',85); - //Particles - writeint(max_particles); - write_byte(gb_up_pa); - for ix:=0 to max_particles do - begin - write_byte(get_particle_type(ix)); - write_byte(get_particle_ani(ix)); - writeint(get_particle_x(ix)); - writeint(get_particle_y(ix)); - end; - drw_load_line('Other',90); - //Other + drw_load_line('Drop', 80); + Drop.SaveData; + drw_load_line('Particles', 85); + Particles.SaveData; + + drw_load_line('Other', 90); write_byte(updx); write_byte(updy); writebool(osadki); @@ -648,31 +603,17 @@ function loadworld(path:string):boolean; setBackMap(read_byte, ix); setBiomMap(read_byte, ix); end; - drw_load_line('Chests',55); - //Chests - chest.loadData; - drw_load_line('Furnaces',60); - //Furnaces - furnace.loadData; - //Mobs + drw_load_line('Chests', 55); + Chest.LoadData; + drw_load_line('Furnaces', 60); + Furnace.LoadData; Mobs.LoadData; - drw_load_line('Drop',80); - //Drop - drop.loadData; - drw_load_line('Particles',85); - //Particles - max_particles:=readint; - reset_particles(max_particles+1); - gb_up_pa:=read_byte; - for ix:=0 to max_particles do - begin - set_particle_type(ix,read_byte); - set_particle_ani(ix,read_byte); - set_particle_x(ix,readint); - set_particle_y(ix,readint); - end; - drw_load_line('Other',90); - //Other + drw_load_line('Drop', 80); + Drop.LoadData; + drw_load_line('Particles', 85); + Particles.LoadData; + + drw_load_line('Other',90); updx:=read_byte; updy:=read_byte; osadki:=readbool; @@ -1486,7 +1427,7 @@ var end; else if m_cur=-1 then begin - s_particles:=not s_particles; + Particles.enabled := not Particles.enabled; end; else if m_cur=0 then begin @@ -1540,7 +1481,7 @@ var drw_btn('Light:'+light_type,-3,m_cur,0,1); drw_btn('Weather:'+ifosad,-2,m_cur,0,1); - drw_btn('Particles:'+s_particles,-1,m_cur,0,1); + drw_btn('Particles:' + Particles.enabled, -1, m_cur, 0, 1); drw_btn('Hide GUI:'+not drawgui,0,m_cur,0,1); drw_btn('Touch:'+(load_key_tex>0),1,m_cur,0,1); drw_btn('JPEG:'+s_jpeg_quality,2,m_cur,0,1); @@ -2036,15 +1977,11 @@ procedure draw; draw_block(ix,iy); end; {===================[drop]===================} - drop.draw(camx, camy); + Drop.Draw(camx, camy); {===================[particles]===================} - if s_particles then draw_particle; + Particles.Draw(camx, camy); {===================[player]===================} - if hp>0 then - begin - player.draw(camx, camy); - end; - + Player.Draw(camx, camy); {===================[mobs]===================} Mobs.Draw(camx, camy); {===================[draw_blocks]===================} @@ -2922,7 +2859,7 @@ procedure game; osadki_ani:=osadki_ani+1; if osadki_ani>7 then osadki_ani:=0; - if random(20)=random(20) then create_particle(6,x,y); + if Random(20) = Random(20) then Particles.Create(Particles.bubble, x, y); if gamemode=1 then begin hp:=666; hunger:=666; end; @@ -2934,8 +2871,7 @@ procedure game; //if s_spawn_mob then if random(4096)=1547 then megaspawn; Mobs.Update; - - if particle_upd then update_particle; + Particles.Update; if light_type>0 then begin diff --git a/src/mobs.pas b/src/Mobs.pas similarity index 100% rename from src/mobs.pas rename to src/Mobs.pas diff --git a/src/Particles.mpsrc b/src/Particles.mpsrc new file mode 100644 index 0000000..4b93e19 --- /dev/null +++ b/src/Particles.mpsrc @@ -0,0 +1,166 @@ +unit Particles; + +interface + + const + none = 0; + whiteSmoke = 1; + graySmoke = 2; + blackSmoke = 3; + redSmoke = 4; + pinkSmoke = 5; + bubble = 6; + explosion = 7; + + var + enabled : boolean; + + procedure Create(typ, x, y : integer); + procedure Update; + procedure Draw(camx, camy : integer); + + procedure LoadTextures(path : string); + procedure FreeTextures; + + procedure SaveData; + procedure LoadData; + procedure ResetData; + +implementation + + uses vars, maps, func, canvas, jsr75i; + + const + lastParticle = 64; + + var + tail : integer; + ptype, px, py, pa : array [0..lastParticle] of integer; + smokeSprites : array [0..4, 0..7] of image; + explosionSprites : array [0..15] of image; + bubbleSprite : image; + + procedure Create(typ, x, y : integer); + begin + if not enabled then exit; + ptype[tail] := typ; + px[tail] := x; + py[tail] := y; + pa[tail] := 0; + tail := (tail + 1) mod lastParticle; + end; + + procedure Update; + var + typ, i : integer; + begin + if not enabled then exit; + for i := 0 to lastParticle do if ptype[i] <> none then begin + typ := ptype[i]; + if (typ >= whiteSmoke) and (typ <= pinkSmoke) then begin + py[i] := py[i] - 1; + pa[i] := pa[i] + 1; + if pa[i] > 14 then ptype[i] := none; + end else if typ = bubble then begin + py[i] := py[i] - 1; + if GetMap(px[i] / 16, py[i] / 16) <> 50 then ptype[i] := none; + end else if typ = explosion then begin + pa[i] := pa[i] + 1; + if pa[i] > 15 then ptype[i] := none; + end; + end; + end; + + procedure Draw(camx, camy : integer); + var + typ, i : integer; + begin + if not enabled then exit; + for i := 0 to lastParticle do if ptype[i] <> none then begin + typ := ptype[i]; + if (typ >= whiteSmoke) and (typ <= pinkSmoke) then begin + DrawImage(smokeSprites[typ - 1, pa[i] / 2], px[i] - camx, py[i] - camy); + end else if typ = bubble then begin + DrawImage(bubbleSprite, px[i] - camx, py[i] - camy) + end else if typ = explosion then begin + DrawImage(explosionSprites[pa[i]], px[i] - camx, py[i] - camy); + end; + end; + end; + + procedure LoadTextures(path : string); + var + im : image; + i, j : integer; + begin + if not enabled then exit; + im := ld_tex('particles.png', path, 'terrain/'); + for i := 0 to 4 do begin + for j := 0 to 7 do begin + smokeSprites[i, j] := rotate_image_from_image(im, 8 * j, 8 * i, 8, 8, 0); + end; + end; + + bubbleSprite := rotate_image_from_image(im, 0, 40, 8, 8, 0); + + im := ld_tex('explosion.png', path, 'terrain/'); + for i := 0 to 15 do begin + explosionSprites[i] := rotate_image_from_image(im, 32 * i, 0, 32, 32, 0); + end; + end; + + procedure FreeTextures; + var + nullimg : image; + i, j : integer; + begin + for i := 0 to 4 do begin + for j := 0 to 7 do begin + smokeSprites[i, j] := nullimg; + end; + end; + + bubbleSprite := nullimg; + + for i := 0 to 15 do begin + explosionSprites[i] := nullimg; + end; + end; + + procedure SaveData; + var + i : integer; + begin + for i := 0 to lastParticle do begin + write_byte(ptype[i]); + WriteInt(px[i]); + WriteInt(py[i]); + WriteInt(pa[i]); + end; + end; + + procedure LoadData; + var + i : integer; + begin + for i := 0 to lastParticle do begin + ptype[i] := read_byte; + px[i] := ReadInt; + py[i] := ReadInt; + pa[i] := ReadInt; + end; + end; + + procedure ResetData; + var + i : integer; + begin + for i := 0 to lastParticle do begin + ptype[i] := none; + px[i] := 0; + py[i] := 0; + pa[i] := 0; + end; + end; + +end. diff --git a/src/phy.pas b/src/Phy.pas similarity index 100% rename from src/phy.pas rename to src/Phy.pas diff --git a/src/player.mpsrc b/src/Player.mpsrc similarity index 95% rename from src/player.mpsrc rename to src/Player.mpsrc index 812a2b4..b41c8e3 100644 --- a/src/player.mpsrc +++ b/src/Player.mpsrc @@ -1,4 +1,4 @@ -unit player; +unit Player; interface diff --git a/src/console.pas b/src/console.pas index 309fc28..c6c2f69 100644 --- a/src/console.pas +++ b/src/console.pas @@ -8,7 +8,6 @@ interface osadki:boolean; bl_upd:integer; s_get_drp:boolean; - particle_upd:boolean; drw_back:boolean; drw_sm:boolean; s_max_fps:integer; @@ -17,13 +16,11 @@ interface light_type:integer; ifosad:boolean; - //s_particles:boolean; - module load_sm:integer; load_sky_siz:integer; load_back_tex:boolean; load_weather_tex:boolean; - load_particles_tex:boolean; load_light_tex:boolean; load_gui_tex:boolean; @@ -40,7 +37,6 @@ interface sd:string; EOFstr, ENDstr:boolean; - //max_particles:integer; - module procedure save_settings; procedure load_settings; @@ -49,11 +45,31 @@ interface procedure addToLog(str:string); implementation -uses keyboard,particles_store,vars,maps,items,canvas,mobs,worldgen,jsr75i,particles,func, player,sensor, drop, inv, furnace, items_store, video; + + uses + keyboard, + vars, + maps, + items, + canvas, + mobs, + worldgen, + jsr75i, + particles, + func, + player, + sensor, + drop, + inv, + furnace, + items_store, + video; + const CON_LOG_SIZE=9; PARSER_MAX_STR=15; MAX_IMGREG=2; + var logSTR: array [0..CON_LOG_SIZE] of string; lastCommand:string; @@ -151,7 +167,7 @@ procedure save_settings; t:=addRecordStoreEntry(rs,version); t:=addRecordStoreEntry(rs,''+light_type); t:=addRecordStoreEntry(rs,''+ifosad); - t:=addRecordStoreEntry(rs,''+s_particles); + t:=addRecordStoreEntry(rs, '' + Particles.enabled); t:=addRecordStoreEntry(rs,''+drawgui); t:=addRecordStoreEntry(rs,''+s_jpeg_quality); t:=addRecordStoreEntry(rs,''+load_key_tex); @@ -176,7 +192,7 @@ procedure load_settings; end; light_type:=stringtointeger(readRecordStoreEntry(rs,2)); ifosad:=sett_ld_bool(readRecordStoreEntry(rs,3)); - s_particles:=sett_ld_bool(readRecordStoreEntry(rs,4)); + Particles.enabled := sett_ld_bool(readRecordStoreEntry(rs, 4)); drawgui:=sett_ld_bool(readRecordStoreEntry(rs,5)); s_jpeg_quality:=stringtointeger(readRecordStoreEntry(rs,6)); load_key_tex:=stringtointeger(readRecordStoreEntry(rs,7)); @@ -529,12 +545,6 @@ procedure exeCommand(str:string); if com='GET_DRP' then s_get_drp:=strToBool(nextWord); else - {if com='AI_UPD' then - ai_upd:=strToBool(nextWord); - else} - if com='PRT_UPD' then - particle_upd:=strToBool(nextWord); - else if com='MAX_FPS' then s_max_fps:=decodeInt(nextWord); else if com='DRW_BACK' then @@ -571,7 +581,7 @@ procedure exeCommand(str:string); light_type:=decodeInt(nextWord); else if com='S_PARTICLES' then - s_particles:=strToBool(nextWord); + Particles.enabled := strToBool(nextWord); else if com='LOAD_SKY' then load_sky_siz:=decodeInt(nextWord); @@ -585,9 +595,6 @@ procedure exeCommand(str:string); if com='LOAD_WEATHER_TEX' then load_weather_tex:=strToBool(nextWord); else - if com='LOAD_PARTICLES_TEX' then - load_particles_tex:=strToBool(nextWord); - else if com='LOAD_LIGHT_TEX' then load_light_tex:=strToBool(nextWord); else @@ -612,12 +619,6 @@ procedure exeCommand(str:string); if com='LOAD_MINIMAP_TEX' then load_minimap_tex:=strToBool(nextWord); else - if com='MAX_PARTICLES' then - begin - max_particles:=decodeInt(nextWord); - reset_particles(max_particles+1); - end; - else if com='EXEC' then begin tmp:=nextWord; diff --git a/src/items_logic.mpsrc b/src/items_logic.mpsrc index efcee9f..a3d41c0 100644 --- a/src/items_logic.mpsrc +++ b/src/items_logic.mpsrc @@ -148,7 +148,7 @@ procedure boom(rr,mm,xx,yy:integer); begin if 30<=random(100) then destroy_block_1(getmap(ix,iy),ix,iy); setmap(0,ix,iy); - create_particle(7,(ix*16)+8-16,(iy*16)+8-16); + Particles.Create(Particles.explosion, (ix * 16) + 8 - 16, (iy * 16) + 8 - 16); end; end; minhp:=minhp/360; @@ -1184,7 +1184,7 @@ procedure fluidLogic(x, y, ifbx, thenbx, ifby, thenby:integer); procedure updateBlock(x, y:integer); const GRASS_RND=128; - TORCH_RND=128; + TORCH_RND=10; SPAWN_RND=128; SPAWN_RAD=128; GENWOOD_RND=1024; @@ -1238,7 +1238,7 @@ procedure updateBlock(x, y:integer); if block=26 then begin if random(TORCH_RND)=random(TORCH_RND) then - create_particle(2, x*16+4, y*16+4); + Particles.Create(Particles.graySmoke, x * 16 + 4, y * 16 + 4); end; else if block=50 then @@ -1346,7 +1346,7 @@ procedure updateBlock(x, y:integer); if block=105 then begin if random(TORCH_RND)=random(TORCH_RND) then - create_particle(4, x*16+4, y*16+4); + Particles.Create(Particles.redSmoke, x * 16 + 4, y * 16 + 4); end; else if (block = 106) or (block = 125) then diff --git a/src/particles.mpsrc b/src/particles.mpsrc deleted file mode 100644 index ba3c7c4..0000000 --- a/src/particles.mpsrc +++ /dev/null @@ -1,139 +0,0 @@ -unit particles; - -interface - var - bubble:image; - pr_1:array [0..7] of image; - none1:image; - pr_2:array [0..7] of image; - none2:image; - pr_3:array [0..7] of image; - none3:image; - pr_4:array [0..7] of image; - none4:image; - pr_5:array [0..7] of image; - none5:image; - pr_boom:array [0..15] of image; - none6:image; - - max_particles:integer; - s_particles:boolean; - gb_up_pa:integer; - - procedure create_particle(tp,ix,iy:integer); - procedure update_particle; - procedure draw_particle; - -implementation - uses vars,maps,particles_store; - -procedure create_particle(tp,ix,iy:integer); - var - i:integer; - begin - if s_particles=true then - for i:=0 to max_particles do - if get_particle_type(i)=0 then - begin - set_particle(i,tp,0,ix,iy); - exit; - end; - end; - -procedure null_particle(i:integer); - begin - set_particle(i,0,0,0,0); - end; - -procedure pr_ai_1(i,maxani:integer); - begin - set_particle_y(i,get_particle_y(i)-1); - set_particle_ani(i,get_particle_ani(i)+1); - if get_particle_ani(i)>maxani then null_particle(i); - end; - -procedure pr_ai_bubble(i:integer); - var - xx,yy:integer; - begin - set_particle_y(i,get_particle_y(i)-1); - xx:=get_particle_x(i) div 16; - yy:=get_particle_y(i) div 16; - if getmap(xx,yy)<>50 then null_particle(i); - end; - -procedure pr_ai_boom(i:integer); - begin - set_particle_ani(i,get_particle_ani(i)+1); - if get_particle_ani(i)>15 then null_particle(i); - end; - -procedure update_particle; - var - i:integer; - begin - if s_particles=true then - begin - for i:=0 to max_particles do - if get_particle_type(i)>0 then - begin - if get_particle_type(i)=1 then pr_ai_1(i,5); else - if get_particle_type(i)=2 then pr_ai_1(i,5); else - if get_particle_type(i)=3 then pr_ai_1(i,5); else - if get_particle_type(i)=4 then pr_ai_1(i,5); else - if get_particle_type(i)=5 then pr_ai_1(i,5); else - if get_particle_type(i)=6 then pr_ai_bubble(i); else - if get_particle_type(i)=7 then pr_ai_boom(i); else - null_particle(i); - end; - gb_up_pa:=gb_up_pa+1; - if gb_up_pa>=2 then gb_up_pa:=0; - end; - end; - -procedure draw_particle; - var - i:integer; - begin - for i:=0 to max_particles do - if get_particle_type(i)>0 then - begin - if get_particle_type(i)=1 then - begin - if (get_particle_x(i)-camx>-8) and (get_particle_x(i)-camx-8) and (get_particle_y(i)-camy-8) and (get_particle_x(i)-camx-8) and (get_particle_y(i)-camy-8) and (get_particle_x(i)-camx-8) and (get_particle_y(i)-camy-8) and (get_particle_x(i)-camx-8) and (get_particle_y(i)-camy-8) and (get_particle_x(i)-camx-8) and (get_particle_y(i)-camy-8) and (get_particle_x(i)-camx-8) and (get_particle_y(i)-camy-32) and (get_particle_x(i)-camx-32) and (get_particle_y(i)-camy