From d070670f189ec66ed2ac6b45834a192c004bc92f Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sat, 14 Mar 2020 19:24:27 +0300 Subject: [PATCH] fully separate render --- src/files.h | 3 + src/game.c | 5 +- src/main.c | 1 + src/menu.c | 1 + src/miscc.c | 8 +- src/redraw.c | 3 +- src/render.c | 176 +++++++++++++++++++++++++++++++++++++++++- src/render.h | 7 ++ src/vga.c | 26 +------ src/vga.h | 1 + src/view.c | 211 ++++++++++----------------------------------------- src/view.h | 3 +- 12 files changed, 239 insertions(+), 206 deletions(-) diff --git a/src/files.h b/src/files.h index f9862ca..d6b6098 100644 --- a/src/files.h +++ b/src/files.h @@ -67,3 +67,6 @@ void F_randmus(char*);// extern char wads[MAX_WADS][__MAX_PATH]; extern int wad_num; + +int F_getsprid(char n[4],int s,int d); +int F_getresid(char *n); diff --git a/src/game.c b/src/game.c index 8027592..4ae9e11 100644 --- a/src/game.c +++ b/src/game.c @@ -294,7 +294,7 @@ void G_act(void) { if(g_st==GS_BVIDEO) G_start(); else goto inter; } - V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200); +// V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200); return; }else if(g_st==GS_ENDANIM || g_st==GS_END2ANIM || g_st==GS_END3ANIM) { if(!A8_nextframe()) { @@ -304,7 +304,7 @@ void G_act(void) { case GS_END3ANIM: g_st=GS_ENDSCR;lastkey=0;break; }g_sttm=0;return; } - V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200); +// V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200); return; }else if(g_st==GS_DARKEN) { g_st=GS_END2ANIM;A8_start("CREDITS"); @@ -351,7 +351,6 @@ void G_act(void) { if(_2pl) {pl2.hit=0;pl2.hito=-3;} G_code(); - W_act(); IT_act(); SW_act(); if(_2pl) { diff --git a/src/main.c b/src/main.c index 7bd73d4..81c257c 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,7 @@ #include "menu.h" #include "player.h" #include "my.h" +#include "render.h" #include diff --git a/src/menu.c b/src/menu.c index a934da7..7d5f374 100644 --- a/src/menu.c +++ b/src/menu.c @@ -34,6 +34,7 @@ #include "switch.h" #include "menu.h" #include "misc.h" +#include "render.h" #include #include diff --git a/src/miscc.c b/src/miscc.c index 7c69aea..2ece443 100644 --- a/src/miscc.c +++ b/src/miscc.c @@ -33,6 +33,7 @@ #include "dots.h" #include "monster.h" #include "misc.h" +#include "render.h" //#define WD 200 //#define HT 98 @@ -389,10 +390,9 @@ int Z_moveobj(obj_t *p) { return st; } -void Z_splash(obj_t *p,int n) { - Z_sound(bulsnd[0],128); - DOT_water(p->x,p->y-p->h/2,p->xv+p->vx,p->yv+p->vy,n, - (intptr_t)walp[wfront]-1); +void Z_splash (obj_t *p, int n) { + Z_sound(bulsnd[0], 128); + DOT_water(p->x, p->y-p->h / 2, p->xv + p->vx, p->yv + p->vy, n, R_get_special_id(wfront)); } void Z_calc_time(dword t,word *h,word *m,word *s) diff --git a/src/redraw.c b/src/redraw.c index 326dafc..032aa61 100644 --- a/src/redraw.c +++ b/src/redraw.c @@ -19,13 +19,14 @@ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +/* #include #include #include //#include "..\averr.h" #include "vga.h" #include "glob.h" -/* + #define MAXRECT 500 typedef struct{short x,w,y,h;}rect; diff --git a/src/render.c b/src/render.c index c5494a4..5f16f7e 100644 --- a/src/render.c +++ b/src/render.c @@ -1,5 +1,7 @@ #include #include +#include // abs() +#include #include "glob.h" #include "render.h" #include "view.h" @@ -15,6 +17,8 @@ #include "smoke.h" #include "fx.h" #include "memory.h" +#include "files.h" +#include "error.h" // game static vgaimg *scrnh[3]; // TITLEPIC INTERPIC ENDPIC @@ -55,6 +59,15 @@ static char std_pal[256][3]; static byte gamcor[5][64]={ #include "gamma.dat" }; +// walls +#define ANIT 5 +static vgaimg *walp[256]; +static int walh[256]; +static byte walani[256]; +static int anih[ANIT][5]; +static byte anic[ANIT]; +static int max_textures; +static vgaimg *horiz; extern byte bright[256]; // vga.c extern byte mixmap[256][256]; // vga.c @@ -62,7 +75,6 @@ extern byte clrmap[256*12]; // vga.c extern int g_trans; // game.c extern byte transdraw; // game.c -extern void *horiz; // view.c extern int sky_type; // view.c extern int lt_time, lt_type, lt_side, lt_ypos, lt_force; // game.c @@ -71,8 +83,6 @@ extern char g_music[8]; // game.c extern short snd_vol; // sound.c extern short mus_vol; // music.c -void Z_drawfld(byte *, int); // vga.c - /* --- misc --- */ static void *Z_getspr (char n[4], int s, int d, char *dir) { @@ -286,6 +296,30 @@ static void Z_drawmanspr (int x, int y, void *p, char d, byte color) { } } +static void Z_drawfld (byte *fld, int bg) { + byte *p = fld; + int x, y; + for (y = 0; y < FLDH; y++) { + for (x = 0; x < FLDW; x++) { + int sx = x * CELW - w_x + WD / 2; + int sy = y * CELH - w_y + HT / 2 + 1 + w_o; + int id = *p; + if (id != 0) { + int spc = R_get_special_id(id); + if (spc <= 3) { + if (!bg) { + byte *cmap = clrmap + (spc + 7) * 256; + V_remap_rect(sx, sy, CELW, CELH, cmap); + } + } else { + V_pic(sx, sy, walp[id]); + } + } + p++; + } + } +} + /* --- menu --- */ static int gm_tm = 0; // ??? @@ -828,9 +862,26 @@ static void pl_info (player_t *p, int y) { Z_gotoxy(255, y + 15); Z_printbf("%u.%u", t / 10, t % 10); } +static void W_act (void) { + int i, a; + if (g_time % 3 == 0) { + for (i = 1; i < 256; ++i) { + a = walani[i]; + if (a != 0) { + anic[a]++; + if (anih[a][anic[a]] == -1) { + anic[a] = 0; + } + walp[i] = V_getvgaimg(anih[a][anic[a]]); + } + } + } +} + void R_draw (void) { int h; word hr, mn, sc; + W_act(); if (g_trans && !transdraw) { return; } @@ -1168,6 +1219,125 @@ void R_alloc (void) { mslotl = V_loadvgaimg("M_LSLEFT"); mslotm = V_loadvgaimg("M_LSCNTR"); mslotr = V_loadvgaimg("M_LSRGHT"); + // walls + static char *anm[ANIT - 1][5] = { + {"WALL22_1", "WALL23_1", "WALL23_2", NULL, NULL}, + {"WALL58_1", "WALL58_2", "WALL58_3", NULL, NULL}, + {"W73A_1", "W73A_2", NULL, NULL, NULL}, + {"RP2_1", "RP2_2", "RP2_3", "RP2_4", NULL} + }; + for (i = 1; i < ANIT; i++) { + for (j = 0; anm[i - 1][j]; j++) { + anih[i][j] = F_getresid(anm[i - 1][j]); + } + for(; j < 5; j++) { + anih[i][j] = -1; + } + } +} + +void R_get_name (int n, char s[8]) { + if (walh[n] == -1) { + memset(s, 0, 8); + } else if (walh[n] == -2) { + memcpy(s, "_WATER_", 8); + s[7] = (char)((intptr_t)walp[n] - 1 + '0'); + } else { + F_getresname(s, walh[n] & 0x7FFF); + } +} + +static short getani (char n[8]) { + if (strncasecmp(n, "WALL22_1", 8) == 0) { + return 1; + } else if (strncasecmp(n, "WALL58_1", 8) == 0) { + return 2; + } else if (strncasecmp(n, "W73A_1", 8) == 0) { + return 3; + } else if (strncasecmp(n, "RP2_1", 8) == 0) { + return 4; + } else { + return 0; + } +} + +int R_get_special_id (int n) { + assert(n >= 0 && n < 256); + intptr_t x = (intptr_t)walp[n] - 1; + return x > 0 && x <= 3 ? x : 0; +} + +void R_begin_load (void) { + int i; + for (i = 0; i < max_textures; i++) { +// if (walp[i] != NULL && walh[i] >= 0) { +// M_unlock(walp[i]); +// } + walh[i] = -1; + walp[i] = NULL; + walswp[i] = i; + walani[i] = 0; + } + memset(anic, 0, sizeof(anic)); + max_textures = 0; +} + +void R_load (char s[8], int f) { + assert(max_textures < 256); + if (!s[0]) { + walh[max_textures] = -1; + walp[max_textures] = NULL; + } else { + if (strncasecmp(s, "_WATER_", 7) == 0) { + walh[max_textures] = -2; + walp[max_textures] = (void*)((intptr_t)s[7] - '0' + 1); + } else { + walh[max_textures] = F_getresid(s); + walp[max_textures] = V_getvgaimg(walh[max_textures]); + if (f) { + walh[max_textures] |= 0x8000; + } + if (s[0] == 'S' && s[1] == 'W' && s[4] == '_') { + walswp[max_textures] = 0; + } + } + walani[max_textures] = getani(s); + } + max_textures++; +} + +void R_end_load (void) { + int i, j, k, g; + char s[8]; + j = max_textures; + for (i = 1; i < 256 && j < 256; i++) { + if (walswp[i] == 0) { + R_get_name(i, s); + s[5] ^= 1; + g = F_getresid(s) | (walh[i] & 0x8000); + k = 1; + while (k < 256 && walh[k] != g) { + k += 1; + } + if (k >= 256) { + k = j; + j += 1; + walh[k] = g; + walp[k] = V_getvgaimg(g); + walf[k] = g & 0x8000 ? 1 : 0; + } + walswp[i] = k; + walswp[k] = i; + } + } +} + +void R_loadsky (int sky) { + char s[6]; + strcpy(s, "RSKY1"); + s[4] = '0' + sky; + M_unlock(horiz); + horiz = V_loadvgaimg(s); } void R_setgamma(int g) { diff --git a/src/render.h b/src/render.h index 8026af7..9226e99 100644 --- a/src/render.h +++ b/src/render.h @@ -6,3 +6,10 @@ void R_done (void); void R_setgamma (int g); int R_getgamma (void); void R_toggle_fullscreen (void); + +void R_get_name (int n, char s[8]); +int R_get_special_id (int n); +void R_begin_load (void); +void R_load (char s[8], int f); +void R_end_load (void); +void R_loadsky (int sky); diff --git a/src/vga.c b/src/vga.c index 21e8b4c..0d16859 100644 --- a/src/vga.c +++ b/src/vga.c @@ -27,6 +27,7 @@ #include "view.h" #include "memory.h" #include "misc.h" +#include "files.h" #include @@ -323,31 +324,6 @@ void V_remap_rect(int x,int y,int w,int h,byte *cmap) mappixel(cx,cy,cmap); } -void Z_drawfld (byte *fld, int bg) -{ - byte *p = fld; - int x, y; - for (y = 0; y < FLDH; y++) { - for (x = 0; x < FLDW; x++) { - int sx = x * CELW - w_x + WD / 2; - int sy = y * CELH - w_y + HT / 2 + 1 + w_o; - if (*p) { - vgaimg *pic = walp[*p]; - // special pointer value setted for _WATER_* in view.c - if ((intptr_t)pic <= 3) { - if (!bg) { - byte *cmap = clrmap + ((intptr_t)pic+7)*256; - V_remap_rect(sx, sy, CELW, CELH, cmap); - } - } else { - V_pic(sx, sy, pic); - } - } - p++; - } - } -} - void V_toggle() { if (!SDL_WM_ToggleFullScreen(screen)) { diff --git a/src/vga.h b/src/vga.h index cc90ca5..48392c2 100644 --- a/src/vga.h +++ b/src/vga.h @@ -228,6 +228,7 @@ extern void *vf_font; // виртуальный экран extern unsigned char scrbuf[64000]; +void V_remap_rect(int x,int y,int w,int h,byte *cmap); void V_toggle(); void V_rotspr (int x, int y, vgaimg* i, int d); diff --git a/src/view.c b/src/view.c index 0c274fc..73953d7 100644 --- a/src/view.c +++ b/src/view.c @@ -40,34 +40,17 @@ #include "map.h" #include "sound.h" #include "my.h" +#include "render.h" -#define ANIT 5 - -/* -#define WD 200 -#define HT 98 - -#define MAXX (FLDW*CELW-WD/2) -#define MAXY (FLDH*CELH-HT/2) -*/ - -int WD; // -int HT; // +int WD; +int HT; extern map_block_t blk; -void V_remap_rect(int,int,int,int,byte *); - byte w_horiz=ON; -void *horiz=NULL;//static void *horiz=NULL; int w_o,w_x,w_y,sky_type=1; -void *walp[256]; dword walf[256]; -int walh[256]; byte walswp[256]; -byte walani[256]; -int anih[ANIT][5]; -byte anic[ANIT]; byte fldb[FLDH][FLDW]; byte fldf[FLDH][FLDW]; byte fld[FLDH][FLDW]; @@ -75,31 +58,12 @@ byte fld[FLDH][FLDW]; extern int lt_time,lt_type,lt_side,lt_ypos; extern void *ltn[2][2]; -static void getname (int n, char *s) { - if (walh[n] == -1) { - memset(s, 0, 8); - } else if (walh[n] == -2) { - memcpy(s, "_WATER_", 8); - s[7] = (char)((intptr_t)walp[n] - 1 + '0'); - } else { - F_getresname(s, walh[n] & 0x7FFF); - } -} - -static short getani(char *n) { - if(strncasecmp(n,"WALL22_1",8)==0) return 1; - if(strncasecmp(n,"WALL58_1",8)==0) return 2; - if(strncasecmp(n,"W73A_1",8)==0) return 3; - if(strncasecmp(n,"RP2_1",8)==0) return 4; - return 0; -} - -void W_savegame(FILE* h) { +void W_savegame (FILE* h) { char s[8]; int i; myfwrite32(sky_type, h); for(i = 1; i < 256; ++i) { - getname(i, s); + R_get_name(i, s); myfwrite(s, 8, 1, h); } for (i = 0; i < 256; i++) { @@ -113,32 +77,20 @@ void W_savegame(FILE* h) { myfwrite(fldf, FLDW*FLDH, 1, h); } -void W_loadgame(FILE* h) { - char s[8]; +void W_loadgame (FILE* h) { int i; + char s[256][8]; sky_type = myfread32(h); + R_loadsky(sky_type); for (i = 1; i < 256; ++i) { - walani[i]=0; - myfread(s, 8, 1, h); - if (!s[0]) { - walh[i] = -1; - walp[i] = NULL; - } else { - walani[i] = getani(s); - if (strncasecmp(s, "_WATER_", 7) == 0) { - walh[i] = -2; - walp[i] = (void*)((intptr_t)s[7] - '0' + 1); - } else { - walh[i] = F_getresid(s); - walp[i] = V_getvgaimg(walh[i]); - } - } + myfread(s[i], 8, 1, h); } - for (i = 0; i < 256; i++) { + R_begin_load(); + R_load("", 0); // empty + i = myfread32(h); // ignore + for (i = 1; i < 256; i++) { walf[i] = myfread32(h); - if (i > 0 && walf[i] & 1) { - walh[i] |= 0x8000; - } + R_load(s[i], walf[i] & 1); } for (i = 0; i < 256; i++) { walswp[i] = myfread8(h); @@ -146,27 +98,10 @@ void W_loadgame(FILE* h) { myfread(fldb, FLDW*FLDH, 1, h); myfread(fld, FLDW*FLDH, 1, h); myfread(fldf, FLDW*FLDH, 1, h); - strcpy(s, "RSKY1"); - s[4] = '0' + sky_type; - M_unlock(horiz); - horiz = V_loadvgaimg(s); + R_end_load(); } void W_init(void) { - int i,j; - static char *anm[ANIT-1][5]={ - {"WALL22_1","WALL23_1","WALL23_2",NULL,NULL}, - {"WALL58_1","WALL58_2","WALL58_3",NULL,NULL}, - {"W73A_1","W73A_2",NULL,NULL,NULL}, - {"RP2_1","RP2_2","RP2_3","RP2_4",NULL} - }; - - for(i=1;i 0; ++i, blk.sz -= 9) { - myfread(w.n, 8, 1, h); - w.t = myfread8(h); - if (strncasecmp(w.n, "_WATER_", 7) == 0) { - walp[i] = (void*)((intptr_t)w.n[7] - '0' + 1); - walh[i] = -2; - } else { - walh[i] = F_getresid(w.n); - walp[i] = V_getvgaimg(walh[i]); - if (w.n[0] == 'S' && w.n[1] == 'W' && w.n[4] == '_') { - walswp[i] = 0; - } - walf[i] = w.t ? 1 : 0; - if (w.t) { - walh[i] |= 0x8000; - } - if (strncasecmp(w.n, "VTRAP01", 8) == 0) { - walf[i] |= 2; - } - walani[i] = getani(w.n); - } - } - for (j = i, i = 1; i < 256 && j < 256; ++i) { - if (walswp[i] == 0) { - F_getresname(w.n, walh[i] & 0x7FFF); - w.n[5] ^= 1; - g = F_getresid(w.n) | (walh[i] & 0x8000); - k = 1; - while (k < 256 && walh[k] != g) { - k += 1; - } - if(k >= 256) { - k = j; - j += 1; - walh[k] = g; - walp[k] = V_getvgaimg(g); - walf[k] = g & 0x8000 ? 1 : 0; - } - walswp[i] = k; - walswp[k] = i; + R_begin_load(); + R_load("", 0); // empty + for (i = 1; i < 256 && blk.sz > 0; i++, blk.sz -= 9) { + myfread(s, 8, 1, h); + t = myfread8(h); + R_load(s, t); + if (strncasecmp(s, "VTRAP01", 8) == 0) { + walf[i] |= 2; } } - return 1; - case MB_BACK: + R_end_load(); + return 1; + case MB_BACK: p = fldb; goto unp; - case MB_WTYPE: + case MB_WTYPE: p = fld; goto unp; - case MB_FRONT: + case MB_FRONT: p = fldf; unp: switch (blk.st) { - case 0: + case 0: myfread(p, FLDW * FLDH, 1, h); break; - case 1: + case 1: buf = malloc(blk.sz); - if(buf == NULL) { - ERR_fatal("Не хватает памяти"); + if (buf == NULL) { + ERR_fatal("Не хватает памяти"); } - myfread(buf, blk.sz, 1, h); - unpack(buf, blk.sz, p); + myfread(buf, blk.sz, 1, h); + unpack(buf, blk.sz, p); free(buf); break; - default: + default: return 0; - } + } return 1; - case MB_SKY: + case MB_SKY: sky_type = myfread16(h); - strcpy(w.n, "RSKY1"); - w.n[4] = '0' + sky_type; - M_unlock(horiz); - horiz = V_loadvgaimg(w.n); - return 1; + R_loadsky(sky_type); + return 1; } return 0; } diff --git a/src/view.h b/src/view.h index bc14b45..5f1aad9 100644 --- a/src/view.h +++ b/src/view.h @@ -67,7 +67,8 @@ typedef struct{ #pragma pack() -void W_act(void); +extern dword walf[256]; +extern byte walswp[256]; void W_init(void); -- 2.29.2