DEADSOFTWARE

sound: separate and rewrite
[flatwaifu.git] / src / view.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
23 #include "glob.h"
24 #include <string.h>
25 #include <stdlib.h>
26 #include "memory.h"
27 #include "files.h"
28 #include "error.h"
29 #include "view.h"
30 #include "dots.h"
31 #include "smoke.h"
32 #include "weapons.h"
33 #include "items.h"
34 #include "switch.h"
35 #include "fx.h"
36 #include "player.h"
37 #include "monster.h"
38 #include "misc.h"
39 #include "map.h"
40 #include "sound.h"
41 #include "my.h"
42 #include "render.h"
44 byte w_horiz=ON;
45 int sky_type=1;
46 dword walf[256];
47 byte walswp[256];
48 byte fldb[FLDH][FLDW];
49 byte fldf[FLDH][FLDW];
50 byte fld[FLDH][FLDW];
52 void W_savegame (FILE* h) {
53 char s[8];
54 int i;
55 myfwrite32(sky_type, h);
56 for(i = 1; i < 256; ++i) {
57 R_get_name(i, s);
58 myfwrite(s, 8, 1, h);
59 }
60 for (i = 0; i < 256; i++) {
61 myfwrite32(walf[i], h);
62 }
63 for (i = 0; i < 256; i++) {
64 myfwrite8(walswp[i], h);
65 }
66 myfwrite(fldb, FLDW*FLDH, 1, h);
67 myfwrite(fld, FLDW*FLDH, 1, h);
68 myfwrite(fldf, FLDW*FLDH, 1, h);
69 }
71 void W_loadgame (FILE* h) {
72 int i;
73 char s[256][8];
74 sky_type = myfread32(h);
75 R_loadsky(sky_type);
76 for (i = 1; i < 256; ++i) {
77 myfread(s[i], 8, 1, h);
78 }
79 R_begin_load();
80 i = myfread32(h); // ignore
81 for (i = 1; i < 256; i++) {
82 walf[i] = myfread32(h);
83 R_load(s[i], walf[i] & 1);
84 }
85 for (i = 0; i < 256; i++) {
86 //walswp[i] = myfread8(h);
87 (void)myfread8(h); // useless in new code
88 }
89 myfread(fldb, FLDW*FLDH, 1, h);
90 myfread(fld, FLDW*FLDH, 1, h);
91 myfread(fldf, FLDW*FLDH, 1, h);
92 R_end_load();
93 }
95 void W_init (void) {
96 DOT_init();
97 SMK_init();
98 FX_init();
99 WP_init();
100 IT_init();
101 SW_init();
102 PL_init();
103 MN_init();
104 R_loadsky(1);
107 static void unpack (void *buf, int len, void *obuf) {
108 int i = 0;
109 int j = 0;
110 unsigned char *p = buf;
111 unsigned char *q = obuf;
112 while (i < len) {
113 int id = p[i];
114 int step = 1;
115 i += 1;
116 if (id == 0xff) {
117 step = p[i] | p[i + 1] << 8;
118 id = p[i + 2];
119 i += 3;
121 memset(&q[j], id, step);
122 j += step;
126 int W_load (FILE *h) {
127 char s[8];
128 int i, j, t;
129 void *p, *buf;
130 switch (blk.t) {
131 case MB_WALLNAMES:
132 R_begin_load();
133 for (i = 1; i < 256 && blk.sz > 0; i++, blk.sz -= 9) {
134 myfread(s, 8, 1, h);
135 t = myfread8(h);
136 R_load(s, t);
137 if (strncasecmp(s, "VTRAP01", 8) == 0) {
138 walf[i] |= 2;
141 R_end_load();
142 return 1;
143 case MB_BACK:
144 p = fldb;
145 goto unp;
146 case MB_WTYPE:
147 p = fld;
148 goto unp;
149 case MB_FRONT:
150 p = fldf;
151 unp:
152 switch (blk.st) {
153 case 0:
154 myfread(p, FLDW * FLDH, 1, h);
155 break;
156 case 1:
157 buf = malloc(blk.sz);
158 if (buf == NULL) {
159 ERR_fatal("Не хватает памяти");
161 myfread(buf, blk.sz, 1, h);
162 unpack(buf, blk.sz, p);
163 free(buf);
164 break;
165 default:
166 return 0;
168 return 1;
169 case MB_SKY:
170 sky_type = myfread16(h);
171 R_loadsky(sky_type);
172 return 1;
174 return 0;