Subversion Repositories eduke32

Rev

Rev 8488 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8488 Rev 8490
1
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
1
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
2
// Ken Silverman's official web site: "http://www.advsys.net/ken"
2
// Ken Silverman's official web site: "http://www.advsys.net/ken"
3
// See the included license file "BUILDLIC.TXT" for license info.
3
// See the included license file "BUILDLIC.TXT" for license info.
4
//
4
//
5
// This file has been modified from Ken Silverman's original release
5
// This file has been modified from Ken Silverman's original release
6
// by Jonathon Fowler (jf@jonof.id.au)
6
// by Jonathon Fowler (jf@jonof.id.au)
7
// by the EDuke32 team (development@voidpoint.com)
7
// by the EDuke32 team (development@voidpoint.com)
8
8
9
#include "build.h"
9
#include "build.h"
10
10
11
#include "baselayer.h"
11
#include "baselayer.h"
12
#include "cache1d.h"
12
#include "cache1d.h"
13
#include "colmatch.h"
13
#include "colmatch.h"
14
#include "common.h"
14
#include "common.h"
15
#include "compat.h"
15
#include "compat.h"
16
#include "editor.h"
16
#include "editor.h"
17
#include "m32script.h"
17
#include "m32script.h"
18
#include "osd.h"
18
#include "osd.h"
19
#include "palette.h"
19
#include "palette.h"
20
#include "pragmas.h"
20
#include "pragmas.h"
21
#include "renderlayer.h"
21
#include "renderlayer.h"
22
#include "scancodes.h"
22
#include "scancodes.h"
23
#include "vfs.h"
23
#include "vfs.h"
24
24
25
#ifdef _WIN32
25
#ifdef _WIN32
26
#include "winbits.h"
26
#include "winbits.h"
27
#endif
27
#endif
28
28
29
char levelname[BMAX_PATH] = {0};
29
char levelname[BMAX_PATH] = {0};
30
30
31
#define updatecrc16(crc,dat) (crc = (((crc<<8)&65535)^crctable[((((uint16_t)crc)>>8)&65535)^dat]))
31
#define updatecrc16(crc,dat) (crc = (((crc<<8)&65535)^crctable[((((uint16_t)crc)>>8)&65535)^dat]))
32
static int32_t crctable[256];
32
static int32_t crctable[256];
33
static char kensig[64];
33
static char kensig[64];
34
34
35
static const char *CallExtGetVer(void);
35
static const char *CallExtGetVer(void);
36
static int32_t CallExtInit(void);
36
static int32_t CallExtInit(void);
37
static int32_t CallExtPreInit(int32_t argc,char const * const * argv);
37
static int32_t CallExtPreInit(int32_t argc,char const * const * argv);
38
static int32_t CallExtPostStartupWindow(void);
38
static int32_t CallExtPostStartupWindow(void);
39
static void CallExtPostInit(void);
39
static void CallExtPostInit(void);
40
static void CallExtUnInit(void);
40
static void CallExtUnInit(void);
41
static void CallExtPreCheckKeys(void);
41
static void CallExtPreCheckKeys(void);
42
static void CallExtAnalyzeSprites(int32_t, int32_t, int32_t, int32_t, int32_t);
42
static void CallExtAnalyzeSprites(int32_t, int32_t, int32_t, int32_t, int32_t);
43
static void CallExtCheckKeys(void);
43
static void CallExtCheckKeys(void);
44
static void CallExtPreLoadMap(void);
44
static void CallExtPreLoadMap(void);
45
static void CallExtSetupMapFilename(const char *mapname);
45
static void CallExtSetupMapFilename(const char *mapname);
46
static void CallExtLoadMap(const char *mapname);
46
static void CallExtLoadMap(const char *mapname);
47
static int32_t CallExtPreSaveMap(void);
47
static int32_t CallExtPreSaveMap(void);
48
static void CallExtSaveMap(const char *mapname);
48
static void CallExtSaveMap(const char *mapname);
49
static inline const char *CallExtGetSectorCaption(int16_t sectnum) { return ExtGetSectorCaption(sectnum); }
49
static inline const char *CallExtGetSectorCaption(int16_t sectnum) { return ExtGetSectorCaption(sectnum); }
50
static inline const char *CallExtGetWallCaption(int16_t wallnum) { return ExtGetWallCaption(wallnum); }
50
static inline const char *CallExtGetWallCaption(int16_t wallnum) { return ExtGetWallCaption(wallnum); }
51
static inline const char *CallExtGetSpriteCaption(int16_t spritenum) { return ExtGetSpriteCaption(spritenum); }
51
static inline const char *CallExtGetSpriteCaption(int16_t spritenum) { return ExtGetSpriteCaption(spritenum); }
52
static void CallExtShowSectorData(int16_t sectnum);
52
static void CallExtShowSectorData(int16_t sectnum);
53
static void CallExtShowWallData(int16_t wallnum);
53
static void CallExtShowWallData(int16_t wallnum);
54
static void CallExtShowSpriteData(int16_t spritenum);
54
static void CallExtShowSpriteData(int16_t spritenum);
55
static void CallExtEditSectorData(int16_t sectnum);
55
static void CallExtEditSectorData(int16_t sectnum);
56
static void CallExtEditWallData(int16_t wallnum);
56
static void CallExtEditWallData(int16_t wallnum);
57
static void CallExtEditSpriteData(int16_t spritenum);
57
static void CallExtEditSpriteData(int16_t spritenum);
58
// static const char *CallExtGetSectorType(int32_t lotag);
58
// static const char *CallExtGetSectorType(int32_t lotag);
59
59
60
int8_t m32_clipping=2;
60
int8_t m32_clipping=2;
61
static int32_t m32_rotateang = 0;
61
static int32_t m32_rotateang = 0;
62
62
63
// 0   1     2     3      4       5      6      7
63
// 0   1     2     3      4       5      6      7
64
// up, down, left, right, lshift, rctrl, lctrl, space
64
// up, down, left, right, lshift, rctrl, lctrl, space
65
// 8  9  10    11    12   13
65
// 8  9  10    11    12   13
66
// a, z, pgdn, pgup, [,], [.]
66
// a, z, pgdn, pgup, [,], [.]
67
// 14       15     16 17 18   19
67
// 14       15     16 17 18   19
68
// kpenter, enter, =, -, tab, `
68
// kpenter, enter, =, -, tab, `
69
uint8_t buildkeys[NUMBUILDKEYS] =
69
uint8_t buildkeys[NUMBUILDKEYS] =
70
{
70
{
71
    0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39,
71
    0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39,
72
    0x1e,0x2c,0xd1,0xc9,0x33,0x34,
72
    0x1e,0x2c,0xd1,0xc9,0x33,0x34,
73
    0x9c,0x1c,0xd,0xc,0xf,0x29
73
    0x9c,0x1c,0xd,0xc,0xf,0x29
74
};
74
};
75
75
76
// Start position
76
// Start position
77
vec3_t startpos;
77
vec3_t startpos;
78
int16_t startang, startsectnum;
78
int16_t startang, startsectnum;
79
79
80
// Current position
80
// Current position
81
vec3_t pos;
81
vec3_t pos;
82
int32_t horiz = 100;
82
int32_t horiz = 100;
83
int16_t ang, cursectnum;
83
int16_t ang, cursectnum;
84
static int32_t hvel, vel, svel, angvel;
84
static int32_t hvel, vel, svel, angvel;
85
int32_t g_doHardcodedMovement = 1;
85
int32_t g_doHardcodedMovement = 1;
86
86
87
static int32_t mousexsurp = 0, mouseysurp = 0;
87
static int32_t mousexsurp = 0, mouseysurp = 0;
88
double msens = 1.0;
88
double msens = 1.0;
89
89
90
int32_t grponlymode = 0;
90
int32_t grponlymode = 0;
91
int32_t graphicsmode = 0;
91
int32_t graphicsmode = 0;
92
92
93
int32_t synctics = 0, lockclock = 0;
93
int32_t synctics = 0, lockclock = 0;
94
94
95
// those ones save the respective 3d video vars while in 2d mode
95
// those ones save the respective 3d video vars while in 2d mode
96
// so that exiting from mapster32 in 2d mode saves the correct ones
96
// so that exiting from mapster32 in 2d mode saves the correct ones
97
float vid_gamma_3d=-1, vid_contrast_3d=-1, vid_brightness_3d=-1;
97
float vid_gamma_3d=-1, vid_contrast_3d=-1, vid_brightness_3d=-1;
98
98
99
int32_t xdim2d = 640, ydim2d = 480, xdimgame = 640, ydimgame = 480, bppgame = 8;
99
int32_t xdim2d = 640, ydim2d = 480, xdimgame = 640, ydimgame = 480, bppgame = 8;
100
int32_t forcesetup = 1;
100
int32_t forcesetup = 1;
101
101
102
#ifndef GEKKO
102
#ifndef GEKKO
103
int32_t g_maxCacheSize = 128<<20;
103
int32_t g_maxCacheSize = 128<<20;
104
#else
104
#else
105
int32_t g_maxCacheSize = 8<<20;
105
int32_t g_maxCacheSize = 8<<20;
106
#endif
106
#endif
107
107
108
static int16_t oldmousebstatus = 0;
108
static int16_t oldmousebstatus = 0;
109
109
110
char game_executable[BMAX_PATH] = {0};
110
char game_executable[BMAX_PATH] = {0};
111
111
112
int32_t zlock = 0x7fffffff, zmode = 0, kensplayerheight = 32;
112
int32_t zlock = 0x7fffffff, zmode = 0, kensplayerheight = 32;
113
int16_t defaultspritecstat = 0;
113
int16_t defaultspritecstat = 0;
114
114
115
int16_t localartfreq[MAXTILES];
115
int16_t localartfreq[MAXTILES];
116
int16_t localartlookup[MAXTILES], localartlookupnum;
116
int16_t localartlookup[MAXTILES], localartlookupnum;
117
117
118
char tempbuf[4096];
118
char tempbuf[4096];
119
119
120
char names[MAXTILES][25];
120
char names[MAXTILES][25];
121
const char *g_namesFileName = "NAMES.H";
121
const char *g_namesFileName = "NAMES.H";
122
122
123
int16_t asksave = 0;
123
int16_t asksave = 0;
124
int32_t osearchx, osearchy;                               //old search input
124
int32_t osearchx, osearchy;                               //old search input
125
125
126
int32_t grid = 0, autogrid = 1, gridlock = 1, showtags = 2;
126
int32_t grid = 0, autogrid = 1, gridlock = 1, showtags = 2;
127
int32_t zoom = 768, gettilezoom = 1, ztarget = 768;
127
int32_t zoom = 768, gettilezoom = 1, ztarget = 768;
128
int32_t lastpm16time = 0;
128
int32_t lastpm16time = 0;
129
129
130
extern int32_t mapversion;
130
extern int32_t mapversion;
131
131
132
int16_t highlight[MAXWALLS+MAXSPRITES];
132
int16_t highlight[MAXWALLS+MAXSPRITES];
133
int16_t highlightsector[MAXSECTORS], highlightsectorcnt = -1;
133
int16_t highlightsector[MAXSECTORS], highlightsectorcnt = -1;
134
extern char textfont[128][8];
134
extern char textfont[128][8];
135
135
136
int32_t tempsectornum = -1;  // for auto ceiling/floor alignment
136
int32_t tempsectornum = -1;  // for auto ceiling/floor alignment
137
int32_t temppicnum, tempcstat, templotag, temphitag, tempextra;
137
int32_t temppicnum, tempcstat, templotag, temphitag, tempextra;
138
uint32_t temppal, tempvis, tempxrepeat, tempyrepeat, tempxpanning=0, tempypanning=0;
138
uint32_t temppal, tempvis, tempxrepeat, tempyrepeat, tempxpanning=0, tempypanning=0;
139
int32_t tempshade, tempxvel, tempyvel, tempzvel;
139
int32_t tempshade, tempxvel, tempyvel, tempzvel;
140
int32_t tempstatnum=0, tempblend=0;
140
int32_t tempstatnum=0, tempblend=0;
141
char somethingintab = 255;
141
char somethingintab = 255;
142
142
143
// Only valid when highlightsectorcnt>0 and no structural
143
// Only valid when highlightsectorcnt>0 and no structural
144
// modifications (deleting/inserting sectors or points, setting new firstwall)
144
// modifications (deleting/inserting sectors or points, setting new firstwall)
145
// have been made:
145
// have been made:
146
static int16_t onextwall[MAXWALLS];  // onextwall[i]>=0 implies wall[i].nextwall < 0
146
static int16_t onextwall[MAXWALLS];  // onextwall[i]>=0 implies wall[i].nextwall < 0
147
static void mkonwvalid(void) { chsecptr_onextwall = onextwall; }
147
static void mkonwvalid(void) { chsecptr_onextwall = onextwall; }
148
static void mkonwinvalid(void) { chsecptr_onextwall = NULL; tempsectornum=-1; }
148
static void mkonwinvalid(void) { chsecptr_onextwall = NULL; tempsectornum=-1; }
149
static void mkonwinvalid_keeptempsect(void) { chsecptr_onextwall = NULL; }
149
static void mkonwinvalid_keeptempsect(void) { chsecptr_onextwall = NULL; }
150
static int32_t onwisvalid(void) { return chsecptr_onextwall != NULL; }
150
static int32_t onwisvalid(void) { return chsecptr_onextwall != NULL; }
151
151
152
int32_t mlook = 0, mskip=0;
152
int32_t mlook = 0, mskip=0;
153
int32_t revertCTRL=0,scrollamount=3;
153
int32_t revertCTRL=0,scrollamount=3;
154
int32_t unrealedlook=1, quickmapcycling=1; //PK
154
int32_t unrealedlook=1, quickmapcycling=1; //PK
155
155
156
char program_origcwd[BMAX_PATH];
156
char program_origcwd[BMAX_PATH];
157
const char *mapster32_fullpath;
157
const char *mapster32_fullpath;
158
char *testplay_addparam = 0;
158
char *testplay_addparam = 0;
159
159
160
static char boardfilename[BMAX_PATH], selectedboardfilename[BMAX_PATH];
160
static char boardfilename[BMAX_PATH], selectedboardfilename[BMAX_PATH];
161
//extern char levelname[BMAX_PATH];  // in astub.c   XXX: clean up this mess!!!
161
//extern char levelname[BMAX_PATH];  // in astub.c   XXX: clean up this mess!!!
162
162
163
void B_SetBoardFileName(const char *fn)
163
void B_SetBoardFileName(const char *fn)
164
{
164
{
165
    Bstrncpyz(boardfilename, fn, BMAX_PATH);
165
    Bstrncpyz(boardfilename, fn, BMAX_PATH);
166
}
166
}
167
167
168
static fnlist_t fnlist;
168
static fnlist_t fnlist;
169
static BUILDVFS_FIND_REC *finddirshigh=NULL, *findfileshigh=NULL;
169
static BUILDVFS_FIND_REC *finddirshigh=NULL, *findfileshigh=NULL;
170
static int32_t currentlist=0;
170
static int32_t currentlist=0;
171
171
172
//static int32_t repeatcountx, repeatcounty;
172
//static int32_t repeatcountx, repeatcounty;
173
173
174
static int32_t fillist[640];
174
static int32_t fillist[640];
175
// used for fillsector, batch point insertion, backup_highlighted_map
175
// used for fillsector, batch point insertion, backup_highlighted_map
176
static int32_t tempxyar[MAXWALLS][2];
176
static int32_t tempxyar[MAXWALLS][2];
177
177
178
static int32_t mousx, mousy;
178
static int32_t mousx, mousy;
179
int16_t prefixtiles[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
179
int16_t prefixtiles[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
180
uint8_t hlsectorbitmap[(MAXSECTORS+7)>>3];  // show2dsector is already taken...
180
uint8_t hlsectorbitmap[(MAXSECTORS+7)>>3];  // show2dsector is already taken...
181
static int32_t minhlsectorfloorz, numhlsecwalls;
181
static int32_t minhlsectorfloorz, numhlsecwalls;
182
int32_t searchlock = 0;
182
int32_t searchlock = 0;
183
183
184
// used for:
184
// used for:
185
//  - hl_all_bunch_sectors_p
185
//  - hl_all_bunch_sectors_p
186
//  - AlignWalls
186
//  - AlignWalls
187
//  - trace_loop
187
//  - trace_loop
188
static uint8_t visited[(MAXWALLS+7)>>3];
188
static uint8_t visited[(MAXWALLS+7)>>3];
189
189
190
int32_t m32_2d3dmode = 0;
190
int32_t m32_2d3dmode = 0;
191
int32_t m32_2d3dsize = 4;
191
int32_t m32_2d3dsize = 4;
192
vec2_t m32_2d3d = { 0xffff, 4 };
192
vec2_t m32_2d3d = { 0xffff, 4 };
193
193
194
int32_t m32_3dundo = 1;
194
int32_t m32_3dundo = 1;
195
195
196
typedef struct
196
typedef struct
197
{
197
{
198
    int16_t numsectors, numwalls, numsprites;
198
    int16_t numsectors, numwalls, numsprites;
199
#ifdef YAX_ENABLE
199
#ifdef YAX_ENABLE
200
    int16_t numyaxbunches;
200
    int16_t numyaxbunches;
201
    int16_t *bunchnum;  // [numsectors][2]
201
    int16_t *bunchnum;  // [numsectors][2]
202
    int16_t *ynextwall;  // [numwalls][2]
202
    int16_t *ynextwall;  // [numwalls][2]
203
#endif
203
#endif
204
    usectortype *sector;
204
    usectortype *sector;
205
    uwalltype *wall;
205
    uwalltype *wall;
206
    uspritetype *sprite;
206
    uspritetype *sprite;
207
} mapinfofull_t;
207
} mapinfofull_t;
208
208
209
int32_t g_doScreenShot;
209
int32_t g_doScreenShot;
210
210
211
#define eitherALT   (keystatus[sc_LeftAlt]|keystatus[sc_RightAlt])
211
#define eitherALT   (keystatus[sc_LeftAlt]|keystatus[sc_RightAlt])
212
#define eitherCTRL  (keystatus[sc_LeftControl]|keystatus[sc_RightControl])
212
#define eitherCTRL  (keystatus[sc_LeftControl]|keystatus[sc_RightControl])
213
#define eitherSHIFT (keystatus[sc_LeftShift]|keystatus[sc_RightShift])
213
#define eitherSHIFT (keystatus[sc_LeftShift]|keystatus[sc_RightShift])
214
214
215
#define DOWN_BK(BuildKey) (keystatus[buildkeys[BK_##BuildKey]])
215
#define DOWN_BK(BuildKey) (keystatus[buildkeys[BK_##BuildKey]])
216
216
217
int32_t pk_turnaccel=16;
217
int32_t pk_turnaccel=16;
218
int32_t pk_turndecel=12;
218
int32_t pk_turndecel=12;
219
int32_t pk_uedaccel=3;
219
int32_t pk_uedaccel=3;
220
220
221
int8_t keeptexturestretch = 1;
221
int8_t keeptexturestretch = 1;
222
int8_t sideview_reversehrot = 0;
222
int8_t sideview_reversehrot = 0;
223
223
224
int16_t pointhighlightdist = 256;
224
int16_t pointhighlightdist = 256;
225
int16_t linehighlightdist = 1024;
225
int16_t linehighlightdist = 1024;
226
226
227
char lastpm16buf[156];
227
char lastpm16buf[156];
228
228
229
//static int32_t checksectorpointer_warn = 0;
229
//static int32_t checksectorpointer_warn = 0;
230
static int32_t saveboard_savedtags, saveboard_fixedsprites;
230
static int32_t saveboard_savedtags, saveboard_fixedsprites;
231
static int32_t saveboard_canceled;
231
static int32_t saveboard_canceled;
232
232
233
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo);
233
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo);
234
static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal);
234
static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal);
235
static void SaveBoardAndPrintMessage(const char *fn);
235
static void SaveBoardAndPrintMessage(const char *fn);
236
236
237
static int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls);
237
static int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls);
238
static void locktogrid(int32_t *dax, int32_t *day);
238
static void locktogrid(int32_t *dax, int32_t *day);
239
static int32_t checkautoinsert(int32_t dax, int32_t day, int16_t danumwalls);
239
static int32_t checkautoinsert(int32_t dax, int32_t day, int16_t danumwalls);
240
static void keytimerstuff(void);
240
static void keytimerstuff(void);
241
static void flipwalls(int16_t numwalls, int16_t newnumwalls);
241
static void flipwalls(int16_t numwalls, int16_t newnumwalls);
242
static int32_t insertpoint(int16_t linehighlight, int32_t dax, int32_t day, int32_t *mapwallnum);
242
static int32_t insertpoint(int16_t linehighlight, int32_t dax, int32_t day, int32_t *mapwallnum);
243
static void deletepoint(int16_t point, int32_t runi);
243
static void deletepoint(int16_t point, int32_t runi);
244
static int32_t deletesector(int16_t sucksect);
244
static int32_t deletesector(int16_t sucksect);
245
static int16_t whitelinescan(int16_t sucksect, int16_t dalinehighlight);
245
static int16_t whitelinescan(int16_t sucksect, int16_t dalinehighlight);
246
static void printcoords16(int32_t posxe, int32_t posye, int16_t ange);
246
static void printcoords16(int32_t posxe, int32_t posye, int16_t ange);
247
static void overheadeditor(void);
247
static void overheadeditor(void);
248
static int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line, int8_t ignore_pointhighlight);
248
static int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line, int8_t ignore_pointhighlight);
249
static int32_t movewalls(int32_t start, int32_t offs);
249
static int32_t movewalls(int32_t start, int32_t offs);
250
static void loadnames(const char *namesfile);
250
static void loadnames(const char *namesfile);
251
static void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, int32_t *ny,
251
static void getclosestpointonwall(int32_t x, int32_t y, int32_t dawall, int32_t *nx, int32_t *ny,
252
                                  int32_t maybe_screen_coord_p);
252
                                  int32_t maybe_screen_coord_p);
253
static void initcrc(void);
253
static void initcrc(void);
254
254
255
static int32_t menuselect(void);
255
static int32_t menuselect(void);
256
static int32_t menuselect_auto(int, int); //PK
256
static int32_t menuselect_auto(int, int); //PK
257
257
258
static int32_t insert_sprite_common(int32_t sectnum, int32_t dax, int32_t day);
258
static int32_t insert_sprite_common(int32_t sectnum, int32_t dax, int32_t day);
259
static void correct_ornamented_sprite(int32_t i, int32_t hitw);
259
static void correct_ornamented_sprite(int32_t i, int32_t hitw);
260
260
261
static int32_t getfilenames(const char *path, const char *kind);
261
static int32_t getfilenames(const char *path, const char *kind);
262
262
263
// Get basename of BUILD file name (forward slashes as directory separators).
263
// Get basename of BUILD file name (forward slashes as directory separators).
264
static const char *getbasefn(const char *fn)
264
static const char *getbasefn(const char *fn)
265
{
265
{
266
    const char *slash = Bstrrchr(fn, '/');
266
    const char *slash = Bstrrchr(fn, '/');
267
    return slash ? slash+1 : fn;
267
    return slash ? slash+1 : fn;
268
}
268
}
269
269
270
void clearkeys(void)
270
void clearkeys(void)
271
{
271
{
272
    Bmemset(keystatus,0,sizeof(keystatus));
272
    Bmemset(keystatus,0,sizeof(keystatus));
273
}
273
}
274
274
275
#ifdef USE_OPENGL
275
#ifdef USE_OPENGL
276
int osdcmd_restartvid(osdcmdptr_t UNUSED(parm))
276
int osdcmd_restartvid(osdcmdptr_t UNUSED(parm))
277
{
277
{
278
    UNREFERENCED_CONST_PARAMETER(parm);
278
    UNREFERENCED_CONST_PARAMETER(parm);
279
279
280
    if (!in3dmode()) return OSDCMD_OK;
280
    if (!in3dmode()) return OSDCMD_OK;
281
281
282
    videoResetMode();
282
    videoResetMode();
283
    if (videoSetGameMode(fullscreen,xres,yres,bpp,upscalefactor))
283
    if (videoSetGameMode(fullscreen,xres,yres,bpp,upscalefactor))
284
        OSD_Printf("restartvid: Reset failed...\n");
284
        OSD_Printf("restartvid: Reset failed...\n");
285
285
286
    return OSDCMD_OK;
286
    return OSDCMD_OK;
287
}
287
}
288
#endif
288
#endif
289
289
290
static int osdcmd_vidmode(osdcmdptr_t parm)
290
static int osdcmd_vidmode(osdcmdptr_t parm)
291
{
291
{
292
    int32_t newx = xres, newy = yres, newbpp = bpp, newfullscreen = fullscreen;
292
    int32_t newx = xres, newy = yres, newbpp = bpp, newfullscreen = fullscreen;
293
#ifdef USE_OPENGL
293
#ifdef USE_OPENGL
294
    int32_t tmp;
294
    int32_t tmp;
295
#endif
295
#endif
296
296
297
    switch (parm->numparms)
297
    switch (parm->numparms)
298
    {
298
    {
299
#ifdef USE_OPENGL
299
#ifdef USE_OPENGL
300
    case 1:     // bpp switch
300
    case 1:     // bpp switch
301
        tmp = Batol(parm->parms[0]);
301
        tmp = Batol(parm->parms[0]);
302
        if (!(tmp==8 || tmp==16 || tmp==32))
302
        if (!(tmp==8 || tmp==16 || tmp==32))
303
            return OSDCMD_SHOWHELP;
303
            return OSDCMD_SHOWHELP;
304
        newbpp = tmp;
304
        newbpp = tmp;
305
        break;
305
        break;
306
    case 4:     // fs, res, bpp switch
306
    case 4:     // fs, res, bpp switch
307
        newfullscreen = (Batol(parm->parms[3]) != 0);
307
        newfullscreen = (Batol(parm->parms[3]) != 0);
308
        fallthrough__;
308
        fallthrough__;
309
    case 3:     // res & bpp switch
309
    case 3:     // res & bpp switch
310
        tmp = Batol(parm->parms[2]);
310
        tmp = Batol(parm->parms[2]);
311
        if (!(tmp==8 || tmp==16 || tmp==32))
311
        if (!(tmp==8 || tmp==16 || tmp==32))
312
            return OSDCMD_SHOWHELP;
312
            return OSDCMD_SHOWHELP;
313
        newbpp = tmp;
313
        newbpp = tmp;
314
        fallthrough__;
314
        fallthrough__;
315
#endif
315
#endif
316
    case 2: // res switch
316
    case 2: // res switch
317
        newx = Batol(parm->parms[0]);
317
        newx = Batol(parm->parms[0]);
318
        newy = Batol(parm->parms[1]);
318
        newy = Batol(parm->parms[1]);
319
        break;
319
        break;
320
    default:
320
    default:
321
        return OSDCMD_SHOWHELP;
321
        return OSDCMD_SHOWHELP;
322
    }
322
    }
323
323
324
    if (!in3dmode())
324
    if (!in3dmode())
325
    {
325
    {
326
        videoSet2dMode(newx,newy);
326
        videoSet2dMode(newx,newy);
327
        xdim2d = xdim;
327
        xdim2d = xdim;
328
        ydim2d = ydim;
328
        ydim2d = ydim;
329
329
330
        videoBeginDrawing();    //{{{
330
        videoBeginDrawing();    //{{{
331
        CLEARLINES2D(0, ydim16, 0);
331
        CLEARLINES2D(0, ydim16, 0);
332
        videoEndDrawing();      //}}}
332
        videoEndDrawing();      //}}}
333
333
334
        ydim16 = ydim-STATUS2DSIZ2;
334
        ydim16 = ydim-STATUS2DSIZ2;
335
335
336
        return OSDCMD_OK;
336
        return OSDCMD_OK;
337
    }
337
    }
338
338
339
    if (videoSetGameMode(newfullscreen,newx,newy,newbpp,upscalefactor))
339
    if (videoSetGameMode(newfullscreen,newx,newy,newbpp,upscalefactor))
340
        OSD_Printf("vidmode: Mode change failed!\n");
340
        OSD_Printf("vidmode: Mode change failed!\n");
341
341
342
    xdimgame = newx;
342
    xdimgame = newx;
343
    ydimgame = newy;
343
    ydimgame = newy;
344
    bppgame = newbpp;
344
    bppgame = newbpp;
345
    fullscreen = newfullscreen;
345
    fullscreen = newfullscreen;
346
346
347
    return OSDCMD_OK;
347
    return OSDCMD_OK;
348
}
348
}
349
349
350
350
351
#ifdef M32_SHOWDEBUG
351
#ifdef M32_SHOWDEBUG
352
char m32_debugstr[64][128];
352
char m32_debugstr[64][128];
353
int32_t m32_numdebuglines=0;
353
int32_t m32_numdebuglines=0;
354
354
355
static void M32_drawdebug(void)
355
static void M32_drawdebug(void)
356
{
356
{
357
    int32_t i;
357
    int32_t i;
358
    int32_t x=4, y=8;
358
    int32_t x=4, y=8;
359
359
360
#if 0
360
#if 0
361
    {
361
    {
362
        static char tstr[128];
362
        static char tstr[128];
363
        Bsprintf(tstr, "search... stat=%d, sector=%d, wall=%d (%d), isbottom=%d, asksave=%d",
363
        Bsprintf(tstr, "search... stat=%d, sector=%d, wall=%d (%d), isbottom=%d, asksave=%d",
364
                 searchstat, searchsector, searchwall, searchbottomwall, searchisbottom, asksave);
364
                 searchstat, searchsector, searchwall, searchbottomwall, searchisbottom, asksave);
365
        printext256(x,y,whitecol,0,tstr,xdimgame>640?0:1);
365
        printext256(x,y,whitecol,0,tstr,xdimgame>640?0:1);
366
    }
366
    }
367
#endif
367
#endif
368
    if (m32_numdebuglines>0)
368
    if (m32_numdebuglines>0)
369
    {
369
    {
370
        videoBeginDrawing();
370
        videoBeginDrawing();
371
        for (i=0; i<m32_numdebuglines && y<ydim-8; i++, y+=8)
371
        for (i=0; i<m32_numdebuglines && y<ydim-8; i++, y+=8)
372
            printext256(x,y,whitecol,0,m32_debugstr[i],xdimgame>640?0:1);
372
            printext256(x,y,whitecol,0,m32_debugstr[i],xdimgame>640?0:1);
373
        videoEndDrawing();
373
        videoEndDrawing();
374
    }
374
    }
375
    m32_numdebuglines=0;
375
    m32_numdebuglines=0;
376
}
376
}
377
#endif
377
#endif
378
378
379
#ifdef YAX_ENABLE
379
#ifdef YAX_ENABLE
380
// Check whether bunchnum has exactly one corresponding floor and ceiling
380
// Check whether bunchnum has exactly one corresponding floor and ceiling
381
// and return it in this case. If not 1-to-1, return -1.
381
// and return it in this case. If not 1-to-1, return -1.
382
int32_t yax_is121(int16_t bunchnum, int16_t getfloor)
382
int32_t yax_is121(int16_t bunchnum, int16_t getfloor)
383
{
383
{
384
    int32_t i;
384
    int32_t i;
385
    i = headsectbunch[0][bunchnum];
385
    i = headsectbunch[0][bunchnum];
386
    if (i<0 || nextsectbunch[0][i]>=0)
386
    if (i<0 || nextsectbunch[0][i]>=0)
387
        return -1;
387
        return -1;
388
    i = headsectbunch[1][bunchnum];
388
    i = headsectbunch[1][bunchnum];
389
    if (i<0 || nextsectbunch[1][i]>=0)
389
    if (i<0 || nextsectbunch[1][i]>=0)
390
        return -1;
390
        return -1;
391
391
392
    return headsectbunch[getfloor][bunchnum];
392
    return headsectbunch[getfloor][bunchnum];
393
}
393
}
394
394
395
static int32_t yax_numsectsinbunch(int16_t bunchnum, int16_t cf)
395
static int32_t yax_numsectsinbunch(int16_t bunchnum, int16_t cf)
396
{
396
{
397
    int32_t i, n=0;
397
    int32_t i, n=0;
398
398
399
    if (bunchnum<0 || bunchnum>=numyaxbunches)
399
    if (bunchnum<0 || bunchnum>=numyaxbunches)
400
        return -1;
400
        return -1;
401
401
402
    for (SECTORS_OF_BUNCH(bunchnum, cf, i))
402
    for (SECTORS_OF_BUNCH(bunchnum, cf, i))
403
        n++;
403
        n++;
404
404
405
    return n;
405
    return n;
406
}
406
}
407
407
408
static void yax_fixreverselinks(int16_t oldwall, int16_t newwall)
408
static void yax_fixreverselinks(int16_t oldwall, int16_t newwall)
409
{
409
{
410
    int32_t cf, ynw;
410
    int32_t cf, ynw;
411
    for (cf=0; cf<2; cf++)
411
    for (cf=0; cf<2; cf++)
412
    {
412
    {
413
        ynw = yax_getnextwall(oldwall, cf);
413
        ynw = yax_getnextwall(oldwall, cf);
414
        if (ynw >= 0)
414
        if (ynw >= 0)
415
            yax_setnextwall(ynw, !cf, newwall);
415
            yax_setnextwall(ynw, !cf, newwall);
416
    }
416
    }
417
}
417
}
418
418
419
static void yax_tweakwalls(int16_t start, int16_t offs)
419
static void yax_tweakwalls(int16_t start, int16_t offs)
420
{
420
{
421
    int32_t i, nw, cf;
421
    int32_t i, nw, cf;
422
    for (i=0; i<numwalls; i++)
422
    for (i=0; i<numwalls; i++)
423
        for (cf=0; cf<2; cf++)
423
        for (cf=0; cf<2; cf++)
424
        {
424
        {
425
            nw = yax_getnextwall(i, cf);
425
            nw = yax_getnextwall(i, cf);
426
            if (nw >= start)
426
            if (nw >= start)
427
                yax_setnextwall(i, cf, nw+offs);
427
                yax_setnextwall(i, cf, nw+offs);
428
        }
428
        }
429
}
429
}
430
430
431
static void yax_resetbunchnums(void)
431
static void yax_resetbunchnums(void)
432
{
432
{
433
    int32_t i;
433
    int32_t i;
434
434
435
    for (i=0; i<MAXSECTORS; i++)
435
    for (i=0; i<MAXSECTORS; i++)
436
        yax_setbunches(i, -1, -1);
436
        yax_setbunches(i, -1, -1);
437
    yax_update(1);
437
    yax_update(1);
438
    yax_updategrays(pos.z);
438
    yax_updategrays(pos.z);
439
}
439
}
440
440
441
// Whether a wall is constrained by sector extensions.
441
// Whether a wall is constrained by sector extensions.
442
// If false, it's a wall that you can freely move around,
442
// If false, it's a wall that you can freely move around,
443
// attach points to, etc...
443
// attach points to, etc...
444
static int32_t yax_islockedwall(int16_t line)
444
static int32_t yax_islockedwall(int16_t line)
445
{
445
{
446
#ifdef NEW_MAP_FORMAT
446
#ifdef NEW_MAP_FORMAT
447
    return (wall[line].upwall>=0 || wall[line].dnwall>=0);
447
    return (wall[line].upwall>=0 || wall[line].dnwall>=0);
448
#else
448
#else
449
    return !!(wall[line].cstat&YAX_NEXTWALLBITS);
449
    return !!(wall[line].cstat&YAX_NEXTWALLBITS);
450
#endif
450
#endif
451
}
451
}
452
452
453
# define DEFAULT_YAX_HEIGHT (2048<<4)
453
# define DEFAULT_YAX_HEIGHT (2048<<4)
454
#endif
454
#endif
455
455
456
static void reset_default_mapstate(void)
456
static void reset_default_mapstate(void)
457
{
457
{
458
    pos.x = 32768;          //new board!
458
    pos.x = 32768;          //new board!
459
    pos.y = 32768;
459
    pos.y = 32768;
460
    pos.z = 0;
460
    pos.z = 0;
461
    ang = 1536;
461
    ang = 1536;
462
    cursectnum = -1;
462
    cursectnum = -1;
463
463
464
    numsectors = 0;
464
    numsectors = 0;
465
    numwalls = 0;
465
    numwalls = 0;
466
466
467
    editorzrange[0] = INT32_MIN;
467
    editorzrange[0] = INT32_MIN;
468
    editorzrange[1] = INT32_MAX;
468
    editorzrange[1] = INT32_MAX;
469
469
470
    initspritelists();
470
    initspritelists();
471
    taglab_init();
471
    taglab_init();
472
    artClearMapArt();
472
    artClearMapArt();
473
#ifdef YAX_ENABLE
473
#ifdef YAX_ENABLE
474
    yax_resetbunchnums();
474
    yax_resetbunchnums();
475
#endif
475
#endif
476
    g_loadedMapVersion = -1;
476
    g_loadedMapVersion = -1;
477
}
477
}
478
478
479
static void m32_keypresscallback(int32_t code, int32_t downp)
479
static void m32_keypresscallback(int32_t code, int32_t downp)
480
{
480
{
481
    UNREFERENCED_PARAMETER(downp);
481
    UNREFERENCED_PARAMETER(downp);
482
482
483
    g_iReturnVar = code;
483
    g_iReturnVar = code;
484
    VM_OnEvent(EVENT_KEYPRESS, -1);
484
    VM_OnEvent(EVENT_KEYPRESS, -1);
485
}
485
}
486
486
487
void M32_ResetFakeRORTiles(void)
487
void M32_ResetFakeRORTiles(void)
488
{
488
{
489
#ifdef POLYMER
489
#ifdef POLYMER
490
# ifdef YAX_ENABLE
490
# ifdef YAX_ENABLE
491
        // END_TWEAK ceiling/floor fake 'TROR' pics, see BEGIN_TWEAK in engine.c
491
        // END_TWEAK ceiling/floor fake 'TROR' pics, see BEGIN_TWEAK in engine.c
492
        if (videoGetRenderMode() == REND_POLYMER && showinvisibility)
492
        if (videoGetRenderMode() == REND_POLYMER && showinvisibility)
493
        {
493
        {
494
            int32_t i;
494
            int32_t i;
495
495
496
            for (i=0; i<numyaxbunches; i++)
496
            for (i=0; i<numyaxbunches; i++)
497
            {
497
            {
498
                yax_tweakpicnums(i, YAX_CEILING, 1);
498
                yax_tweakpicnums(i, YAX_CEILING, 1);
499
                yax_tweakpicnums(i, YAX_FLOOR, 1);
499
                yax_tweakpicnums(i, YAX_FLOOR, 1);
500
            }
500
            }
501
        }
501
        }
502
# endif
502
# endif
503
#endif
503
#endif
504
}
504
}
505
505
506
void M32_DrawRoomsAndMasks(void)
506
void M32_DrawRoomsAndMasks(void)
507
{
507
{
508
    static int srchwall = -1;
508
    static int srchwall = -1;
509
    const int32_t tmpyx=yxaspect, tmpvr=viewingrange;
509
    const int32_t tmpyx=yxaspect, tmpvr=viewingrange;
510
510
511
    if (r_usenewaspect)
511
    if (r_usenewaspect)
512
    {
512
    {
513
        newaspect_enable = 1;
513
        newaspect_enable = 1;
514
        videoSetCorrectedAspect();
514
        videoSetCorrectedAspect();
515
    }
515
    }
516
516
517
    VM_OnEvent(EVENT_PREDRAW3DSCREEN, -1);
517
    VM_OnEvent(EVENT_PREDRAW3DSCREEN, -1);
518
518
519
    yax_preparedrawrooms();
519
    yax_preparedrawrooms();
520
    drawrooms(pos.x,pos.y,pos.z,ang,horiz,cursectnum);
520
    drawrooms(pos.x,pos.y,pos.z,ang,horiz,cursectnum);
521
    yax_drawrooms(CallExtAnalyzeSprites, cursectnum, 0, 0);
521
    yax_drawrooms(CallExtAnalyzeSprites, cursectnum, 0, 0);
522
522
523
    const int osearchwall=searchwall, osearchstat=searchstat;
523
    const int osearchwall=searchwall, osearchstat=searchstat;
524
    if (srchwall >= 0)
524
    if (srchwall >= 0)
525
    {
525
    {
526
        // a.m32 states 'tduprot' and 'tduplin' need searchstat to check for
526
        // a.m32 states 'tduprot' and 'tduplin' need searchstat to check for
527
        // whether we've hit a sprite, but these would be only set after the
527
        // whether we've hit a sprite, but these would be only set after the
528
        // drawmasks(). Hence this hackish workaround.
528
        // drawmasks(). Hence this hackish workaround.
529
        searchstat = 3;
529
        searchstat = 3;
530
        searchwall = srchwall;
530
        searchwall = srchwall;
531
    }
531
    }
532
    CallExtAnalyzeSprites(0,0,0,0,0);
532
    CallExtAnalyzeSprites(0,0,0,0,0);
533
    searchwall = osearchwall, searchstat=osearchstat;
533
    searchwall = osearchwall, searchstat=osearchstat;
534
534
535
    renderDrawMasks();
535
    renderDrawMasks();
536
    srchwall = (searchstat == 3) ? searchwall : -1;
536
    srchwall = (searchstat == 3) ? searchwall : -1;
537
    M32_ResetFakeRORTiles();
537
    M32_ResetFakeRORTiles();
538
538
539
#ifdef POLYMER
539
#ifdef POLYMER
540
    if (videoGetRenderMode() == REND_POLYMER && searchit == 2)
540
    if (videoGetRenderMode() == REND_POLYMER && searchit == 2)
541
    {
541
    {
542
        polymer_editorpick();
542
        polymer_editorpick();
543
        drawrooms(pos.x,pos.y,pos.z,ang,horiz,cursectnum);
543
        drawrooms(pos.x,pos.y,pos.z,ang,horiz,cursectnum);
544
        CallExtAnalyzeSprites(0,0,0,0,0);
544
        CallExtAnalyzeSprites(0,0,0,0,0);
545
        renderDrawMasks();
545
        renderDrawMasks();
546
        M32_ResetFakeRORTiles();
546
        M32_ResetFakeRORTiles();
547
    }
547
    }
548
#endif
548
#endif
549
549
550
    VM_OnEvent(EVENT_DRAW3DSCREEN, -1);
550
    VM_OnEvent(EVENT_DRAW3DSCREEN, -1);
551
551
552
    if (g_doScreenShot)
552
    if (g_doScreenShot)
553
    {
553
    {
554
        videoCaptureScreen("mcapxxxx.tga", 0);
554
        videoCaptureScreen("mcapxxxx.tga", 0);
555
        g_doScreenShot = 0;
555
        g_doScreenShot = 0;
556
    }
556
    }
557
557
558
    if (r_usenewaspect)
558
    if (r_usenewaspect)
559
    {
559
    {
560
        newaspect_enable = 0;
560
        newaspect_enable = 0;
561
        renderSetAspect(tmpvr, tmpyx);
561
        renderSetAspect(tmpvr, tmpyx);
562
    }
562
    }
563
}
563
}
564
564
565
void M32_OnShowOSD(int shown)
565
void M32_OnShowOSD(int shown)
566
{
566
{
567
    mouseLockToWindow((!shown) + 2);
567
    mouseLockToWindow((!shown) + 2);
568
}
568
}
569
569
570
static void M32_FatalEngineError(void)
570
static void M32_FatalEngineError(void)
571
{
571
{
572
#ifdef DEBUGGINGAIDS
572
#ifdef DEBUGGINGAIDS
573
    debug_break();
573
    debug_break();
574
#endif
574
#endif
575
    Bsprintf(tempbuf, "There was a problem initializing the engine: %s\n", engineerrstr);
575
    Bsprintf(tempbuf, "There was a problem initializing the engine: %s\n", engineerrstr);
576
    ERRprintf("%s", tempbuf);
576
    ERRprintf("%s", tempbuf);
577
    fatal_exit(tempbuf);
577
    fatal_exit(tempbuf);
578
}
578
}
579
579
580
static void InitCustomColors()
580
static void InitCustomColors()
581
{
581
{
582
    /* blue */
582
    /* blue */
583
    vgapal16[9*4+0] = 252;
583
    vgapal16[9*4+0] = 252;
584
    vgapal16[9*4+1] = 124;
584
    vgapal16[9*4+1] = 124;
585
    vgapal16[9*4+2] = 28;
585
    vgapal16[9*4+2] = 28;
586
586
587
    /* orange */
587
    /* orange */
588
    vgapal16[31*4+0] = 80; // blue
588
    vgapal16[31*4+0] = 80; // blue
589
    vgapal16[31*4+1] = 180; // green
589
    vgapal16[31*4+1] = 180; // green
590
    vgapal16[31*4+2] = 240; // red
590
    vgapal16[31*4+2] = 240; // red
591
591
592
    // UNUSED?
592
    // UNUSED?
593
    vgapal16[39*4+0] = 144;
593
    vgapal16[39*4+0] = 144;
594
    vgapal16[39*4+1] = 212;
594
    vgapal16[39*4+1] = 212;
595
    vgapal16[39*4+2] = 252;
595
    vgapal16[39*4+2] = 252;
596
596
597
597
598
    /* light yellow */
598
    /* light yellow */
599
    vgapal16[22*4+0] = 204;
599
    vgapal16[22*4+0] = 204;
600
    vgapal16[22*4+1] = 252;
600
    vgapal16[22*4+1] = 252;
601
    vgapal16[22*4+2] = 252;
601
    vgapal16[22*4+2] = 252;
602
602
603
    /* grey */
603
    /* grey */
604
    vgapal16[23*4+0] = 180;
604
    vgapal16[23*4+0] = 180;
605
    vgapal16[23*4+1] = 180;
605
    vgapal16[23*4+1] = 180;
606
    vgapal16[23*4+2] = 180;
606
    vgapal16[23*4+2] = 180;
607
607
608
    /* blue */
608
    /* blue */
609
    vgapal16[24*4+0] = 204;
609
    vgapal16[24*4+0] = 204;
610
    vgapal16[24*4+1] = 164;
610
    vgapal16[24*4+1] = 164;
611
    vgapal16[24*4+2] = 48;
611
    vgapal16[24*4+2] = 48;
612
612
613
    vgapal16[32*4+0] = 240;
613
    vgapal16[32*4+0] = 240;
614
    vgapal16[32*4+1] = 200;
614
    vgapal16[32*4+1] = 200;
615
    vgapal16[32*4+2] = 84;
615
    vgapal16[32*4+2] = 84;
616
616
617
    // grid color
617
    // grid color
618
    vgapal16[25*4+0] = 64;
618
    vgapal16[25*4+0] = 64;
619
    vgapal16[25*4+1] = 56;
619
    vgapal16[25*4+1] = 56;
620
    vgapal16[25*4+2] = 56;
620
    vgapal16[25*4+2] = 56;
621
621
622
    vgapal16[26*4+0] = 96;
622
    vgapal16[26*4+0] = 96;
623
    vgapal16[26*4+1] = 96;
623
    vgapal16[26*4+1] = 96;
624
    vgapal16[26*4+2] = 96;
624
    vgapal16[26*4+2] = 96;
625
625
626
    // UNUSED?
626
    // UNUSED?
627
    vgapal16[33*4+0] = 0; //60; // blue
627
    vgapal16[33*4+0] = 0; //60; // blue
628
    vgapal16[33*4+1] = 0; //120; // green
628
    vgapal16[33*4+1] = 0; //120; // green
629
    vgapal16[33*4+2] = 192; //180; // red
629
    vgapal16[33*4+2] = 192; //180; // red
630
630
631
    // UNUSED?
631
    // UNUSED?
632
    vgapal16[41*4+0] = 0; //96;
632
    vgapal16[41*4+0] = 0; //96;
633
    vgapal16[41*4+1] = 0; //160;
633
    vgapal16[41*4+1] = 0; //160;
634
    vgapal16[41*4+2] = 252; //192;
634
    vgapal16[41*4+2] = 252; //192;
635
-
 
636
    for (int i = 0; i<256; i++)
-
 
637
    {
-
 
638
        if (editorcolors[i] == 0)
-
 
639
        {
-
 
640
            palette_t *edcol = (palette_t *)&vgapal16[4*i];
-
 
641
            editorcolors[i] = paletteGetClosestColorUpToIndex(edcol->b,edcol->g,edcol->r, 239);
-
 
642
        }
-
 
643
    }
-
 
644
}
635
}
645
636
646
int app_main(int argc, char const * const * argv)
637
int app_main(int argc, char const * const * argv)
647
{
638
{
648
#ifdef STARTUP_SETUP_WINDOW
639
#ifdef STARTUP_SETUP_WINDOW
649
    char cmdsetup = 0;
640
    char cmdsetup = 0;
650
#endif
641
#endif
651
    char quitflag;
642
    char quitflag;
652
    int32_t i;
643
    int32_t i;
653
644
654
    pathsearchmode = 1;         // unrestrict findfrompath so that full access to the filesystem can be had
645
    pathsearchmode = 1;         // unrestrict findfrompath so that full access to the filesystem can be had
655
646
656
#ifdef USE_OPENGL
647
#ifdef USE_OPENGL
657
    OSD_RegisterFunction("restartvid","restartvid: reinitialize the video mode",osdcmd_restartvid);
648
    OSD_RegisterFunction("restartvid","restartvid: reinitialize the video mode",osdcmd_restartvid);
658
    OSD_RegisterFunction("vidmode","vidmode <xdim> <ydim> <bpp> <fullscreen>: immediately change the video mode",osdcmd_vidmode);
649
    OSD_RegisterFunction("vidmode","vidmode <xdim> <ydim> <bpp> <fullscreen>: immediately change the video mode",osdcmd_vidmode);
659
    baselayer_osdcmd_vidmode_func = osdcmd_vidmode;
650
    baselayer_osdcmd_vidmode_func = osdcmd_vidmode;
660
#else
651
#else
661
    OSD_RegisterFunction("vidmode","vidmode <xdim> <ydim>: immediately change the video mode",osdcmd_vidmode);
652
    OSD_RegisterFunction("vidmode","vidmode <xdim> <ydim>: immediately change the video mode",osdcmd_vidmode);
662
#endif
653
#endif
663
654
664
    wm_setapptitle(AppProperName);
655
    wm_setapptitle(AppProperName);
665
656
666
    editstatus = 1;
657
    editstatus = 1;
667
658
668
    if ((i = CallExtPreInit(argc,argv)) < 0) return -1;
659
    if ((i = CallExtPreInit(argc,argv)) < 0) return -1;
669
660
670
#ifdef _WIN32
661
#ifdef _WIN32
671
    win_priorityclass = 1;
662
    win_priorityclass = 1;
672
#endif
663
#endif
673
664
674
    for (i=1; i<argc; i++)
665
    for (i=1; i<argc; i++)
675
    {
666
    {
676
        if (argv[i][0] == '-')
667
        if (argv[i][0] == '-')
677
        {
668
        {
678
#ifdef STARTUP_SETUP_WINDOW
669
#ifdef STARTUP_SETUP_WINDOW
679
            if (!Bstrcmp(argv[i], "-setup")) cmdsetup = 1;
670
            if (!Bstrcmp(argv[i], "-setup")) cmdsetup = 1;
680
            else
671
            else
681
#endif
672
#endif
682
            if (!Bstrcmp(argv[i], "-help") || !Bstrcmp(argv[i], "--help") || !Bstrcmp(argv[i], "-?"))
673
            if (!Bstrcmp(argv[i], "-help") || !Bstrcmp(argv[i], "--help") || !Bstrcmp(argv[i], "-?"))
683
            {
674
            {
684
#ifdef WM_MSGBOX_WINDOW
675
#ifdef WM_MSGBOX_WINDOW
685
                wm_msgbox(AppProperName,
676
                wm_msgbox(AppProperName,
686
#else
677
#else
687
                Bprintf(
678
                Bprintf(
688
#endif
679
#endif
689
                    "%s\n"
680
                    "%s\n"
690
                    "Syntax: %s [options] mapname\n"
681
                    "Syntax: %s [options] mapname\n"
691
                    "Options:\n"
682
                    "Options:\n"
692
                    "\t-grp\tUse an extra GRP or ZIP file.\n"
683
                    "\t-grp\tUse an extra GRP or ZIP file.\n"
693
                    "\t-g\tSame as above.\n"
684
                    "\t-g\tSame as above.\n"
694
#ifdef STARTUP_SETUP_WINDOW
685
#ifdef STARTUP_SETUP_WINDOW
695
                    "\t-setup\tDisplays the configuration dialogue box before entering the editor.\n"
686
                    "\t-setup\tDisplays the configuration dialogue box before entering the editor.\n"
696
#endif
687
#endif
697
                    , AppProperName, AppTechnicalName);
688
                    , AppProperName, AppTechnicalName);
698
                return 0;
689
                return 0;
699
            }
690
            }
700
            continue;
691
            continue;
701
        }
692
        }
702
    }
693
    }
703
694
704
    if (boardfilename[0] == 0)
695
    if (boardfilename[0] == 0)
705
        Bstrcpy(boardfilename,"newboard.map");
696
        Bstrcpy(boardfilename,"newboard.map");
706
    else if (Bstrchr(boardfilename,'.') == 0)
697
    else if (Bstrchr(boardfilename,'.') == 0)
707
        Bstrcat(boardfilename, ".map");
698
        Bstrcat(boardfilename, ".map");
708
    //Bcanonicalisefilename(boardfilename,0);
699
    //Bcanonicalisefilename(boardfilename,0);
709
700
710
    OSD_SetFunctions(
701
    OSD_SetFunctions(
711
        NULL, NULL, NULL, NULL, NULL,
702
        NULL, NULL, NULL, NULL, NULL,
712
        COMMON_clearbackground,
703
        COMMON_clearbackground,
713
        BGetTime,
704
        BGetTime,
714
        M32_OnShowOSD
705
        M32_OnShowOSD
715
    );
706
    );
716
707
717
    if (!buildvfs_getcwd(program_origcwd,BMAX_PATH))
708
    if (!buildvfs_getcwd(program_origcwd,BMAX_PATH))
718
        program_origcwd[0] = '\0';
709
        program_origcwd[0] = '\0';
719
710
720
    Bstrncpy(game_executable, DefaultGameLocalExec, sizeof(game_executable));
711
    Bstrncpy(game_executable, DefaultGameLocalExec, sizeof(game_executable));
721
712
722
    if (enginePreInit())
713
    if (enginePreInit())
723
        M32_FatalEngineError();
714
        M32_FatalEngineError();
724
715
725
    if ((i = CallExtInit()) < 0) return -1;
716
    if ((i = CallExtInit()) < 0) return -1;
726
717
727
#ifdef STARTUP_SETUP_WINDOW
718
#ifdef STARTUP_SETUP_WINDOW
728
    if (i || forcesetup || cmdsetup)
719
    if (i || forcesetup || cmdsetup)
729
    {
720
    {
730
        if (quitevent || !startwin_run())
721
        if (quitevent || !startwin_run())
731
        {
722
        {
732
            engineUnInit();
723
            engineUnInit();
733
            exit(EXIT_SUCCESS);
724
            exit(EXIT_SUCCESS);
734
        }
725
        }
735
    }
726
    }
736
#endif
727
#endif
737
728
738
    if (CallExtPostStartupWindow() < 0) return -1;
729
    if (CallExtPostStartupWindow() < 0) return -1;
739
730
740
    loadnames(g_namesFileName);
731
    loadnames(g_namesFileName);
741
732
742
    if (initinput()) return -1;
733
    if (initinput()) return -1;
743
734
744
    mouseInit();
735
    mouseInit();
745
736
746
    timerInit(CLOCKTICKSPERSECOND);
737
    timerInit(CLOCKTICKSPERSECOND);
747
    timerSetCallback(keytimerstuff);
738
    timerSetCallback(keytimerstuff);
748
739
749
    artLoadFiles("tiles000.art", g_maxCacheSize);
740
    artLoadFiles("tiles000.art", g_maxCacheSize);
750
741
751
    Bstrcpy(kensig,"Uses BUILD technology by Ken Silverman");
742
    Bstrcpy(kensig,"Uses BUILD technology by Ken Silverman");
752
    initcrc();
743
    initcrc();
753
744
-
 
745
    InitCustomColors();
-
 
746
754
    const char *defsfile = G_DefFile();
747
    const char *defsfile = G_DefFile();
755
748
756
    if (testkopen("editor.def", 0))
749
    if (testkopen("editor.def", 0))
757
        G_AddDefModule("editor.def");
750
        G_AddDefModule("editor.def");
758
751
759
    if (!loaddefinitionsfile(defsfile))
752
    if (!loaddefinitionsfile(defsfile))
760
        initprintf("Definitions file \"%s\" loaded.\n",defsfile);
753
        initprintf("Definitions file \"%s\" loaded.\n",defsfile);
761
754
762
    for (char * m : g_defModules)
755
    for (char * m : g_defModules)
763
        free(m);
756
        free(m);
764
    g_defModules.clear();
757
    g_defModules.clear();
765
758
766
    if (enginePostInit())
759
    if (enginePostInit())
767
        M32_FatalEngineError();
760
        M32_FatalEngineError();
768
761
769
    InitCustomColors();
-
 
770
-
 
771
    CallExtPostInit();
762
    CallExtPostInit();
772
763
773
#ifdef YAX_ENABLE
764
#ifdef YAX_ENABLE
774
    // init dummy texture for YAX
765
    // init dummy texture for YAX
775
    // must be after loadpics(), which inits BUILD's cache
766
    // must be after loadpics(), which inits BUILD's cache
776
767
777
    i = MAXTILES-1;
768
    i = MAXTILES-1;
778
    if (tilesiz[i].x==0 && tilesiz[i].y==0)
769
    if (tilesiz[i].x==0 && tilesiz[i].y==0)
779
    {
770
    {
780
        static char R[8*16] = { //
771
        static char R[8*16] = { //
781
            0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,
772
            0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,
782
            0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,
773
            0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,
783
            0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,
774
            0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,
784
            0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0,
775
            0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0,
785
            0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0,
776
            0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0,
786
            0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0,
777
            0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0,
787
            0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0,
778
            0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0,
788
        };
779
        };
789
780
790
        char *newtile;
781
        char *newtile;
791
        int32_t sx=32, sy=32, col, j;
782
        int32_t sx=32, sy=32, col, j;
792
783
793
        walock[i] = CACHE1D_PERMANENT;
784
        walock[i] = CACHE1D_PERMANENT;
794
        picsiz[i] = 5 + (5<<4);
785
        picsiz[i] = 5 + (5<<4);
795
        tilesiz[i].x = sx; tilesiz[i].y = sy;
786
        tilesiz[i].x = sx; tilesiz[i].y = sy;
796
        g_cache.allocateBlock(&waloff[i], sx*sy, &walock[i]);
787
        g_cache.allocateBlock(&waloff[i], sx*sy, &walock[i]);
797
        newtile = (char *)waloff[i];
788
        newtile = (char *)waloff[i];
798
789
799
        col = paletteGetClosestColor(128, 128, 0);
790
        col = paletteGetClosestColor(128, 128, 0);
800
        for (j=0; j<(signed)sizeof(R); j++)
791
        for (j=0; j<(signed)sizeof(R); j++)
801
            R[j] *= col;
792
            R[j] *= col;
802
793
803
        Bmemset(newtile, 0, sx*sy);
794
        Bmemset(newtile, 0, sx*sy);
804
        for (j=0; j<8; j++)
795
        for (j=0; j<8; j++)
805
            Bmemcpy(&newtile[32*j], &R[16*j], 16);
796
            Bmemcpy(&newtile[32*j], &R[16*j], 16);
806
    }
797
    }
807
#endif
798
#endif
808
799
809
#ifdef HAVE_CLIPSHAPE_FEATURE
800
#ifdef HAVE_CLIPSHAPE_FEATURE
810
    int k = engineLoadClipMaps();
801
    int k = engineLoadClipMaps();
811
    if (k>0)
802
    if (k>0)
812
        initprintf("There was an error loading the sprite clipping map (status %d).\n", k);
803
        initprintf("There was an error loading the sprite clipping map (status %d).\n", k);
813
804
814
    for (char * f : g_clipMapFiles)
805
    for (char * f : g_clipMapFiles)
815
        free(f);
806
        free(f);
816
    g_clipMapFiles.clear();
807
    g_clipMapFiles.clear();
817
#endif
808
#endif
818
809
819
    taglab_init();
810
    taglab_init();
820
811
821
    mkonwinvalid();
812
    mkonwinvalid();
822
813
823
    // executed once per init
814
    // executed once per init
824
    OSD_Exec("m32_autoexec.cfg");
815
    OSD_Exec("m32_autoexec.cfg");
825
816
826
    if (LoadBoard(boardfilename, 1))
817
    if (LoadBoard(boardfilename, 1))
827
        reset_default_mapstate();
818
        reset_default_mapstate();
828
819
829
    totalclock = 0;
820
    totalclock = 0;
830
821
831
    updatesector(pos.x,pos.y,&cursectnum);
822
    updatesector(pos.x,pos.y,&cursectnum);
832
823
833
    keySetCallback(&m32_keypresscallback);
824
    keySetCallback(&m32_keypresscallback);
834
    M32_OnShowOSD(0);  // make sure the desktop's mouse cursor is hidden
825
    M32_OnShowOSD(0);  // make sure the desktop's mouse cursor is hidden
835
826
836
    if (cursectnum == -1)
827
    if (cursectnum == -1)
837
    {
828
    {
838
        vid_gamma_3d = g_videoGamma;
829
        vid_gamma_3d = g_videoGamma;
839
        vid_brightness_3d = g_videoBrightness;
830
        vid_brightness_3d = g_videoBrightness;
840
        vid_contrast_3d = g_videoContrast;
831
        vid_contrast_3d = g_videoContrast;
841
832
842
        g_videoGamma = g_videoContrast = 1.0;
833
        g_videoGamma = g_videoContrast = 1.0;
843
        g_videoBrightness = 0.0;
834
        g_videoBrightness = 0.0;
844
835
845
        videoSetPalette(0,0,0);
836
        videoSetPalette(0,0,0);
846
        if (videoSetGameMode(fullscreen, xdim2d, ydim2d, 8, upscalefactor) < 0)
837
        if (videoSetGameMode(fullscreen, xdim2d, ydim2d, 8, upscalefactor) < 0)
847
        {
838
        {
848
            CallExtUnInit();
839
            CallExtUnInit();
849
            engineUnInit();
840
            engineUnInit();
850
            Bprintf("%d * %d not supported in this graphics mode\n",xdim2d,ydim2d);
841
            Bprintf("%d * %d not supported in this graphics mode\n",xdim2d,ydim2d);
851
            Bexit(EXIT_SUCCESS);
842
            Bexit(EXIT_SUCCESS);
852
        }
843
        }
853
844
854
        system_getcvars();
845
        system_getcvars();
855
846
856
        overheadeditor();
847
        overheadeditor();
857
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
848
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
858
849
859
        g_videoGamma = vid_gamma_3d;
850
        g_videoGamma = vid_gamma_3d;
860
        g_videoContrast = vid_contrast_3d;
851
        g_videoContrast = vid_contrast_3d;
861
        g_videoBrightness = vid_brightness_3d;
852
        g_videoBrightness = vid_brightness_3d;
862
853
863
        vid_gamma_3d = vid_contrast_3d = vid_brightness_3d = -1;
854
        vid_gamma_3d = vid_contrast_3d = vid_brightness_3d = -1;
864
855
865
        videoSetPalette(GAMMA_CALC,0,0);
856
        videoSetPalette(GAMMA_CALC,0,0);
866
    }
857
    }
867
    else
858
    else
868
    {
859
    {
869
        if (videoSetGameMode(fullscreen, xdimgame, ydimgame, bppgame, upscalefactor) < 0)
860
        if (videoSetGameMode(fullscreen, xdimgame, ydimgame, bppgame, upscalefactor) < 0)
870
        {
861
        {
871
            CallExtUnInit();
862
            CallExtUnInit();
872
            engineUnInit();
863
            engineUnInit();
873
            Bprintf("%d * %d not supported in this graphics mode\n",xdim,ydim);
864
            Bprintf("%d * %d not supported in this graphics mode\n",xdim,ydim);
874
            Bexit(EXIT_SUCCESS);
865
            Bexit(EXIT_SUCCESS);
875
        }
866
        }
876
867
877
        system_getcvars();
868
        system_getcvars();
878
869
879
        videoSetPalette(GAMMA_CALC,0,0);
870
        videoSetPalette(GAMMA_CALC,0,0);
880
    }
871
    }
881
872
882
CANCEL:
873
CANCEL:
883
    quitflag = 0;
874
    quitflag = 0;
884
    while (quitflag == 0)
875
    while (quitflag == 0)
885
    {
876
    {
886
        if (handleevents())
877
        if (handleevents())
887
        {
878
        {
888
            if (quitevent)
879
            if (quitevent)
889
            {
880
            {
890
                keystatus[sc_Escape] = 1;
881
                keystatus[sc_Escape] = 1;
891
                quitevent = 0;
882
                quitevent = 0;
892
            }
883
            }
893
        }
884
        }
894
885
895
        OSD_DispatchQueued();
886
        OSD_DispatchQueued();
896
887
897
        videoNextPage();
888
        videoNextPage();
898
        synctics = (int32_t) totalclock-lockclock;
889
        synctics = (int32_t) totalclock-lockclock;
899
        lockclock += synctics;
890
        lockclock += synctics;
900
891
901
        CallExtPreCheckKeys();
892
        CallExtPreCheckKeys();
902
893
903
        M32_DrawRoomsAndMasks();
894
        M32_DrawRoomsAndMasks();
904
895
905
        inputchecked = 1;
896
        inputchecked = 1;
906
897
907
#ifdef M32_SHOWDEBUG
898
#ifdef M32_SHOWDEBUG
908
        if (searchstat>=0 && (searchwall<0 || searchsector<0))
899
        if (searchstat>=0 && (searchwall<0 || searchsector<0))
909
        {
900
        {
910
            if (m32_numdebuglines<64)
901
            if (m32_numdebuglines<64)
911
                Bsprintf(m32_debugstr[m32_numdebuglines++], "inconsistent search variables!");
902
                Bsprintf(m32_debugstr[m32_numdebuglines++], "inconsistent search variables!");
912
            searchstat = -1;
903
            searchstat = -1;
913
        }
904
        }
914
905
915
        M32_drawdebug();
906
        M32_drawdebug();
916
#endif
907
#endif
917
        CallExtCheckKeys();
908
        CallExtCheckKeys();
918
909
919
910
920
        if (keystatus[sc_Escape])
911
        if (keystatus[sc_Escape])
921
        {
912
        {
922
            keystatus[sc_Escape] = 0;
913
            keystatus[sc_Escape] = 0;
923
914
924
            printext256(0,0,whitecol,0,"Are you sure you want to quit?",0);
915
            printext256(0,0,whitecol,0,"Are you sure you want to quit?",0);
925
916
926
            videoShowFrame(1);
917
            videoShowFrame(1);
927
            synctics = (int32_t) totalclock-lockclock;
918
            synctics = (int32_t) totalclock-lockclock;
928
            lockclock += synctics;
919
            lockclock += synctics;
929
920
930
            while ((keystatus[sc_Escape]|keystatus[sc_Enter]|keystatus[sc_Space]|keystatus[sc_N]) == 0)
921
            while ((keystatus[sc_Escape]|keystatus[sc_Enter]|keystatus[sc_Space]|keystatus[sc_N]) == 0)
931
            {
922
            {
932
                idle_waitevent();
923
                idle_waitevent();
933
                if (handleevents())
924
                if (handleevents())
934
                {
925
                {
935
                    if (quitevent)
926
                    if (quitevent)
936
                    {
927
                    {
937
                        quitflag = 1;
928
                        quitflag = 1;
938
                        break;
929
                        break;
939
                    }
930
                    }
940
                }
931
                }
941
932
942
                if (keystatus[sc_Y]||keystatus[sc_Enter]) // Y or ENTER
933
                if (keystatus[sc_Y]||keystatus[sc_Enter]) // Y or ENTER
943
                {
934
                {
944
                    keystatus[sc_Y] = 0;
935
                    keystatus[sc_Y] = 0;
945
                    keystatus[sc_Enter] = 0;
936
                    keystatus[sc_Enter] = 0;
946
                    quitflag = 1; break;
937
                    quitflag = 1; break;
947
                }
938
                }
948
            }
939
            }
949
            while (keystatus[sc_Escape])
940
            while (keystatus[sc_Escape])
950
            {
941
            {
951
                keystatus[sc_Escape] = 0;
942
                keystatus[sc_Escape] = 0;
952
                quitevent = 0;
943
                quitevent = 0;
953
                goto CANCEL;
944
                goto CANCEL;
954
            }
945
            }
955
        }
946
        }
956
    }
947
    }
957
948
958
    if (asksave)
949
    if (asksave)
959
    {
950
    {
960
        i = CheckMapCorruption(4, 0);
951
        i = CheckMapCorruption(4, 0);
961
952
962
        printext256(0,8,whitecol,0,i<4?"Save changes?":"Map is heavily corrupt. Save changes?",0);
953
        printext256(0,8,whitecol,0,i<4?"Save changes?":"Map is heavily corrupt. Save changes?",0);
963
        videoShowFrame(1);
954
        videoShowFrame(1);
964
955
965
        while ((keystatus[sc_Escape]|keystatus[sc_Enter]|keystatus[sc_Space]|keystatus[sc_N]|keystatus[sc_C]) == 0)
956
        while ((keystatus[sc_Escape]|keystatus[sc_Enter]|keystatus[sc_Space]|keystatus[sc_N]|keystatus[sc_C]) == 0)
966
        {
957
        {
967
            idle_waitevent();
958
            idle_waitevent();
968
            if (handleevents()) { if (quitevent) break; } // like saying no
959
            if (handleevents()) { if (quitevent) break; } // like saying no
969
960
970
            if (keystatus[sc_Y] || keystatus[sc_Enter]) // Y or ENTER
961
            if (keystatus[sc_Y] || keystatus[sc_Enter]) // Y or ENTER
971
            {
962
            {
972
                keystatus[sc_Y] = keystatus[sc_Enter] = 0;
963
                keystatus[sc_Y] = keystatus[sc_Enter] = 0;
973
964
974
                SaveBoard(NULL, M32_SB_ASKOV);
965
                SaveBoard(NULL, M32_SB_ASKOV);
975
966
976
                break;
967
                break;
977
            }
968
            }
978
        }
969
        }
979
        while (keystatus[sc_Escape]||keystatus[sc_C])
970
        while (keystatus[sc_Escape]||keystatus[sc_C])
980
        {
971
        {
981
            keystatus[sc_Escape] = keystatus[sc_C] = 0;
972
            keystatus[sc_Escape] = keystatus[sc_C] = 0;
982
            quitevent = 0;
973
            quitevent = 0;
983
            goto CANCEL;
974
            goto CANCEL;
984
        }
975
        }
985
    }
976
    }
986
977
987
978
988
    CallExtUnInit();
979
    CallExtUnInit();
989
//    clearfilenames();
980
//    clearfilenames();
990
    engineUnInit();
981
    engineUnInit();
991
982
992
    return 0;
983
    return 0;
993
}
984
}
994
985
995
static int32_t mhk=0;
986
static int32_t mhk=0;
996
static void loadmhk(int32_t domessage)
987
static void loadmhk(int32_t domessage)
997
{
988
{
998
    char levname[BMAX_PATH];
989
    char levname[BMAX_PATH];
999
990
1000
    if (!mhk)
991
    if (!mhk)
1001
        return;
992
        return;
1002
993
1003
    Bstrcpy(levname, boardfilename);
994
    Bstrcpy(levname, boardfilename);
1004
    append_ext_UNSAFE(levname, ".mhk");
995
    append_ext_UNSAFE(levname, ".mhk");
1005
996
1006
    if (!engineLoadMHK(levname))
997
    if (!engineLoadMHK(levname))
1007
    {
998
    {
1008
        if (domessage)
999
        if (domessage)
1009
            message("Loaded map hack file \"%s\"",levname);
1000
            message("Loaded map hack file \"%s\"",levname);
1010
        else
1001
        else
1011
            initprintf("Loaded map hack file \"%s\"\n",levname);
1002
            initprintf("Loaded map hack file \"%s\"\n",levname);
1012
    }
1003
    }
1013
    else
1004
    else
1014
    {
1005
    {
1015
        mhk=2;
1006
        mhk=2;
1016
        if (domessage)
1007
        if (domessage)
1017
            message("No maphack found for map \"%s\"",boardfilename);
1008
            message("No maphack found for map \"%s\"",boardfilename);
1018
    }
1009
    }
1019
}
1010
}
1020
1011
1021
// this is spriteon{ceiling,ground}z from astub.c packed into
1012
// this is spriteon{ceiling,ground}z from astub.c packed into
1022
// one convenient function
1013
// one convenient function
1023
void spriteoncfz(int32_t i, int32_t *czptr, int32_t *fzptr)
1014
void spriteoncfz(int32_t i, int32_t *czptr, int32_t *fzptr)
1024
{
1015
{
1025
    int32_t height, zofs;
1016
    int32_t height, zofs;
1026
1017
1027
    getzsofslope(sprite[i].sectnum, sprite[i].x,sprite[i].y, czptr, fzptr);
1018
    getzsofslope(sprite[i].sectnum, sprite[i].x,sprite[i].y, czptr, fzptr);
1028
    if ((sprite[i].cstat&48)==32)
1019
    if ((sprite[i].cstat&48)==32)
1029
        return;
1020
        return;
1030
1021
1031
    zofs = spriteheightofs(i, &height, 0);
1022
    zofs = spriteheightofs(i, &height, 0);
1032
1023
1033
    *czptr += height - zofs;
1024
    *czptr += height - zofs;
1034
    *fzptr -= zofs;
1025
    *fzptr -= zofs;
1035
}
1026
}
1036
1027
1037
static void move_and_update(int32_t xvect, int32_t yvect, int32_t addshr)
1028
static void move_and_update(int32_t xvect, int32_t yvect, int32_t addshr)
1038
{
1029
{
1039
    if (m32_clipping==0)
1030
    if (m32_clipping==0)
1040
    {
1031
    {
1041
        pos.x += xvect>>(14+addshr);
1032
        pos.x += xvect>>(14+addshr);
1042
        pos.y += yvect>>(14+addshr);
1033
        pos.y += yvect>>(14+addshr);
1043
        updatesector(pos.x,pos.y, &cursectnum);
1034
        updatesector(pos.x,pos.y, &cursectnum);
1044
    }
1035
    }
1045
    else
1036
    else
1046
    {
1037
    {
1047
        clipmove(&pos,&cursectnum, xvect>>addshr,yvect>>addshr,
1038
        clipmove(&pos,&cursectnum, xvect>>addshr,yvect>>addshr,
1048
                 128,4<<8,4<<8, (m32_clipping==1) ? 0 : CLIPMASK0);
1039
                 128,4<<8,4<<8, (m32_clipping==1) ? 0 : CLIPMASK0);
1049
    }
1040
    }
1050
1041
1051
    if (in3dmode())
1042
    if (in3dmode())
1052
    {
1043
    {
1053
        silentmessage("x:%d y:%d z:%d ang:%d horiz:%d", pos.x, pos.y, pos.z, ang, horiz);
1044
        silentmessage("x:%d y:%d z:%d ang:%d horiz:%d", pos.x, pos.y, pos.z, ang, horiz);
1054
        getmessagetimeoff = (int32_t) totalclock+30;
1045
        getmessagetimeoff = (int32_t) totalclock+30;
1055
    }
1046
    }
1056
}
1047
}
1057
1048
1058
static void mainloop_move(void)
1049
static void mainloop_move(void)
1059
{
1050
{
1060
    int32_t xvect, yvect, doubvel;
1051
    int32_t xvect, yvect, doubvel;
1061
1052
1062
    if (angvel != 0)  //ang += angvel * constant
1053
    if (angvel != 0)  //ang += angvel * constant
1063
    {
1054
    {
1064
        if (eitherCTRL && m32_2d3dmode)
1055
        if (eitherCTRL && m32_2d3dmode)
1065
        {
1056
        {
1066
            int x = m32_2d3d.x + (angvel / 32);
1057
            int x = m32_2d3d.x + (angvel / 32);
1067
            int xx = m32_2d3d.x + XSIZE_2D3D + (angvel / 32);
1058
            int xx = m32_2d3d.x + XSIZE_2D3D + (angvel / 32);
1068
1059
1069
            if (x > 4 && xx < xdim2d - 4)
1060
            if (x > 4 && xx < xdim2d - 4)
1070
            {
1061
            {
1071
                silentmessage("2d3d x:%d y:%d", m32_2d3d.x, m32_2d3d.y);
1062
                silentmessage("2d3d x:%d y:%d", m32_2d3d.x, m32_2d3d.y);
1072
                m32_2d3d.x += (angvel / 32);
1063
                m32_2d3d.x += (angvel / 32);
1073
            }
1064
            }
1074
        }
1065
        }
1075
        else
1066
        else
1076
        {
1067
        {
1077
            //ENGINE calculates angvel for you
1068
            //ENGINE calculates angvel for you
1078
1069
1079
            //Lt. shift makes turn velocity 50% faster
1070
            //Lt. shift makes turn velocity 50% faster
1080
            doubvel = (synctics + DOWN_BK(RUN)*(synctics>>1));
1071
            doubvel = (synctics + DOWN_BK(RUN)*(synctics>>1));
1081
1072
1082
            ang += ((angvel*doubvel)>>4);
1073
            ang += ((angvel*doubvel)>>4);
1083
            ang &= 2047;
1074
            ang &= 2047;
1084
1075
1085
            if (in3dmode())
1076
            if (in3dmode())
1086
            {
1077
            {
1087
                silentmessage("x:%d y:%d z:%d ang:%d horiz:%d", pos.x, pos.y, pos.z, ang, horiz);
1078
                silentmessage("x:%d y:%d z:%d ang:%d horiz:%d", pos.x, pos.y, pos.z, ang, horiz);
1088
                getmessagetimeoff = (int32_t) totalclock+30;
1079
                getmessagetimeoff = (int32_t) totalclock+30;
1089
            }
1080
            }
1090
        }
1081
        }
1091
    }
1082
    }
1092
    if ((vel|svel) != 0)
1083
    if ((vel|svel) != 0)
1093
    {
1084
    {
1094
        if (eitherCTRL && m32_2d3dmode)
1085
        if (eitherCTRL && m32_2d3dmode)
1095
        {
1086
        {
1096
            int y = m32_2d3d.y - (vel / 64);
1087
            int y = m32_2d3d.y - (vel / 64);
1097
            int yy = m32_2d3d.y + YSIZE_2D3D - (vel / 64);
1088
            int yy = m32_2d3d.y + YSIZE_2D3D - (vel / 64);
1098
1089
1099
            if (y > 4 && yy < ydim2d - STATUS2DSIZ2 - 4)
1090
            if (y > 4 && yy < ydim2d - STATUS2DSIZ2 - 4)
1100
            {
1091
            {
1101
                silentmessage("2d3d x:%d y:%d", m32_2d3d.x, m32_2d3d.y);
1092
                silentmessage("2d3d x:%d y:%d", m32_2d3d.x, m32_2d3d.y);
1102
                m32_2d3d.y -= (vel / 64);
1093
                m32_2d3d.y -= (vel / 64);
1103
            }
1094
            }
1104
        }
1095
        }
1105
        else
1096
        else
1106
1097
1107
        {
1098
        {
1108
            //Lt. shift doubles forward velocity
1099
            //Lt. shift doubles forward velocity
1109
            doubvel = (1+(DOWN_BK(RUN)))*synctics;
1100
            doubvel = (1+(DOWN_BK(RUN)))*synctics;
1110
1101
1111
            xvect = 0;
1102
            xvect = 0;
1112
            yvect = 0;
1103
            yvect = 0;
1113
1104
1114
            if (vel != 0)
1105
            if (vel != 0)
1115
            {
1106
            {
1116
                xvect += ((vel*doubvel)>>3)*(int32_t) sintable[(ang+2560)&2047];
1107
                xvect += ((vel*doubvel)>>3)*(int32_t) sintable[(ang+2560)&2047];
1117
                yvect += ((vel*doubvel)>>3)*(int32_t) sintable[(ang+2048)&2047];
1108
                yvect += ((vel*doubvel)>>3)*(int32_t) sintable[(ang+2048)&2047];
1118
            }
1109
            }
1119
            if (svel != 0)
1110
            if (svel != 0)
1120
            {
1111
            {
1121
                xvect += ((svel*doubvel)>>3)*(int32_t) sintable[(ang+2048)&2047];
1112
                xvect += ((svel*doubvel)>>3)*(int32_t) sintable[(ang+2048)&2047];
1122
                yvect += ((svel*doubvel)>>3)*(int32_t) sintable[(ang+1536)&2047];
1113
                yvect += ((svel*doubvel)>>3)*(int32_t) sintable[(ang+1536)&2047];
1123
            }
1114
            }
1124
1115
1125
            move_and_update(xvect, yvect, 0);
1116
            move_and_update(xvect, yvect, 0);
1126
        }
1117
        }
1127
    }
1118
    }
1128
}
1119
}
1129
1120
1130
static void handle_sprite_in_clipboard(int32_t i)
1121
static void handle_sprite_in_clipboard(int32_t i)
1131
{
1122
{
1132
    if (somethingintab == 3)
1123
    if (somethingintab == 3)
1133
    {
1124
    {
1134
        int32_t j, k;
1125
        int32_t j, k;
1135
1126
1136
        sprite[i].picnum = temppicnum;
1127
        sprite[i].picnum = temppicnum;
1137
        if (tilesiz[temppicnum].x <= 0 || tilesiz[temppicnum].y <= 0)
1128
        if (tilesiz[temppicnum].x <= 0 || tilesiz[temppicnum].y <= 0)
1138
        {
1129
        {
1139
            j = 0;
1130
            j = 0;
1140
            for (k=0; k<MAXTILES; k++)
1131
            for (k=0; k<MAXTILES; k++)
1141
                if (tilesiz[k].x > 0 && tilesiz[k].y > 0)
1132
                if (tilesiz[k].x > 0 && tilesiz[k].y > 0)
1142
                {
1133
                {
1143
                    j = k;
1134
                    j = k;
1144
                    break;
1135
                    break;
1145
                }
1136
                }
1146
            sprite[i].picnum = j;
1137
            sprite[i].picnum = j;
1147
        }
1138
        }
1148
        sprite[i].shade = tempshade;
1139
        sprite[i].shade = tempshade;
1149
        sprite[i].blend = tempblend;
1140
        sprite[i].blend = tempblend;
1150
        sprite[i].pal = temppal;
1141
        sprite[i].pal = temppal;
1151
        sprite[i].xrepeat = max(tempxrepeat, 1u);
1142
        sprite[i].xrepeat = max(tempxrepeat, 1u);
1152
        sprite[i].yrepeat = max(tempyrepeat, 1u);
1143
        sprite[i].yrepeat = max(tempyrepeat, 1u);
1153
        sprite[i].cstat = tempcstat;
1144
        sprite[i].cstat = tempcstat;
1154
    }
1145
    }
1155
}
1146
}
1156
1147
1157
1148
1158
void editinput(void)
1149
void editinput(void)
1159
{
1150
{
1160
    int32_t mousz, bstatus;
1151
    int32_t mousz, bstatus;
1161
    int32_t i, tempint=0;
1152
    int32_t i, tempint=0;
1162
    int32_t goalz, xvect, yvect, hiz, loz, oposz;
1153
    int32_t goalz, xvect, yvect, hiz, loz, oposz;
1163
    int32_t hihit, lohit, omlook=mlook;
1154
    int32_t hihit, lohit, omlook=mlook;
1164
1155
1165
// 3B  3C  3D  3E   3F  40  41  42   43  44  57  58          46
1156
// 3B  3C  3D  3E   3F  40  41  42   43  44  57  58          46
1166
// F1  F2  F3  F4   F5  F6  F7  F8   F9 F10 F11 F12        SCROLL
1157
// F1  F2  F3  F4   F5  F6  F7  F8   F9 F10 F11 F12        SCROLL
1167
1158
1168
    mousz = 0;
1159
    mousz = 0;
1169
    mouseGetValues(&mousx,&mousy,&bstatus);
1160
    mouseGetValues(&mousx,&mousy,&bstatus);
1170
    mousx = (mousx<<16) + mousexsurp;
1161
    mousx = (mousx<<16) + mousexsurp;
1171
    mousy = (mousy<<16) + mouseysurp;
1162
    mousy = (mousy<<16) + mouseysurp;
1172
1163
1173
    if (unrealedlook && !mskip)
1164
    if (unrealedlook && !mskip)
1174
    {
1165
    {
1175
        if (mlook==0 && (bstatus&(1|2|4))==2)
1166
        if (mlook==0 && (bstatus&(1|2|4))==2)
1176
            mlook = 3;
1167
            mlook = 3;
1177
        else if ((bstatus&(1|2|4))==1)
1168
        else if ((bstatus&(1|2|4))==1)
1178
            mlook = 3;
1169
            mlook = 3;
1179
    }
1170
    }
1180
1171
1181
    {
1172
    {
1182
        ldiv_t ld;
1173
        ldiv_t ld;
1183
        if (mlook)
1174
        if (mlook)
1184
        {
1175
        {
1185
            ld = ldiv(mousx, (int32_t)((1<<16)/(msens*0.5f))); mousx = ld.quot; mousexsurp = ld.rem;
1176
            ld = ldiv(mousx, (int32_t)((1<<16)/(msens*0.5f))); mousx = ld.quot; mousexsurp = ld.rem;
1186
            ld = ldiv(mousy, (int32_t)((1<<16)/(msens*0.25f))); mousy = ld.quot; mouseysurp = ld.rem;
1177
            ld = ldiv(mousy, (int32_t)((1<<16)/(msens*0.25f))); mousy = ld.quot; mouseysurp = ld.rem;
1187
        }
1178
        }
1188
        else
1179
        else
1189
        {
1180
        {
1190
            ld = ldiv(mousx, (int32_t)((1<<16)/msens)); mousx = ld.quot; mousexsurp = ld.rem;
1181
            ld = ldiv(mousx, (int32_t)((1<<16)/msens)); mousx = ld.quot; mousexsurp = ld.rem;
1191
            ld = ldiv(mousy, (int32_t)((1<<16)/msens)); mousy = ld.quot; mouseysurp = ld.rem;
1182
            ld = ldiv(mousy, (int32_t)((1<<16)/msens)); mousy = ld.quot; mouseysurp = ld.rem;
1192
        }
1183
        }
1193
    }
1184
    }
1194
1185
1195
    if (mlook == 3)
1186
    if (mlook == 3)
1196
        mlook = omlook;
1187
        mlook = omlook;
1197
1188
1198
    // UnrealEd:
1189
    // UnrealEd:
1199
    // rmb: mouselook
1190
    // rmb: mouselook
1200
    // lbm: x:turn y:fwd/back local x
1191
    // lbm: x:turn y:fwd/back local x
1201
    // lmb&rmb: x:strafe y:up/dn (move in local yz plane)
1192
    // lmb&rmb: x:strafe y:up/dn (move in local yz plane)
1202
    // mmb: fwd/back in viewing vector
1193
    // mmb: fwd/back in viewing vector
1203
1194
1204
    if (unrealedlook && !mskip)    //PK
1195
    if (unrealedlook && !mskip)    //PK
1205
    {
1196
    {
1206
        if ((bstatus&(1|2|4))==1)
1197
        if ((bstatus&(1|2|4))==1)
1207
        {
1198
        {
1208
            ang += mousx;
1199
            ang += mousx;
1209
            xvect = -((mousy*(int32_t)sintable[(ang+2560)&2047])<<(3+pk_uedaccel));
1200
            xvect = -((mousy*(int32_t)sintable[(ang+2560)&2047])<<(3+pk_uedaccel));
1210
            yvect = -((mousy*(int32_t)sintable[(ang+2048)&2047])<<(3+pk_uedaccel));
1201
            yvect = -((mousy*(int32_t)sintable[(ang+2048)&2047])<<(3+pk_uedaccel));
1211
1202
1212
            move_and_update(xvect, yvect, 0);
1203
            move_and_update(xvect, yvect, 0);
1213
        }
1204
        }
1214
        else if (!mlook && (bstatus&(1|2|4))==2)
1205
        else if (!mlook && (bstatus&(1|2|4))==2)
1215
        {
1206
        {
1216
            mlook=2;
1207
            mlook=2;
1217
        }
1208
        }
1218
        else if ((bstatus&(1|2|4))==(1|2))
1209
        else if ((bstatus&(1|2|4))==(1|2))
1219
        {
1210
        {
1220
            zmode = 2;
1211
            zmode = 2;
1221
            xvect = -((mousx*(int32_t)sintable[(ang+2048)&2047])<<pk_uedaccel);
1212
            xvect = -((mousx*(int32_t)sintable[(ang+2048)&2047])<<pk_uedaccel);
1222
            yvect = -((mousx*(int32_t)sintable[(ang+1536)&2047])<<pk_uedaccel);
1213
            yvect = -((mousx*(int32_t)sintable[(ang+1536)&2047])<<pk_uedaccel);
1223
            pos.z += mousy<<(4+pk_uedaccel);
1214
            pos.z += mousy<<(4+pk_uedaccel);
1224
1215
1225
            move_and_update(xvect, yvect, 0);
1216
            move_and_update(xvect, yvect, 0);
1226
        }
1217
        }
1227
        else if ((bstatus&(1|2|4))==4)
1218
        else if ((bstatus&(1|2|4))==4)
1228
        {
1219
        {
1229
            zmode = 2;
1220
            zmode = 2;
1230
1221
1231
            // horiz-100 of 200 is viewing at 326.4 build angle units (=atan(200/128)) upward
1222
            // horiz-100 of 200 is viewing at 326.4 build angle units (=atan(200/128)) upward
1232
            tempint = getangle(128, horiz-100);
1223
            tempint = getangle(128, horiz-100);
1233
1224
1234
            xvect = -((mousy*
1225
            xvect = -((mousy*
1235
                       ((int32_t)sintable[(ang+2560)&2047]>>6)*
1226
                       ((int32_t)sintable[(ang+2560)&2047]>>6)*
1236
                       ((int32_t)sintable[(tempint+512)&2047])>>6)
1227
                       ((int32_t)sintable[(tempint+512)&2047])>>6)
1237
                      <<pk_uedaccel);
1228
                      <<pk_uedaccel);
1238
            yvect = -((mousy*
1229
            yvect = -((mousy*
1239
                       ((int32_t)sintable[(ang+2048)&2047]>>6)*
1230
                       ((int32_t)sintable[(ang+2048)&2047]>>6)*
1240
                       ((int32_t)sintable[(tempint+512)&2047])>>6)
1231
                       ((int32_t)sintable[(tempint+512)&2047])>>6)
1241
                      <<pk_uedaccel);
1232
                      <<pk_uedaccel);
1242
1233
1243
            pos.z += mousy*(((int32_t)sintable[(tempint+2048)&2047])>>(10-pk_uedaccel));
1234
            pos.z += mousy*(((int32_t)sintable[(tempint+2048)&2047])>>(10-pk_uedaccel));
1244
1235
1245
            move_and_update(xvect, yvect, 2);
1236
            move_and_update(xvect, yvect, 2);
1246
        }
1237
        }
1247
    }
1238
    }
1248
1239
1249
    if (mskip)
1240
    if (mskip)
1250
    {
1241
    {
1251
        // mskip was set in astub.c to not trigger UEd mouse movements.
1242
        // mskip was set in astub.c to not trigger UEd mouse movements.
1252
        // Reset now.
1243
        // Reset now.
1253
        mskip = 0;
1244
        mskip = 0;
1254
    }
1245
    }
1255
    else
1246
    else
1256
    {
1247
    {
1257
        if (mlook && (unrealedlook==0 || (bstatus&(1|4))==0))
1248
        if (mlook && (unrealedlook==0 || (bstatus&(1|4))==0))
1258
        {
1249
        {
1259
            ang += mousx;
1250
            ang += mousx;
1260
            horiz -= mousy;
1251
            horiz -= mousy;
1261
1252
1262
            /*
1253
            /*
1263
            if (mousy && !(mousy/4))
1254
            if (mousy && !(mousy/4))
1264
                horiz--;
1255
                horiz--;
1265
            if (mousx && !(mousx/2))
1256
            if (mousx && !(mousx/2))
1266
                ang++;
1257
                ang++;
1267
            */
1258
            */
1268
1259
1269
            inpclamp(&horiz, -99, 299);
1260
            inpclamp(&horiz, -99, 299);
1270
1261
1271
            if (mlook == 1)
1262
            if (mlook == 1)
1272
            {
1263
            {
1273
                searchx = xdim>>1;
1264
                searchx = xdim>>1;
1274
                searchy = ydim>>1;
1265
                searchy = ydim>>1;
1275
            }
1266
            }
1276
            osearchx = searchx-mousx;
1267
            osearchx = searchx-mousx;
1277
            osearchy = searchy-mousy;
1268
            osearchy = searchy-mousy;
1278
1269
1279
            if (mousx || mousy)
1270
            if (mousx || mousy)
1280
            {
1271
            {
1281
                silentmessage("x:%d y:%d z:%d ang:%d horiz:%d", pos.x, pos.y, pos.z, ang, horiz);
1272
                silentmessage("x:%d y:%d z:%d ang:%d horiz:%d", pos.x, pos.y, pos.z, ang, horiz);
1282
                getmessagetimeoff = (int32_t) totalclock+30;
1273
                getmessagetimeoff = (int32_t) totalclock+30;
1283
            }
1274
            }
1284
        }
1275
        }
1285
        else if (unrealedlook==0 || (bstatus&(1|2|4))==0)
1276
        else if (unrealedlook==0 || (bstatus&(1|2|4))==0)
1286
        {
1277
        {
1287
            osearchx = searchx;
1278
            osearchx = searchx;
1288
            osearchy = searchy;
1279
            osearchy = searchy;
1289
            searchx += mousx;
1280
            searchx += mousx;
1290
            searchy += mousy;
1281
            searchy += mousy;
1291
1282
1292
            inpclamp(&searchx, 12, xdim-13);
1283
            inpclamp(&searchx, 12, xdim-13);
1293
            inpclamp(&searchy, 12, ydim-13);
1284
            inpclamp(&searchy, 12, ydim-13);
1294
        }
1285
        }
1295
    }
1286
    }
1296
1287
1297
//    showmouse();
1288
//    showmouse();
1298
1289
1299
    if (keystatus[sc_F9])  // F9
1290
    if (keystatus[sc_F9])  // F9
1300
    {
1291
    {
1301
        if (mhk)
1292
        if (mhk)
1302
        {
1293
        {
1303
            Bmemset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES);
1294
            Bmemset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES);
1304
            Bmemset(spritesmooth, 0, sizeof(spritesmooth_t) * (MAXSPRITES+MAXUNIQHUDID));
1295
            Bmemset(spritesmooth, 0, sizeof(spritesmooth_t) * (MAXSPRITES+MAXUNIQHUDID));
1305
            engineClearLightsFromMHK();
1296
            engineClearLightsFromMHK();
1306
            mhk = 0;
1297
            mhk = 0;
1307
            message("Maphacks disabled");
1298
            message("Maphacks disabled");
1308
        }
1299
        }
1309
        else
1300
        else
1310
        {
1301
        {
1311
            mhk = 1;
1302
            mhk = 1;
1312
            loadmhk(1);
1303
            loadmhk(1);
1313
        }
1304
        }
1314
1305
1315
        keystatus[sc_F9] = 0;
1306
        keystatus[sc_F9] = 0;
1316
    }
1307
    }
1317
1308
1318
    mainloop_move();
1309
    mainloop_move();
1319
1310
1320
    getzrange(&pos,cursectnum, &hiz,&hihit, &loz,&lohit, 128, (m32_clipping==1)?0:CLIPMASK0);
1311
    getzrange(&pos,cursectnum, &hiz,&hihit, &loz,&lohit, 128, (m32_clipping==1)?0:CLIPMASK0);
1321
/*
1312
/*
1322
{
1313
{
1323
    int32_t his = !(hihit&32768), los = !(lohit&32768);
1314
    int32_t his = !(hihit&32768), los = !(lohit&32768);
1324
    if (m32_numdebuglines<64)
1315
    if (m32_numdebuglines<64)
1325
        Bsprintf(m32_debugstr[m32_numdebuglines++], "s%d: cf[%s%d, %s%d] z(%d, %d)", cursectnum,
1316
        Bsprintf(m32_debugstr[m32_numdebuglines++], "s%d: cf[%s%d, %s%d] z(%d, %d)", cursectnum,
1326
                 his?"s":"w",hihit&16383, los?"s":"w",lohit&16383, hiz,loz);
1317
                 his?"s":"w",hihit&16383, los?"s":"w",lohit&16383, hiz,loz);
1327
}
1318
}
1328
*/
1319
*/
1329
    oposz = pos.z;
1320
    oposz = pos.z;
1330
    if (zmode == 0)
1321
    if (zmode == 0)
1331
    {
1322
    {
1332
        goalz = loz-(kensplayerheight<<8);  //playerheight pixels above floor
1323
        goalz = loz-(kensplayerheight<<8);  //playerheight pixels above floor
1333
        if (goalz < hiz+(16<<8))  //ceiling&floor too close
1324
        if (goalz < hiz+(16<<8))  //ceiling&floor too close
1334
            goalz = (loz+hiz)>>1;
1325
            goalz = (loz+hiz)>>1;
1335
        goalz += mousz;
1326
        goalz += mousz;
1336
1327
1337
        if (DOWN_BK(MOVEUP))  //A (stand high)
1328
        if (DOWN_BK(MOVEUP))  //A (stand high)
1338
        {
1329
        {
1339
            goalz -= (16<<8);
1330
            goalz -= (16<<8);
1340
            if (DOWN_BK(RUN))
1331
            if (DOWN_BK(RUN))
1341
                goalz -= (24<<8);
1332
                goalz -= (24<<8);
1342
        }
1333
        }
1343
        if (DOWN_BK(MOVEDOWN))  //Z (stand low)
1334
        if (DOWN_BK(MOVEDOWN))  //Z (stand low)
1344
        {
1335
        {
1345
            goalz += (12<<8);
1336
            goalz += (12<<8);
1346
            if (DOWN_BK(RUN))
1337
            if (DOWN_BK(RUN))
1347
                goalz += (12<<8);
1338
                goalz += (12<<8);
1348
        }
1339
        }
1349
1340
1350
        if (goalz != pos.z)
1341
        if (goalz != pos.z)
1351
        {
1342
        {
1352
            if (pos.z < goalz) hvel += 64;
1343
            if (pos.z < goalz) hvel += 64;
1353
            if (pos.z > goalz) hvel = ((goalz-pos.z)>>3);
1344
            if (pos.z > goalz) hvel = ((goalz-pos.z)>>3);
1354
1345
1355
            pos.z += hvel;
1346
            pos.z += hvel;
1356
            if (pos.z > loz-(4<<8)) pos.z = loz-(4<<8), hvel = 0;
1347
            if (pos.z > loz-(4<<8)) pos.z = loz-(4<<8), hvel = 0;
1357
            if (pos.z < hiz+(4<<8)) pos.z = hiz+(4<<8), hvel = 0;
1348
            if (pos.z < hiz+(4<<8)) pos.z = hiz+(4<<8), hvel = 0;
1358
        }
1349
        }
1359
    }
1350
    }
1360
    else
1351
    else
1361
    {
1352
    {
1362
        goalz = pos.z;
1353
        goalz = pos.z;
1363
        if (DOWN_BK(MOVEUP))  //A
1354
        if (DOWN_BK(MOVEUP))  //A
1364
        {
1355
        {
1365
            if (eitherALT)
1356
            if (eitherALT)
1366
            {
1357
            {
1367
                horiz = max(-100,horiz-((DOWN_BK(RUN)+1)*synctics*2));
1358
                horiz = max(-100,horiz-((DOWN_BK(RUN)+1)*synctics*2));
1368
            }
1359
            }
1369
            else
1360
            else
1370
            {
1361
            {
1371
                if (zmode != 1)
1362
                if (zmode != 1)
1372
                    goalz -= (8<<8);
1363
                    goalz -= (8<<8);
1373
                else
1364
                else
1374
                {
1365
                {
1375
                    zlock += (4<<8);
1366
                    zlock += (4<<8);
1376
                    DOWN_BK(MOVEUP) = 0;
1367
                    DOWN_BK(MOVEUP) = 0;
1377
                }
1368
                }
1378
            }
1369
            }
1379
        }
1370
        }
1380
        if (DOWN_BK(MOVEDOWN))  //Z (stand low)
1371
        if (DOWN_BK(MOVEDOWN))  //Z (stand low)
1381
        {
1372
        {
1382
            if (eitherALT)
1373
            if (eitherALT)
1383
            {
1374
            {
1384
                horiz = min(300,horiz+((DOWN_BK(RUN)+1)*synctics*2));
1375
                horiz = min(300,horiz+((DOWN_BK(RUN)+1)*synctics*2));
1385
            }
1376
            }
1386
            else
1377
            else
1387
            {
1378
            {
1388
                if (zmode != 1)
1379
                if (zmode != 1)
1389
                    goalz += (8<<8);
1380
                    goalz += (8<<8);
1390
                else if (zlock > 0)
1381
                else if (zlock > 0)
1391
                {
1382
                {
1392
                    zlock -= (4<<8);
1383
                    zlock -= (4<<8);
1393
                    DOWN_BK(MOVEDOWN) = 0;
1384
                    DOWN_BK(MOVEDOWN) = 0;
1394
                }
1385
                }
1395
            }
1386
            }
1396
        }
1387
        }
1397
1388
1398
        if (m32_clipping)
1389
        if (m32_clipping)
1399
            inpclamp(&goalz, hiz+(4<<8), loz-(4<<8));
1390
            inpclamp(&goalz, hiz+(4<<8), loz-(4<<8));
1400
1391
1401
        if (zmode == 1) goalz = loz-zlock;
1392
        if (zmode == 1) goalz = loz-zlock;
1402
        if (m32_clipping && (goalz < hiz+(4<<8)))
1393
        if (m32_clipping && (goalz < hiz+(4<<8)))
1403
            goalz = ((loz+hiz)>>1);  //ceiling&floor too close
1394
            goalz = ((loz+hiz)>>1);  //ceiling&floor too close
1404
        if (zmode == 1) pos.z = goalz;
1395
        if (zmode == 1) pos.z = goalz;
1405
1396
1406
        if (goalz != pos.z)
1397
        if (goalz != pos.z)
1407
        {
1398
        {
1408
            //if (pos.z < goalz) hvel += (32<<DOWN_BK(RUN));
1399
            //if (pos.z < goalz) hvel += (32<<DOWN_BK(RUN));
1409
            //if (pos.z > goalz) hvel -= (32<<DOWN_BK(RUN));
1400
            //if (pos.z > goalz) hvel -= (32<<DOWN_BK(RUN));
1410
            if (pos.z < goalz)
1401
            if (pos.z < goalz)
1411
                hvel = ((192*synctics)<<DOWN_BK(RUN));
1402
                hvel = ((192*synctics)<<DOWN_BK(RUN));
1412
            else
1403
            else
1413
                hvel = -((192*synctics)<<DOWN_BK(RUN));
1404
                hvel = -((192*synctics)<<DOWN_BK(RUN));
1414
1405
1415
            pos.z += hvel;
1406
            pos.z += hvel;
1416
1407
1417
            if (m32_clipping)
1408
            if (m32_clipping)
1418
            {
1409
            {
1419
                if (pos.z > loz-(4<<8)) pos.z = loz-(4<<8), hvel = 0;
1410
                if (pos.z > loz-(4<<8)) pos.z = loz-(4<<8), hvel = 0;
1420
                if (pos.z < hiz+(4<<8)) pos.z = hiz+(4<<8), hvel = 0;
1411
                if (pos.z < hiz+(4<<8)) pos.z = hiz+(4<<8), hvel = 0;
1421
            }
1412
            }
1422
        }
1413
        }
1423
        else
1414
        else
1424
            hvel = 0;
1415
            hvel = 0;
1425
    }
1416
    }
1426
1417
1427
    {
1418
    {
1428
        int16_t ocursectnum = cursectnum;
1419
        int16_t ocursectnum = cursectnum;
1429
        updatesectorz(pos.x,pos.y,pos.z, &cursectnum);
1420
        updatesectorz(pos.x,pos.y,pos.z, &cursectnum);
1430
        if (cursectnum<0)
1421
        if (cursectnum<0)
1431
        {
1422
        {
1432
            if (zmode != 2)
1423
            if (zmode != 2)
1433
                pos.z = oposz;  // don't allow to fall into infinity when in void space
1424
                pos.z = oposz;  // don't allow to fall into infinity when in void space
1434
            cursectnum = ocursectnum;
1425
            cursectnum = ocursectnum;
1435
        }
1426
        }
1436
    }
1427
    }
1437
1428
1438
    if (pos.z != oposz && in3dmode())
1429
    if (pos.z != oposz && in3dmode())
1439
    {
1430
    {
1440
        silentmessage("x:%d y:%d z:%d ang:%d horiz:%d", pos.x, pos.y, pos.z, ang, horiz);
1431
        silentmessage("x:%d y:%d z:%d ang:%d horiz:%d", pos.x, pos.y, pos.z, ang, horiz);
1441
        getmessagetimeoff = (int32_t) totalclock+30;
1432
        getmessagetimeoff = (int32_t) totalclock+30;
1442
    }
1433
    }
1443
1434
1444
    searchit = 2;
1435
    searchit = 2;
1445
    if (searchstat >= 0)
1436
    if (searchstat >= 0)
1446
    {
1437
    {
1447
        if ((bstatus&(1|2|4)) || keystatus[sc_Space])  // SPACE
1438
        if ((bstatus&(1|2|4)) || keystatus[sc_Space])  // SPACE
1448
            searchit = 0;
1439
            searchit = 0;
1449
1440
1450
        if (keystatus[sc_S])  //S (insert sprite) (3D)
1441
        if (keystatus[sc_S])  //S (insert sprite) (3D)
1451
        {
1442
        {
1452
            hitdata_t hit;
1443
            hitdata_t hit;
1453
            vec2_t osearch = {searchx, searchy};
1444
            vec2_t osearch = {searchx, searchy};
1454
            vec2_t bdim = {xdim, ydim};
1445
            vec2_t bdim = {xdim, ydim};
1455
            if (m32_is2d3dmode())
1446
            if (m32_is2d3dmode())
1456
            {
1447
            {
1457
                xdim = XSIZE_2D3D;
1448
                xdim = XSIZE_2D3D;
1458
                ydim = YSIZE_2D3D;
1449
                ydim = YSIZE_2D3D;
1459
                searchx -= m32_2d3d.x;
1450
                searchx -= m32_2d3d.x;
1460
                searchy -= m32_2d3d.y;
1451
                searchy -= m32_2d3d.y;
1461
            }
1452
            }
1462
1453
1463
            vec2_t da = { 16384, divscale14(searchx-(xdim>>1), xdim>>1) };
1454
            vec2_t da = { 16384, divscale14(searchx-(xdim>>1), xdim>>1) };
1464
1455
1465
            rotatepoint(zerovec, da, ang, &da);
1456
            rotatepoint(zerovec, da, ang, &da);
1466
1457
1467
#ifdef USE_OPENGL
1458
#ifdef USE_OPENGL
1468
            if (videoGetRenderMode() == REND_POLYMOST)
1459
            if (videoGetRenderMode() == REND_POLYMOST)
1469
                hit = polymost_hitdata;
1460
                hit = polymost_hitdata;
1470
            else
1461
            else
1471
#endif
1462
#endif
1472
                hitscan((const vec3_t *)&pos,cursectnum,              //Start position
1463
                hitscan((const vec3_t *)&pos,cursectnum,              //Start position
1473
                    da.x,da.y,(scale(searchy,200,ydim)-horiz)*2000, //vector of 3D ang
1464
                    da.x,da.y,(scale(searchy,200,ydim)-horiz)*2000, //vector of 3D ang
1474
                    &hit,CLIPMASK1);
1465
                    &hit,CLIPMASK1);
1475
1466
1476
            if (hit.sect >= 0)
1467
            if (hit.sect >= 0)
1477
            {
1468
            {
1478
                da.x = hit.pos.x;
1469
                da.x = hit.pos.x;
1479
                da.y = hit.pos.y;
1470
                da.y = hit.pos.y;
1480
                if (gridlock && grid > 0)
1471
                if (gridlock && grid > 0)
1481
                {
1472
                {
1482
                    if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
1473
                    if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
1483
                        hit.pos.z &= 0xfffffc00;
1474
                        hit.pos.z &= 0xfffffc00;
1484
                    else
1475
                    else
1485
                        locktogrid(&da.x, &da.y);
1476
                        locktogrid(&da.x, &da.y);
1486
                }
1477
                }
1487
1478
1488
                i = insert_sprite_common(hit.sect, da.x, da.y);
1479
                i = insert_sprite_common(hit.sect, da.x, da.y);
1489
1480
1490
                if (i < 0)
1481
                if (i < 0)
1491
                    message("Couldn't insert sprite.");
1482
                    message("Couldn't insert sprite.");
1492
                else
1483
                else
1493
                {
1484
                {
1494
                    int32_t cz, fz;
1485
                    int32_t cz, fz;
1495
1486
1496
                    handle_sprite_in_clipboard(i);
1487
                    handle_sprite_in_clipboard(i);
1497
1488
1498
                    spriteoncfz(i, &cz, &fz);
1489
                    spriteoncfz(i, &cz, &fz);
1499
                    sprite[i].z = clamp2(hit.pos.z, cz, fz);
1490
                    sprite[i].z = clamp2(hit.pos.z, cz, fz);
1500
1491
1501
                    if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
1492
                    if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
1502
                    {
1493
                    {
1503
                        sprite[i].cstat &= ~48;
1494
                        sprite[i].cstat &= ~48;
1504
                        sprite[i].cstat |= (16+64);
1495
                        sprite[i].cstat |= (16+64);
1505
1496
1506
                        correct_ornamented_sprite(i, hit.wall);
1497
                        correct_ornamented_sprite(i, hit.wall);
1507
                    }
1498
                    }
1508
                    else
1499
                    else
1509
                        sprite[i].cstat |= (tilesiz[sprite[i].picnum].y>=32);
1500
                        sprite[i].cstat |= (tilesiz[sprite[i].picnum].y>=32);
1510
1501
1511
                    correct_sprite_yoffset(i);
1502
                    correct_sprite_yoffset(i);
1512
1503
1513
                    asksave = 1;
1504
                    asksave = 1;
1514
1505
1515
                    VM_OnEvent(EVENT_INSERTSPRITE3D, i);
1506
                    VM_OnEvent(EVENT_INSERTSPRITE3D, i);
1516
                }
1507
                }
1517
            }
1508
            }
1518
1509
1519
            xdim = bdim.x;
1510
            xdim = bdim.x;
1520
            ydim = bdim.y;
1511
            ydim = bdim.y;
1521
            searchx = osearch.x;
1512
            searchx = osearch.x;
1522
            searchy = osearch.y;
1513
            searchy = osearch.y;
1523
            keystatus[sc_S] = 0;
1514
            keystatus[sc_S] = 0;
1524
        }
1515
        }
1525
1516
1526
        if (keystatus[sc_F5]||keystatus[sc_F6])  //F5,F6
1517
        if (keystatus[sc_F5]||keystatus[sc_F6])  //F5,F6
1527
        {
1518
        {
1528
            switch (searchstat)
1519
            switch (searchstat)
1529
            {
1520
            {
1530
            case SEARCH_CEILING:
1521
            case SEARCH_CEILING:
1531
            case SEARCH_FLOOR:
1522
            case SEARCH_FLOOR:
1532
                CallExtShowSectorData(searchsector); break;
1523
                CallExtShowSectorData(searchsector); break;
1533
            case SEARCH_WALL:
1524
            case SEARCH_WALL:
1534
            case SEARCH_MASKWALL:
1525
            case SEARCH_MASKWALL:
1535
                CallExtShowWallData(searchwall); break;
1526
                CallExtShowWallData(searchwall); break;
1536
            case SEARCH_SPRITE:
1527
            case SEARCH_SPRITE:
1537
                CallExtShowSpriteData(searchwall); break;
1528
                CallExtShowSpriteData(searchwall); break;
1538
            }
1529
            }
1539
1530
1540
            keystatus[sc_F5] = keystatus[sc_F6] = 0;
1531
            keystatus[sc_F5] = keystatus[sc_F6] = 0;
1541
        }
1532
        }
1542
        if (keystatus[sc_F7]||keystatus[sc_F8])  //F7,F8
1533
        if (keystatus[sc_F7]||keystatus[sc_F8])  //F7,F8
1543
        {
1534
        {
1544
            switch (searchstat)
1535
            switch (searchstat)
1545
            {
1536
            {
1546
            case SEARCH_CEILING:
1537
            case SEARCH_CEILING:
1547
            case SEARCH_FLOOR:
1538
            case SEARCH_FLOOR:
1548
                CallExtEditSectorData(searchsector); break;
1539
                CallExtEditSectorData(searchsector); break;
1549
            case SEARCH_WALL:
1540
            case SEARCH_WALL:
1550
            case SEARCH_MASKWALL:
1541
            case SEARCH_MASKWALL:
1551
                CallExtEditWallData(searchwall); break;
1542
                CallExtEditWallData(searchwall); break;
1552
            case SEARCH_SPRITE:
1543
            case SEARCH_SPRITE:
1553
                CallExtEditSpriteData(searchwall); break;
1544
                CallExtEditSpriteData(searchwall); break;
1554
            }
1545
            }
1555
1546
1556
            keystatus[sc_F7] = keystatus[sc_F8] = 0;
1547
            keystatus[sc_F7] = keystatus[sc_F8] = 0;
1557
        }
1548
        }
1558
1549
1559
    }
1550
    }
1560
1551
1561
    if (keystatus[buildkeys[BK_MODE2D_3D]] && !m32_is2d3dmode())  // Enter
1552
    if (keystatus[buildkeys[BK_MODE2D_3D]] && !m32_is2d3dmode())  // Enter
1562
    {
1553
    {
1563
1554
1564
        vid_gamma_3d = g_videoGamma;
1555
        vid_gamma_3d = g_videoGamma;
1565
        vid_contrast_3d = g_videoContrast;
1556
        vid_contrast_3d = g_videoContrast;
1566
        vid_brightness_3d = g_videoBrightness;
1557
        vid_brightness_3d = g_videoBrightness;
1567
1558
1568
        g_videoGamma = g_videoContrast = 1.0;
1559
        g_videoGamma = g_videoContrast = 1.0;
1569
        g_videoBrightness = 0.0;
1560
        g_videoBrightness = 0.0;
1570
1561
1571
        videoSetPalette(0,0,0);
1562
        videoSetPalette(0,0,0);
1572
1563
1573
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
1564
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
1574
        overheadeditor();
1565
        overheadeditor();
1575
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
1566
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
1576
1567
1577
        g_videoGamma = vid_gamma_3d;
1568
        g_videoGamma = vid_gamma_3d;
1578
        g_videoContrast = vid_contrast_3d;
1569
        g_videoContrast = vid_contrast_3d;
1579
        g_videoBrightness = vid_brightness_3d;
1570
        g_videoBrightness = vid_brightness_3d;
1580
1571
1581
        vid_gamma_3d = vid_contrast_3d = vid_brightness_3d = -1;
1572
        vid_gamma_3d = vid_contrast_3d = vid_brightness_3d = -1;
1582
1573
1583
        videoSetPalette(GAMMA_CALC,0,0);
1574
        videoSetPalette(GAMMA_CALC,0,0);
1584
    }
1575
    }
1585
}
1576
}
1586
1577
1587
char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck)
1578
char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck)
1588
{
1579
{
1589
    if (dadir < 0)
1580
    if (dadir < 0)
1590
    {
1581
    {
1591
        if ((dachar > 0) || (boundcheck == 0))
1582
        if ((dachar > 0) || (boundcheck == 0))
1592
        {
1583
        {
1593
            dachar--;
1584
            dachar--;
1594
            if (smooshyalign > 0)
1585
            if (smooshyalign > 0)
1595
                dachar = (dachar&0xf8);
1586
                dachar = (dachar&0xf8);
1596
        }
1587
        }
1597
    }
1588
    }
1598
    else if (dadir > 0)
1589
    else if (dadir > 0)
1599
    {
1590
    {
1600
        if ((dachar < 255) || (boundcheck == 0))
1591
        if ((dachar < 255) || (boundcheck == 0))
1601
        {
1592
        {
1602
            dachar++;
1593
            dachar++;
1603
            if (smooshyalign > 0)
1594
            if (smooshyalign > 0)
1604
            {
1595
            {
1605
                if (dachar >= 256-8) dachar = 255;
1596
                if (dachar >= 256-8) dachar = 255;
1606
                else dachar = ((dachar+7)&0xf8);
1597
                else dachar = ((dachar+7)&0xf8);
1607
            }
1598
            }
1608
        }
1599
        }
1609
    }
1600
    }
1610
    return dachar;
1601
    return dachar;
1611
}
1602
}
1612
1603
1613
1604
1614
////////////////////// OVERHEADEDITOR //////////////////////
1605
////////////////////// OVERHEADEDITOR //////////////////////
1615
1606
1616
// some 2d mode state
1607
// some 2d mode state
1617
static struct overheadstate
1608
static struct overheadstate
1618
{
1609
{
1619
    // number of backed up drawn walls
1610
    // number of backed up drawn walls
1620
    int32_t bak_wallsdrawn;
1611
    int32_t bak_wallsdrawn;
1621
1612
1622
    // state related to line drawing
1613
    // state related to line drawing
1623
    int16_t suckwall, split;
1614
    int16_t suckwall, split;
1624
    int16_t splitsect;
1615
    int16_t splitsect;
1625
    int16_t splitstartwall;
1616
    int16_t splitstartwall;
1626
} ovh;
1617
} ovh;
1627
1618
1628
1619
1629
static int32_t inside_editor(const vec3_t *pos, int32_t searchx, int32_t searchy, int32_t zoom,
1620
static int32_t inside_editor(const vec3_t *pos, int32_t searchx, int32_t searchy, int32_t zoom,
1630
                             int32_t x, int32_t y, int16_t sectnum)
1621
                             int32_t x, int32_t y, int16_t sectnum)
1631
{
1622
{
1632
    if (!m32_sideview)
1623
    if (!m32_sideview)
1633
        return inside(x, y, sectnum);
1624
        return inside(x, y, sectnum);
1634
1625
1635
    // if in side-view mode, use the screen coords instead
1626
    // if in side-view mode, use the screen coords instead
1636
    {
1627
    {
1637
        int32_t dst = MAXSECTORS+M32_FIXME_SECTORS-1, i, oi;
1628
        int32_t dst = MAXSECTORS+M32_FIXME_SECTORS-1, i, oi;
1638
        int32_t srcw=sector[sectnum].wallptr, dstw=MAXWALLS;
1629
        int32_t srcw=sector[sectnum].wallptr, dstw=MAXWALLS;
1639
        int32_t ret;
1630
        int32_t ret;
1640
1631
1641
        if (sector[sectnum].wallnum > M32_FIXME_WALLS)
1632
        if (sector[sectnum].wallnum > M32_FIXME_WALLS)
1642
            return -1;
1633
            return -1;
1643
1634
1644
        Bmemcpy(&sector[dst], &sector[sectnum], sizeof(sectortype));
1635
        Bmemcpy(&sector[dst], &sector[sectnum], sizeof(sectortype));
1645
        sector[dst].wallptr = dstw;
1636
        sector[dst].wallptr = dstw;
1646
1637
1647
        Bmemcpy(&wall[dstw], &wall[srcw], sector[dst].wallnum*sizeof(walltype));
1638
        Bmemcpy(&wall[dstw], &wall[srcw], sector[dst].wallnum*sizeof(walltype));
1648
        for (i=dstw, oi=srcw; i<dstw+sector[dst].wallnum; i++, oi++)
1639
        for (i=dstw, oi=srcw; i<dstw+sector[dst].wallnum; i++, oi++)
1649
        {
1640
        {
1650
            wall[i].point2 += dstw-srcw;
1641
            wall[i].point2 += dstw-srcw;
1651
1642
1652
            editorGet2dScreenCoordinates(&wall[i].x, &wall[i].y, wall[i].x-pos->x, wall[i].y-pos->y, zoom);
1643
            editorGet2dScreenCoordinates(&wall[i].x, &wall[i].y, wall[i].x-pos->x, wall[i].y-pos->y, zoom);
1653
            wall[i].y += getscreenvdisp(getflorzofslope(sectnum,wall[oi].x,wall[oi].y)-pos->z, zoom);
1644
            wall[i].y += getscreenvdisp(getflorzofslope(sectnum,wall[oi].x,wall[oi].y)-pos->z, zoom);
1654
            wall[i].x += halfxdim16;
1645
            wall[i].x += halfxdim16;
1655
            wall[i].y += midydim16;
1646
            wall[i].y += midydim16;
1656
        }
1647
        }
1657
1648
1658
        i = numsectors;
1649
        i = numsectors;
1659
        numsectors = dst+1;
1650
        numsectors = dst+1;
1660
        ret = inside(searchx, searchy, dst);
1651
        ret = inside(searchx, searchy, dst);
1661
        numsectors = i;
1652
        numsectors = i;
1662
        return ret;
1653
        return ret;
1663
    }
1654
    }
1664
}
1655
}
1665
1656
1666
int32_t inside_editor_curpos(int16_t sectnum)
1657
int32_t inside_editor_curpos(int16_t sectnum)
1667
{
1658
{
1668
    // TODO: take care: mous[xy]plc global vs overheadeditor auto
1659
    // TODO: take care: mous[xy]plc global vs overheadeditor auto
1669
    return inside_editor(&pos, searchx,searchy, zoom, mousxplc,mousyplc, sectnum);
1660
    return inside_editor(&pos, searchx,searchy, zoom, mousxplc,mousyplc, sectnum);
1670
}
1661
}
1671
1662
1672
1663
1673
static inline void drawline16base(int32_t bx, int32_t by, int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col)
1664
static inline void drawline16base(int32_t bx, int32_t by, int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col)
1674
{
1665
{
1675
    editorDraw2dLine(bx+x1, by+y1, bx+x2, by+y2, col);
1666
    editorDraw2dLine(bx+x1, by+y1, bx+x2, by+y2, col);
1676
}
1667
}
1677
1668
1678
void drawsmallabel(const char *text, char col, char backcol, char border, int32_t dax, int32_t day, int32_t daz)
1669
void drawsmallabel(const char *text, char col, char backcol, char border, int32_t dax, int32_t day, int32_t daz)
1679
{
1670
{
1680
    editorGet2dScreenCoordinates(&dax,&day, dax-pos.x,day-pos.y, zoom);
1671
    editorGet2dScreenCoordinates(&dax,&day, dax-pos.x,day-pos.y, zoom);
1681
1672
1682
    if (m32_sideview)
1673
    if (m32_sideview)
1683
        day += getscreenvdisp(daz-pos.z, zoom);
1674
        day += getscreenvdisp(daz-pos.z, zoom);
1684
1675
1685
    int32_t const x1 = halfxdim16+dax-(Bstrlen(text)<<1);
1676
    int32_t const x1 = halfxdim16+dax-(Bstrlen(text)<<1);
1686
    int32_t const y1 = midydim16+day-4;
1677
    int32_t const y1 = midydim16+day-4;
1687
    int32_t const x2 = x1 + (Bstrlen(text)<<2)+2;
1678
    int32_t const x2 = x1 + (Bstrlen(text)<<2)+2;
1688
    int32_t const y2 = y1 + 7;
1679
    int32_t const y2 = y1 + 7;
1689
1680
1690
    int f = mulscale8(x2-x1, zoom);
1681
    int f = mulscale8(x2-x1, zoom);
1691
1682
1692
    if ((x1 <= -f) || (x2 >= xdim + f) || (y1 <= -f) || (y2 >= ydim16 + f))
1683
    if ((x1 <= -f) || (x2 >= xdim + f) || (y1 <= -f) || (y2 >= ydim16 + f))
1693
        return;
1684
        return;
1694
1685
1695
    printext16(x1,y1, col,backcol, text,1);
1686
    printext16(x1,y1, col,backcol, text,1);
1696
1687
1697
    editorDraw2dLine(x1-2, y1-2, x2-2, y1-2, border);
1688
    editorDraw2dLine(x1-2, y1-2, x2-2, y1-2, border);
1698
    editorDraw2dLine(x1-2, y2+1, x2-2, y2+1, border);
1689
    editorDraw2dLine(x1-2, y2+1, x2-2, y2+1, border);
1699
1690
1700
    editorDraw2dLine(x1-3, y1-1, x1-3, y2+0, border);
1691
    editorDraw2dLine(x1-3, y1-1, x1-3, y2+0, border);
1701
    editorDraw2dLine(x2-1, y1-1, x2-1, y2+0, border);
1692
    editorDraw2dLine(x2-1, y1-1, x2-1, y2+0, border);
1702
1693
1703
    editorDraw2dLine(x1-1,y1-1, x2-3,y1-1, backcol);
1694
    editorDraw2dLine(x1-1,y1-1, x2-3,y1-1, backcol);
1704
    editorDraw2dLine(x1-1,y2+0, x2-3,y2+0, backcol);
1695
    editorDraw2dLine(x1-1,y2+0, x2-3,y2+0, backcol);
1705
1696
1706
    editorDraw2dLine(x1-2,y1+0, x1-2,y2-1, backcol);
1697
    editorDraw2dLine(x1-2,y1+0, x1-2,y2-1, backcol);
1707
    editorDraw2dLine(x2-2,y1+0, x2-2,y2-1, backcol);
1698
    editorDraw2dLine(x2-2,y1+0, x2-2,y2-1, backcol);
1708
    editorDraw2dLine(x2-3,y1+0, x2-3,y2+0, backcol);
1699
    editorDraw2dLine(x2-3,y1+0, x2-3,y2+0, backcol);
1709
1700
1710
    videoBeginDrawing(); //{{{
1701
    videoBeginDrawing(); //{{{
1711
1702
1712
    if ((unsigned)y1-1 < ydim16+0u && (unsigned) (x1-2) < xdim2d+0u && (unsigned) (x2-2) < xdim2d+0u)
1703
    if ((unsigned)y1-1 < ydim16+0u && (unsigned) (x1-2) < xdim2d+0u && (unsigned) (x2-2) < xdim2d+0u)
1713
    {
1704
    {
1714
        drawpixel((char *) (frameplace + ((y1-1) * bytesperline) + (x1-2)), border);
1705
        drawpixel((char *) (frameplace + ((y1-1) * bytesperline) + (x1-2)), border);
1715
        drawpixel((char *) (frameplace + ((y1-1) * bytesperline) + (x2-2)), border);
1706
        drawpixel((char *) (frameplace + ((y1-1) * bytesperline) + (x2-2)), border);
1716
    }
1707
    }
1717
1708
1718
    if ((unsigned) y2 < ydim16+0u && (unsigned) (x1-2) < xdim2d+0u && (unsigned) (x2-2) < xdim2d+0u)
1709
    if ((unsigned) y2 < ydim16+0u && (unsigned) (x1-2) < xdim2d+0u && (unsigned) (x2-2) < xdim2d+0u)
1719
    {
1710
    {
1720
        drawpixel((char *) (frameplace + ((y2) * bytesperline) + (x1-2)), border);
1711
        drawpixel((char *) (frameplace + ((y2) * bytesperline) + (x1-2)), border);
1721
        drawpixel((char *) (frameplace + ((y2) * bytesperline) + (x2-2)), border);
1712
        drawpixel((char *) (frameplace + ((y2) * bytesperline) + (x2-2)), border);
1722
    }
1713
    }
1723
1714
1724
    videoEndDrawing();
1715
    videoEndDrawing();
1725
}
1716
}
1726
1717
1727
// backup highlighted sectors with sprites as mapinfo for later restoration
1718
// backup highlighted sectors with sprites as mapinfo for later restoration
1728
// return values:
1719
// return values:
1729
//  -1: highlightsectorcnt<=0
1720
//  -1: highlightsectorcnt<=0
1730
//   0: ok
1721
//   0: ok
1731
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo)
1722
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo)
1732
{
1723
{
1733
    int32_t i, j, k, m, tmpnumwalls=0, tmpnumsprites=0;
1724
    int32_t i, j, k, m, tmpnumwalls=0, tmpnumsprites=0;
1734
    int16_t *const otonsect = (int16_t *)tempxyar;  // STRICTALIASING
1725
    int16_t *const otonsect = (int16_t *)tempxyar;  // STRICTALIASING
1735
    int16_t *const otonwall = ((int16_t *)tempxyar) + MAXWALLS;
1726
    int16_t *const otonwall = ((int16_t *)tempxyar) + MAXWALLS;
1736
#ifdef YAX_ENABLE
1727
#ifdef YAX_ENABLE
1737
    int16_t otonbunch[YAX_MAXBUNCHES];
1728
    int16_t otonbunch[YAX_MAXBUNCHES];
1738
    int16_t numsectsofbunch[YAX_MAXBUNCHES];  // ceilings + floors
1729
    int16_t numsectsofbunch[YAX_MAXBUNCHES];  // ceilings + floors
1739
#endif
1730
#endif
1740
1731
1741
    if (highlightsectorcnt <= 0)
1732
    if (highlightsectorcnt <= 0)
1742
        return -1;
1733
        return -1;
1743
1734
1744
#ifdef YAX_ENABLE
1735
#ifdef YAX_ENABLE
1745
    for (i=0; i<numyaxbunches; i++)
1736
    for (i=0; i<numyaxbunches; i++)
1746
        numsectsofbunch[i] = 0;
1737
        numsectsofbunch[i] = 0;
1747
#endif
1738
#endif
1748
1739
1749
    // set up old-->new mappings
1740
    // set up old-->new mappings
1750
    j = 0;
1741
    j = 0;
1751
    k = 0;
1742
    k = 0;
1752
    for (i=0; i<numsectors; i++)
1743
    for (i=0; i<numsectors; i++)
1753
    {
1744
    {
1754
        int32_t startwall, endwall;
1745
        int32_t startwall, endwall;
1755
1746
1756
        if (hlsectorbitmap[i>>3]&pow2char[i&7])
1747
        if (hlsectorbitmap[i>>3]&pow2char[i&7])
1757
        {
1748
        {
1758
#ifdef YAX_ENABLE
1749
#ifdef YAX_ENABLE
1759
            int16_t bn[2], cf;
1750
            int16_t bn[2], cf;
1760
1751
1761
            yax_getbunches(i, &bn[0], &bn[1]);
1752
            yax_getbunches(i, &bn[0], &bn[1]);
1762
            for (cf=0; cf<2; cf++)
1753
            for (cf=0; cf<2; cf++)
1763
                if (bn[cf] >= 0)
1754
                if (bn[cf] >= 0)
1764
                    numsectsofbunch[bn[cf]]++;
1755
                    numsectsofbunch[bn[cf]]++;
1765
#endif
1756
#endif
1766
            otonsect[i] = j++;
1757
            otonsect[i] = j++;
1767
1758
1768
            for (WALLS_OF_SECTOR(i, m))
1759
            for (WALLS_OF_SECTOR(i, m))
1769
                otonwall[m] = k++;
1760
                otonwall[m] = k++;
1770
        }
1761
        }
1771
        else
1762
        else
1772
        {
1763
        {
1773
            otonsect[i] = -1;
1764
            otonsect[i] = -1;
1774
1765
1775
            for (WALLS_OF_SECTOR(i, m))
1766
            for (WALLS_OF_SECTOR(i, m))
1776
                otonwall[m] = -1;
1767
                otonwall[m] = -1;
1777
        }
1768
        }
1778
    }
1769
    }
1779
1770
1780
#ifdef YAX_ENABLE
1771
#ifdef YAX_ENABLE
1781
    j = 0;
1772
    j = 0;
1782
    for (i=0; i<numyaxbunches; i++)
1773
    for (i=0; i<numyaxbunches; i++)
1783
    {
1774
    {
1784
        // only back up complete bunches
1775
        // only back up complete bunches
1785
        if (numsectsofbunch[i] == yax_numsectsinbunch(i, 0)+yax_numsectsinbunch(i, 1))
1776
        if (numsectsofbunch[i] == yax_numsectsinbunch(i, 0)+yax_numsectsinbunch(i, 1))
1786
            otonbunch[i] = j++;  // kept bunch
1777
            otonbunch[i] = j++;  // kept bunch
1787
        else
1778
        else
1788
            otonbunch[i] = -1;  // discarded bunch
1779
            otonbunch[i] = -1;  // discarded bunch
1789
    }
1780
    }
1790
    mapinfo->numyaxbunches = j;
1781
    mapinfo->numyaxbunches = j;
1791
#endif
1782
#endif
1792
1783
1793
    // count walls & sprites
1784
    // count walls & sprites
1794
    for (i=0; i<highlightsectorcnt; i++)
1785
    for (i=0; i<highlightsectorcnt; i++)
1795
    {
1786
    {
1796
        tmpnumwalls += sector[highlightsector[i]].wallnum;
1787
        tmpnumwalls += sector[highlightsector[i]].wallnum;
1797
1788
1798
        m = headspritesect[highlightsector[i]];
1789
        m = headspritesect[highlightsector[i]];
1799
        while (m != -1)
1790
        while (m != -1)
1800
        {
1791
        {
1801
            tmpnumsprites++;
1792
            tmpnumsprites++;
1802
            m = nextspritesect[m];
1793
            m = nextspritesect[m];
1803
        }
1794
        }
1804
    }
1795
    }
1805
1796
1806
    // allocate temp storage
1797
    // allocate temp storage
1807
    mapinfo->sector = (usectortype *)Xmalloc(highlightsectorcnt * sizeof(sectortype));
1798
    mapinfo->sector = (usectortype *)Xmalloc(highlightsectorcnt * sizeof(sectortype));
1808
    mapinfo->wall = (uwalltype *)Xmalloc(tmpnumwalls * sizeof(walltype));
1799
    mapinfo->wall = (uwalltype *)Xmalloc(tmpnumwalls * sizeof(walltype));
1809
1800
1810