Subversion Repositories eduke32

Rev

Rev 8490 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8490 Rev 8761
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
}
635
}
636
636
637
int app_main(int argc, char const * const * argv)
637
int app_main(int argc, char const * const * argv)
638
{
638
{
639
#ifdef STARTUP_SETUP_WINDOW
639
#ifdef STARTUP_SETUP_WINDOW
640
    char cmdsetup = 0;
640
    char cmdsetup = 0;
641
#endif
641
#endif
642
    char quitflag;
642
    char quitflag;
643
    int32_t i;
643
    int32_t i;
644
644
645
    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
646
646
647
#ifdef USE_OPENGL
647
#ifdef USE_OPENGL
648
    OSD_RegisterFunction("restartvid","restartvid: reinitialize the video mode",osdcmd_restartvid);
648
    OSD_RegisterFunction("restartvid","restartvid: reinitialize the video mode",osdcmd_restartvid);
649
    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);
650
    baselayer_osdcmd_vidmode_func = osdcmd_vidmode;
650
    baselayer_osdcmd_vidmode_func = osdcmd_vidmode;
651
#else
651
#else
652
    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);
653
#endif
653
#endif
654
654
655
    wm_setapptitle(AppProperName);
655
    wm_setapptitle(AppProperName);
656
656
657
    editstatus = 1;
657
    editstatus = 1;
658
658
659
    if ((i = CallExtPreInit(argc,argv)) < 0) return -1;
659
    if ((i = CallExtPreInit(argc,argv)) < 0) return -1;
660
660
661
#ifdef _WIN32
661
#ifdef _WIN32
662
    win_priorityclass = 1;
662
    win_priorityclass = 1;
663
#endif
663
#endif
664
664
665
    for (i=1; i<argc; i++)
665
    for (i=1; i<argc; i++)
666
    {
666
    {
667
        if (argv[i][0] == '-')
667
        if (argv[i][0] == '-')
668
        {
668
        {
669
#ifdef STARTUP_SETUP_WINDOW
669
#ifdef STARTUP_SETUP_WINDOW
670
            if (!Bstrcmp(argv[i], "-setup")) cmdsetup = 1;
670
            if (!Bstrcmp(argv[i], "-setup")) cmdsetup = 1;
671
            else
671
            else
672
#endif
672
#endif
673
            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], "-?"))
674
            {
674
            {
675
#ifdef WM_MSGBOX_WINDOW
675
#ifdef WM_MSGBOX_WINDOW
676
                wm_msgbox(AppProperName,
676
                wm_msgbox(AppProperName,
677
#else
677
#else
678
                Bprintf(
678
                Bprintf(
679
#endif
679
#endif
680
                    "%s\n"
680
                    "%s\n"
681
                    "Syntax: %s [options] mapname\n"
681
                    "Syntax: %s [options] mapname\n"
682
                    "Options:\n"
682
                    "Options:\n"
683
                    "\t-grp\tUse an extra GRP or ZIP file.\n"
683
                    "\t-grp\tUse an extra GRP or ZIP file.\n"
684
                    "\t-g\tSame as above.\n"
684
                    "\t-g\tSame as above.\n"
685
#ifdef STARTUP_SETUP_WINDOW
685
#ifdef STARTUP_SETUP_WINDOW
686
                    "\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"
687
#endif
687
#endif
688
                    , AppProperName, AppTechnicalName);
688
                    , AppProperName, AppTechnicalName);
689
                return 0;
689
                return 0;
690
            }
690
            }
691
            continue;
691
            continue;
692
        }
692
        }
693
    }
693
    }
694
694
695
    if (boardfilename[0] == 0)
695
    if (boardfilename[0] == 0)
696
        Bstrcpy(boardfilename,"newboard.map");
696
        Bstrcpy(boardfilename,"newboard.map");
697
    else if (Bstrchr(boardfilename,'.') == 0)
697
    else if (Bstrchr(boardfilename,'.') == 0)
698
        Bstrcat(boardfilename, ".map");
698
        Bstrcat(boardfilename, ".map");
699
    //Bcanonicalisefilename(boardfilename,0);
699
    //Bcanonicalisefilename(boardfilename,0);
700
700
701
    OSD_SetFunctions(
701
    OSD_SetFunctions(
702
        NULL, NULL, NULL, NULL, NULL,
702
        NULL, NULL, NULL, NULL, NULL,
703
        COMMON_clearbackground,
703
        COMMON_clearbackground,
704
        BGetTime,
704
        BGetTime,
705
        M32_OnShowOSD
705
        M32_OnShowOSD
706
    );
706
    );
707
707
708
    if (!buildvfs_getcwd(program_origcwd,BMAX_PATH))
708
    if (!buildvfs_getcwd(program_origcwd,BMAX_PATH))
709
        program_origcwd[0] = '\0';
709
        program_origcwd[0] = '\0';
710
710
711
    Bstrncpy(game_executable, DefaultGameLocalExec, sizeof(game_executable));
711
    Bstrncpy(game_executable, DefaultGameLocalExec, sizeof(game_executable));
712
712
713
    if (enginePreInit())
713
    if (enginePreInit())
714
        M32_FatalEngineError();
714
        M32_FatalEngineError();
715
715
716
    if ((i = CallExtInit()) < 0) return -1;
716
    if ((i = CallExtInit()) < 0) return -1;
717
717
718
#ifdef STARTUP_SETUP_WINDOW
718
#ifdef STARTUP_SETUP_WINDOW
719
    if (i || forcesetup || cmdsetup)
719
    if (i || forcesetup || cmdsetup)
720
    {
720
    {
721
        if (quitevent || !startwin_run())
721
        if (quitevent || !startwin_run())
722
        {
722
        {
723
            engineUnInit();
723
            engineUnInit();
724
            exit(EXIT_SUCCESS);
724
            exit(EXIT_SUCCESS);
725
        }
725
        }
726
    }
726
    }
727
#endif
727
#endif
728
728
729
    if (CallExtPostStartupWindow() < 0) return -1;
729
    if (CallExtPostStartupWindow() < 0) return -1;
730
730
731
    loadnames(g_namesFileName);
731
    loadnames(g_namesFileName);
732
732
733
    if (initinput()) return -1;
733
    if (initinput()) return -1;
734
734
735
    mouseInit();
735
    mouseInit();
736
736
737
    timerInit(CLOCKTICKSPERSECOND);
737
    timerInit(CLOCKTICKSPERSECOND);
738
    timerSetCallback(keytimerstuff);
738
    timerSetCallback(keytimerstuff);
739
739
740
    artLoadFiles("tiles000.art", g_maxCacheSize);
740
    artLoadFiles("tiles000.art", g_maxCacheSize);
741
741
742
    Bstrcpy(kensig,"Uses BUILD technology by Ken Silverman");
742
    Bstrcpy(kensig,"Uses BUILD technology by Ken Silverman");
743
    initcrc();
743
    initcrc();
744
744
745
    InitCustomColors();
745
    InitCustomColors();
746
746
747
    const char *defsfile = G_DefFile();
747
    const char *defsfile = G_DefFile();
748
748
749
    if (testkopen("editor.def", 0))
749
    if (testkopen("editor.def", 0))
750
        G_AddDefModule("editor.def");
750
        G_AddDefModule("editor.def");
751
751
752
    if (!loaddefinitionsfile(defsfile))
752
    if (!loaddefinitionsfile(defsfile))
753
        initprintf("Definitions file \"%s\" loaded.\n",defsfile);
753
        initprintf("Definitions file \"%s\" loaded.\n",defsfile);
754
754
755
    for (char * m : g_defModules)
755
    for (char * m : g_defModules)
756
        free(m);
756
        free(m);
757
    g_defModules.clear();
757
    g_defModules.clear();
758
758
759
    if (enginePostInit())
759
    if (enginePostInit())
760
        M32_FatalEngineError();
760
        M32_FatalEngineError();
761
761
762
    CallExtPostInit();
762
    CallExtPostInit();
763
763
764
#ifdef YAX_ENABLE
764
#ifdef YAX_ENABLE
765
    // init dummy texture for YAX
765
    // init dummy texture for YAX
766
    // must be after loadpics(), which inits BUILD's cache
766
    // must be after loadpics(), which inits BUILD's cache
767
767
768
    i = MAXTILES-1;
768
    i = MAXTILES-1;
769
    if (tilesiz[i].x==0 && tilesiz[i].y==0)
769
    if (tilesiz[i].x==0 && tilesiz[i].y==0)
770
    {
770
    {
771
        static char R[8*16] = { //
771
        static char R[8*16] = { //
772
            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,
773
            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,
774
            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,
775
            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,
776
            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,
777
            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,
778
            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,
779
        };
779
        };
780
780
781
        char *newtile;
781
        char *newtile;
782
        int32_t sx=32, sy=32, col, j;
782
        int32_t sx=32, sy=32, col, j;
783
783
784
        walock[i] = CACHE1D_PERMANENT;
784
        walock[i] = CACHE1D_PERMANENT;
785
        picsiz[i] = 5 + (5<<4);
785
        picsiz[i] = 5 + (5<<4);
786
        tilesiz[i].x = sx; tilesiz[i].y = sy;
786
        tilesiz[i].x = sx; tilesiz[i].y = sy;
787
        g_cache.allocateBlock(&waloff[i], sx*sy, &walock[i]);
787
        g_cache.allocateBlock(&waloff[i], sx*sy, &walock[i]);
788
        newtile = (char *)waloff[i];
788
        newtile = (char *)waloff[i];
789
789
790
        col = paletteGetClosestColor(128, 128, 0);
790
        col = paletteGetClosestColor(128, 128, 0);
791
        for (j=0; j<(signed)sizeof(R); j++)
791
        for (j=0; j<(signed)sizeof(R); j++)
792
            R[j] *= col;
792
            R[j] *= col;
793
793
794
        Bmemset(newtile, 0, sx*sy);
794
        Bmemset(newtile, 0, sx*sy);
795
        for (j=0; j<8; j++)
795
        for (j=0; j<8; j++)
796
            Bmemcpy(&newtile[32*j], &R[16*j], 16);
796
            Bmemcpy(&newtile[32*j], &R[16*j], 16);
797
    }
797
    }
798
#endif
798
#endif
799
799
800
#ifdef HAVE_CLIPSHAPE_FEATURE
800
#ifdef HAVE_CLIPSHAPE_FEATURE
801
    int k = engineLoadClipMaps();
801
    int k = engineLoadClipMaps();
802
    if (k>0)
802
    if (k>0)
803
        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);
804
804
805
    for (char * f : g_clipMapFiles)
805
    for (char * f : g_clipMapFiles)
806
        free(f);
806
        free(f);
807
    g_clipMapFiles.clear();
807
    g_clipMapFiles.clear();
808
#endif
808
#endif
809
809
810
    taglab_init();
810
    taglab_init();
811
811
812
    mkonwinvalid();
812
    mkonwinvalid();
813
813
814
    // executed once per init
814
    // executed once per init
815
    OSD_Exec("m32_autoexec.cfg");
815
    OSD_Exec("m32_autoexec.cfg");
816
816
817
    if (LoadBoard(boardfilename, 1))
817
    if (LoadBoard(boardfilename, 1))
818
        reset_default_mapstate();
818
        reset_default_mapstate();
819
819
820
    totalclock = 0;
820
    totalclock = 0;
821
821
822
    updatesector(pos.x,pos.y,&cursectnum);
822
    updatesector(pos.x,pos.y,&cursectnum);
823
823
824
    keySetCallback(&m32_keypresscallback);
824
    keySetCallback(&m32_keypresscallback);
825
    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
826
826
827
    if (cursectnum == -1)
827
    if (cursectnum == -1)
828
    {
828
    {
829
        vid_gamma_3d = g_videoGamma;
829
        vid_gamma_3d = g_videoGamma;
830
        vid_brightness_3d = g_videoBrightness;
830
        vid_brightness_3d = g_videoBrightness;
831
        vid_contrast_3d = g_videoContrast;
831
        vid_contrast_3d = g_videoContrast;
832
832
833
        g_videoGamma = g_videoContrast = 1.0;
833
        g_videoGamma = g_videoContrast = 1.0;
834
        g_videoBrightness = 0.0;
834
        g_videoBrightness = 0.0;
835
835
836
        videoSetPalette(0,0,0);
836
        videoSetPalette(0,0,0);
837
        if (videoSetGameMode(fullscreen, xdim2d, ydim2d, 8, upscalefactor) < 0)
837
        if (videoSetGameMode(fullscreen, xdim2d, ydim2d, 8, upscalefactor) < 0)
838
        {
838
        {
839
            CallExtUnInit();
839
            CallExtUnInit();
840
            engineUnInit();
840
            engineUnInit();
841
            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);
842
            Bexit(EXIT_SUCCESS);
842
            Bexit(EXIT_SUCCESS);
843
        }
843
        }
844
844
845
        system_getcvars();
845
        system_getcvars();
846
846
847
        overheadeditor();
847
        overheadeditor();
848
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
848
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
849
849
850
        g_videoGamma = vid_gamma_3d;
850
        g_videoGamma = vid_gamma_3d;
851
        g_videoContrast = vid_contrast_3d;
851
        g_videoContrast = vid_contrast_3d;
852
        g_videoBrightness = vid_brightness_3d;
852
        g_videoBrightness = vid_brightness_3d;
853
853
854
        vid_gamma_3d = vid_contrast_3d = vid_brightness_3d = -1;
854
        vid_gamma_3d = vid_contrast_3d = vid_brightness_3d = -1;
855
855
856
        videoSetPalette(GAMMA_CALC,0,0);
856
        videoSetPalette(GAMMA_CALC,0,0);
857
    }
857
    }
858
    else
858
    else
859
    {
859
    {
860
        if (videoSetGameMode(fullscreen, xdimgame, ydimgame, bppgame, upscalefactor) < 0)
860
        if (videoSetGameMode(fullscreen, xdimgame, ydimgame, bppgame, upscalefactor) < 0)
861
        {
861
        {
862
            CallExtUnInit();
862
            CallExtUnInit();
863
            engineUnInit();
863
            engineUnInit();
864
            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);
865
            Bexit(EXIT_SUCCESS);
865
            Bexit(EXIT_SUCCESS);
866
        }
866
        }
867
867
868
        system_getcvars();
868
        system_getcvars();
869
869
870
        videoSetPalette(GAMMA_CALC,0,0);
870
        videoSetPalette(GAMMA_CALC,0,0);
871
    }
871
    }
872
872
873
CANCEL:
873
CANCEL:
874
    quitflag = 0;
874
    quitflag = 0;
875
    while (quitflag == 0)
875
    while (quitflag == 0)
876
    {
876
    {
877
        if (handleevents())
877
        if (handleevents())
878
        {
878
        {
879
            if (quitevent)
879
            if (quitevent)
880
            {
880
            {
881
                keystatus[sc_Escape] = 1;
881
                keystatus[sc_Escape] = 1;
882
                quitevent = 0;
882
                quitevent = 0;
883
            }
883
            }
884
        }
884
        }
885
885
886
        OSD_DispatchQueued();
886
        OSD_DispatchQueued();
887
887
888
        videoNextPage();
888
        videoNextPage();
889
        synctics = (int32_t) totalclock-lockclock;
889
        synctics = (int32_t) totalclock-lockclock;
890
        lockclock += synctics;
890
        lockclock += synctics;
891
891
892
        CallExtPreCheckKeys();
892
        CallExtPreCheckKeys();
893
893
894
        M32_DrawRoomsAndMasks();
894
        M32_DrawRoomsAndMasks();
895
895
896
        inputchecked = 1;
896
        inputchecked = 1;
897
897
898
#ifdef M32_SHOWDEBUG
898
#ifdef M32_SHOWDEBUG
899
        if (searchstat>=0 && (searchwall<0 || searchsector<0))
899
        if (searchstat>=0 && (searchwall<0 || searchsector<0))
900
        {
900
        {
901
            if (m32_numdebuglines<64)
901
            if (m32_numdebuglines<64)
902
                Bsprintf(m32_debugstr[m32_numdebuglines++], "inconsistent search variables!");
902
                Bsprintf(m32_debugstr[m32_numdebuglines++], "inconsistent search variables!");
903
            searchstat = -1;
903
            searchstat = -1;
904
        }
904
        }
905
905
906
        M32_drawdebug();
906
        M32_drawdebug();
907
#endif
907
#endif
908
        CallExtCheckKeys();
908
        CallExtCheckKeys();
909
909
910
910
911
        if (keystatus[sc_Escape])
911
        if (keystatus[sc_Escape])
912
        {
912
        {
913
            keystatus[sc_Escape] = 0;
913
            keystatus[sc_Escape] = 0;
914
914
915
            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);
916
916
917
            videoShowFrame(1);
917
            videoShowFrame(1);
918
            synctics = (int32_t) totalclock-lockclock;
918
            synctics = (int32_t) totalclock-lockclock;
919
            lockclock += synctics;
919
            lockclock += synctics;
920
920
921
            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)
922
            {
922
            {
923
                idle_waitevent();
923
                idle_waitevent();
924
                if (handleevents())
924
                if (handleevents())
925
                {
925
                {
926
                    if (quitevent)
926
                    if (quitevent)
927
                    {
927
                    {
928
                        quitflag = 1;
928
                        quitflag = 1;
929
                        break;
929
                        break;
930
                    }
930
                    }
931
                }
931
                }
932
932
933
                if (keystatus[sc_Y]||keystatus[sc_Enter]) // Y or ENTER
933
                if (keystatus[sc_Y]||keystatus[sc_Enter]) // Y or ENTER
934
                {
934
                {
935
                    keystatus[sc_Y] = 0;
935
                    keystatus[sc_Y] = 0;
936
                    keystatus[sc_Enter] = 0;
936
                    keystatus[sc_Enter] = 0;
937
                    quitflag = 1; break;
937
                    quitflag = 1; break;
938
                }
938
                }
939
            }
939
            }
940
            while (keystatus[sc_Escape])
940
            while (keystatus[sc_Escape])
941
            {
941
            {
942
                keystatus[sc_Escape] = 0;
942
                keystatus[sc_Escape] = 0;
943
                quitevent = 0;
943
                quitevent = 0;
944
                goto CANCEL;
944
                goto CANCEL;
945
            }
945
            }
946
        }
946
        }
947
    }
947
    }
948
948
949
    if (asksave)
949
    if (asksave)
950
    {
950
    {
951
        i = CheckMapCorruption(4, 0);
951
        i = CheckMapCorruption(4, 0);
952
952
953
        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);
954
        videoShowFrame(1);
954
        videoShowFrame(1);
955
955
956
        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)
957
        {
957
        {
958
            idle_waitevent();
958
            idle_waitevent();
959
            if (handleevents()) { if (quitevent) break; } // like saying no
959
            if (handleevents()) { if (quitevent) break; } // like saying no
960
960
961
            if (keystatus[sc_Y] || keystatus[sc_Enter]) // Y or ENTER
961
            if (keystatus[sc_Y] || keystatus[sc_Enter]) // Y or ENTER
962
            {
962
            {
963
                keystatus[sc_Y] = keystatus[sc_Enter] = 0;
963
                keystatus[sc_Y] = keystatus[sc_Enter] = 0;
964
964
965
                SaveBoard(NULL, M32_SB_ASKOV);
965
                SaveBoard(NULL, M32_SB_ASKOV);
966
966
967
                break;
967
                break;
968
            }
968
            }
969
        }
969
        }
970
        while (keystatus[sc_Escape]||keystatus[sc_C])
970
        while (keystatus[sc_Escape]||keystatus[sc_C])
971
        {
971
        {
972
            keystatus[sc_Escape] = keystatus[sc_C] = 0;
972
            keystatus[sc_Escape] = keystatus[sc_C] = 0;
973
            quitevent = 0;
973
            quitevent = 0;
974
            goto CANCEL;
974
            goto CANCEL;
975
        }
975
        }
976
    }
976
    }
977
977
978
978
979
    CallExtUnInit();
979
    CallExtUnInit();
980
//    clearfilenames();
980
//    clearfilenames();
981
    engineUnInit();
981
    engineUnInit();
982
982
983
    return 0;
983
    return 0;
984
}
984
}
985
985
986
static int32_t mhk=0;
986
static int32_t mhk=0;
987
static void loadmhk(int32_t domessage)
987
static void loadmhk(int32_t domessage)
988
{
988
{
989
    char levname[BMAX_PATH];
989
    char levname[BMAX_PATH];
990
990
991
    if (!mhk)
991
    if (!mhk)
992
        return;
992
        return;
993
993
994
    Bstrcpy(levname, boardfilename);
994
    Bstrcpy(levname, boardfilename);
995
    append_ext_UNSAFE(levname, ".mhk");
995
    append_ext_UNSAFE(levname, ".mhk");
996
996
997
    if (!engineLoadMHK(levname))
997
    if (!engineLoadMHK(levname))
998
    {
998
    {
999
        if (domessage)
999
        if (domessage)
1000
            message("Loaded map hack file \"%s\"",levname);
1000
            message("Loaded map hack file \"%s\"",levname);
1001
        else
1001
        else
1002
            initprintf("Loaded map hack file \"%s\"\n",levname);
1002
            initprintf("Loaded map hack file \"%s\"\n",levname);
1003
    }
1003
    }
1004
    else
1004
    else
1005
    {
1005
    {
1006
        mhk=2;
1006
        mhk=2;
1007
        if (domessage)
1007
        if (domessage)
1008
            message("No maphack found for map \"%s\"",boardfilename);
1008
            message("No maphack found for map \"%s\"",boardfilename);
1009
    }
1009
    }
1010
}
1010
}
1011
1011
1012
// this is spriteon{ceiling,ground}z from astub.c packed into
1012
// this is spriteon{ceiling,ground}z from astub.c packed into
1013
// one convenient function
1013
// one convenient function
1014
void spriteoncfz(int32_t i, int32_t *czptr, int32_t *fzptr)
1014
void spriteoncfz(int32_t i, int32_t *czptr, int32_t *fzptr)
1015
{
1015
{
1016
    int32_t height, zofs;
1016
    int32_t height, zofs;
1017
1017
1018
    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);
1019
    if ((sprite[i].cstat&48)==32)
1019
    if ((sprite[i].cstat&48)==32)
1020
        return;
1020
        return;
1021
1021
1022
    zofs = spriteheightofs(i, &height, 0);
1022
    zofs = spriteheightofs(i, &height, 0);
1023
1023
1024
    *czptr += height - zofs;
1024
    *czptr += height - zofs;
1025
    *fzptr -= zofs;
1025
    *fzptr -= zofs;
1026
}
1026
}
1027
1027
1028
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)
1029
{
1029
{
1030
    if (m32_clipping==0)
1030
    if (m32_clipping==0)
1031
    {
1031
    {
1032
        pos.x += xvect>>(14+addshr);
1032
        pos.x += xvect>>(14+addshr);
1033
        pos.y += yvect>>(14+addshr);
1033
        pos.y += yvect>>(14+addshr);
1034
        updatesector(pos.x,pos.y, &cursectnum);
1034
        updatesector(pos.x,pos.y, &cursectnum);
1035
    }
1035
    }
1036
    else
1036
    else
1037
    {
1037
    {
1038
        clipmove(&pos,&cursectnum, xvect>>addshr,yvect>>addshr,
1038
        clipmove(&pos,&cursectnum, xvect>>addshr,yvect>>addshr,
1039
                 128,4<<8,4<<8, (m32_clipping==1) ? 0 : CLIPMASK0);
1039
                 128,4<<8,4<<8, (m32_clipping==1) ? 0 : CLIPMASK0);
1040
    }
1040
    }
1041
1041
1042
    if (in3dmode())
1042
    if (in3dmode())
1043
    {
1043
    {
1044
        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);
1045
        getmessagetimeoff = (int32_t) totalclock+30;
1045
        getmessagetimeoff = (int32_t) totalclock+30;
1046
    }
1046
    }
1047
}
1047
}
1048
1048
1049
static void mainloop_move(void)
1049
static void mainloop_move(void)
1050
{
1050
{
1051
    int32_t xvect, yvect, doubvel;
1051
    int32_t xvect, yvect, doubvel;
1052
1052
1053
    if (angvel != 0)  //ang += angvel * constant
1053
    if (angvel != 0)  //ang += angvel * constant
1054
    {
1054
    {
1055
        if (eitherCTRL && m32_2d3dmode)
1055
        if (eitherCTRL && m32_2d3dmode)
1056
        {
1056
        {
1057
            int x = m32_2d3d.x + (angvel / 32);
1057
            int x = m32_2d3d.x + (angvel / 32);
1058
            int xx = m32_2d3d.x + XSIZE_2D3D + (angvel / 32);
1058
            int xx = m32_2d3d.x + XSIZE_2D3D + (angvel / 32);
1059
1059
1060
            if (x > 4 && xx < xdim2d - 4)
1060
            if (x > 4 && xx < xdim2d - 4)
1061
            {
1061
            {
1062
                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);
1063
                m32_2d3d.x += (angvel / 32);
1063
                m32_2d3d.x += (angvel / 32);
1064
            }
1064
            }
1065
        }
1065
        }
1066
        else
1066
        else
1067
        {
1067
        {
1068
            //ENGINE calculates angvel for you
1068
            //ENGINE calculates angvel for you
1069
1069
1070
            //Lt. shift makes turn velocity 50% faster
1070
            //Lt. shift makes turn velocity 50% faster
1071
            doubvel = (synctics + DOWN_BK(RUN)*(synctics>>1));
1071
            doubvel = (synctics + DOWN_BK(RUN)*(synctics>>1));
1072
1072
1073
            ang += ((angvel*doubvel)>>4);
1073
            ang += ((angvel*doubvel)>>4);
1074
            ang &= 2047;
1074
            ang &= 2047;
1075
1075
1076
            if (in3dmode())
1076
            if (in3dmode())
1077
            {
1077
            {
1078
                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);
1079
                getmessagetimeoff = (int32_t) totalclock+30;
1079
                getmessagetimeoff = (int32_t) totalclock+30;
1080
            }
1080
            }
1081
        }
1081
        }
1082
    }
1082
    }
1083
    if ((vel|svel) != 0)
1083
    if ((vel|svel) != 0)
1084
    {
1084
    {
1085
        if (eitherCTRL && m32_2d3dmode)
1085
        if (eitherCTRL && m32_2d3dmode)
1086
        {
1086
        {
1087
            int y = m32_2d3d.y - (vel / 64);
1087
            int y = m32_2d3d.y - (vel / 64);
1088
            int yy = m32_2d3d.y + YSIZE_2D3D - (vel / 64);
1088
            int yy = m32_2d3d.y + YSIZE_2D3D - (vel / 64);
1089
1089
1090
            if (y > 4 && yy < ydim2d - STATUS2DSIZ2 - 4)
1090
            if (y > 4 && yy < ydim2d - STATUS2DSIZ2 - 4)
1091
            {
1091
            {
1092
                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);
1093
                m32_2d3d.y -= (vel / 64);
1093
                m32_2d3d.y -= (vel / 64);
1094
            }
1094
            }
1095
        }
1095
        }
1096
        else
1096
        else
1097
1097
1098
        {
1098
        {
1099
            //Lt. shift doubles forward velocity
1099
            //Lt. shift doubles forward velocity
1100
            doubvel = (1+(DOWN_BK(RUN)))*synctics;
1100
            doubvel = (1+(DOWN_BK(RUN)))*synctics;
1101
1101
1102
            xvect = 0;
1102
            xvect = 0;
1103
            yvect = 0;
1103
            yvect = 0;
1104
1104
1105
            if (vel != 0)
1105
            if (vel != 0)
1106
            {
1106
            {
1107
                xvect += ((vel*doubvel)>>3)*(int32_t) sintable[(ang+2560)&2047];
1107
                xvect += ((vel*doubvel)>>3)*(int32_t) sintable[(ang+2560)&2047];
1108
                yvect += ((vel*doubvel)>>3)*(int32_t) sintable[(ang+2048)&2047];
1108
                yvect += ((vel*doubvel)>>3)*(int32_t) sintable[(ang+2048)&2047];
1109
            }
1109
            }
1110
            if (svel != 0)
1110
            if (svel != 0)
1111
            {
1111
            {
1112
                xvect += ((svel*doubvel)>>3)*(int32_t) sintable[(ang+2048)&2047];
1112
                xvect += ((svel*doubvel)>>3)*(int32_t) sintable[(ang+2048)&2047];
1113
                yvect += ((svel*doubvel)>>3)*(int32_t) sintable[(ang+1536)&2047];
1113
                yvect += ((svel*doubvel)>>3)*(int32_t) sintable[(ang+1536)&2047];
1114
            }
1114
            }
1115
1115
1116
            move_and_update(xvect, yvect, 0);
1116
            move_and_update(xvect, yvect, 0);
1117
        }
1117
        }
1118
    }
1118
    }
1119
}
1119
}
1120
1120
1121
static void handle_sprite_in_clipboard(int32_t i)
1121
static void handle_sprite_in_clipboard(int32_t i)
1122
{
1122
{
1123
    if (somethingintab == 3)
1123
    if (somethingintab == 3)
1124
    {
1124
    {
1125
        int32_t j, k;
1125
        int32_t j, k;
1126
1126
1127
        sprite[i].picnum = temppicnum;
1127
        sprite[i].picnum = temppicnum;
1128
        if (tilesiz[temppicnum].x <= 0 || tilesiz[temppicnum].y <= 0)
1128
        if (tilesiz[temppicnum].x <= 0 || tilesiz[temppicnum].y <= 0)
1129
        {
1129
        {
1130
            j = 0;
1130
            j = 0;
1131
            for (k=0; k<MAXTILES; k++)
1131
            for (k=0; k<MAXTILES; k++)
1132
                if (tilesiz[k].x > 0 && tilesiz[k].y > 0)
1132
                if (tilesiz[k].x > 0 && tilesiz[k].y > 0)
1133
                {
1133
                {
1134
                    j = k;
1134
                    j = k;
1135
                    break;
1135
                    break;
1136
                }
1136
                }
1137
            sprite[i].picnum = j;
1137
            sprite[i].picnum = j;
1138
        }
1138
        }
1139
        sprite[i].shade = tempshade;
1139
        sprite[i].shade = tempshade;
1140
        sprite[i].blend = tempblend;
1140
        sprite[i].blend = tempblend;
1141
        sprite[i].pal = temppal;
1141
        sprite[i].pal = temppal;
1142
        sprite[i].xrepeat = max(tempxrepeat, 1u);
1142
        sprite[i].xrepeat = max(tempxrepeat, 1u);
1143
        sprite[i].yrepeat = max(tempyrepeat, 1u);
1143
        sprite[i].yrepeat = max(tempyrepeat, 1u);
1144
        sprite[i].cstat = tempcstat;
1144
        sprite[i].cstat = tempcstat;
1145
    }
1145
    }
1146
}
1146
}
1147
1147
1148
1148
1149
void editinput(void)
1149
void editinput(void)
1150
{
1150
{
1151
    int32_t mousz, bstatus;
1151
    int32_t mousz, bstatus;
1152
    int32_t i, tempint=0;
1152
    int32_t i, tempint=0;
1153
    int32_t goalz, xvect, yvect, hiz, loz, oposz;
1153
    int32_t goalz, xvect, yvect, hiz, loz, oposz;
1154
    int32_t hihit, lohit, omlook=mlook;
1154
    int32_t hihit, lohit, omlook=mlook;
1155
1155
1156
// 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
1157
// 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
1158
1158
1159
    mousz = 0;
1159
    mousz = 0;
1160
    mouseGetValues(&mousx,&mousy,&bstatus);
1160
    mouseGetValues(&mousx,&mousy,&bstatus);
1161
    mousx = (mousx<<16) + mousexsurp;
1161
    mousx = (mousx<<16) + mousexsurp;
1162
    mousy = (mousy<<16) + mouseysurp;
1162
    mousy = (mousy<<16) + mouseysurp;
1163
1163
1164
    if (unrealedlook && !mskip)
1164
    if (unrealedlook && !mskip)
1165
    {
1165
    {
1166
        if (mlook==0 && (bstatus&(1|2|4))==2)
1166
        if (mlook==0 && (bstatus&(1|2|4))==2)
1167
            mlook = 3;
1167
            mlook = 3;
1168
        else if ((bstatus&(1|2|4))==1)
1168
        else if ((bstatus&(1|2|4))==1)
1169
            mlook = 3;
1169
            mlook = 3;
1170
    }
1170
    }
1171
1171
1172
    {
1172
    {
1173
        ldiv_t ld;
1173
        ldiv_t ld;
1174
        if (mlook)
1174
        if (mlook)
1175
        {
1175
        {
1176
            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;
1177
            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;
1178
        }
1178
        }
1179
        else
1179
        else
1180
        {
1180
        {
1181
            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;
1182
            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;
1183
        }
1183
        }
1184
    }
1184
    }
1185
1185
1186
    if (mlook == 3)
1186
    if (mlook == 3)
1187
        mlook = omlook;
1187
        mlook = omlook;
1188
1188
1189
    // UnrealEd:
1189
    // UnrealEd:
1190
    // rmb: mouselook
1190
    // rmb: mouselook
1191
    // lbm: x:turn y:fwd/back local x
1191
    // lbm: x:turn y:fwd/back local x
1192
    // 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)
1193
    // mmb: fwd/back in viewing vector
1193
    // mmb: fwd/back in viewing vector
1194
1194
1195
    if (unrealedlook && !mskip)    //PK
1195
    if (unrealedlook && !mskip)    //PK
1196
    {
1196
    {
1197
        if ((bstatus&(1|2|4))==1)
1197
        if ((bstatus&(1|2|4))==1)
1198
        {
1198
        {
1199
            ang += mousx;
1199
            ang += mousx;
1200
            xvect = -((mousy*(int32_t)sintable[(ang+2560)&2047])<<(3+pk_uedaccel));
1200
            xvect = -((mousy*(int32_t)sintable[(ang+2560)&2047])<<(3+pk_uedaccel));
1201
            yvect = -((mousy*(int32_t)sintable[(ang+2048)&2047])<<(3+pk_uedaccel));
1201
            yvect = -((mousy*(int32_t)sintable[(ang+2048)&2047])<<(3+pk_uedaccel));
1202
1202
1203
            move_and_update(xvect, yvect, 0);
1203
            move_and_update(xvect, yvect, 0);
1204
        }
1204
        }
1205
        else if (!mlook && (bstatus&(1|2|4))==2)
1205
        else if (!mlook && (bstatus&(1|2|4))==2)
1206
        {
1206
        {
1207
            mlook=2;
1207
            mlook=2;
1208
        }
1208
        }
1209
        else if ((bstatus&(1|2|4))==(1|2))
1209
        else if ((bstatus&(1|2|4))==(1|2))
1210
        {
1210
        {
1211
            zmode = 2;
1211
            zmode = 2;
1212
            xvect = -((mousx*(int32_t)sintable[(ang+2048)&2047])<<pk_uedaccel);
1212
            xvect = -((mousx*(int32_t)sintable[(ang+2048)&2047])<<pk_uedaccel);
1213
            yvect = -((mousx*(int32_t)sintable[(ang+1536)&2047])<<pk_uedaccel);
1213
            yvect = -((mousx*(int32_t)sintable[(ang+1536)&2047])<<pk_uedaccel);
1214
            pos.z += mousy<<(4+pk_uedaccel);
1214
            pos.z += mousy<<(4+pk_uedaccel);
1215
1215
1216
            move_and_update(xvect, yvect, 0);
1216
            move_and_update(xvect, yvect, 0);
1217
        }
1217
        }
1218
        else if ((bstatus&(1|2|4))==4)
1218
        else if ((bstatus&(1|2|4))==4)
1219
        {
1219
        {
1220
            zmode = 2;
1220
            zmode = 2;
1221
1221
1222
            // 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
1223
            tempint = getangle(128, horiz-100);
1223
            tempint = getangle(128, horiz-100);
1224
1224
1225
            xvect = -((mousy*
1225
            xvect = -((mousy*
1226
                       ((int32_t)sintable[(ang+2560)&2047]>>6)*
1226
                       ((int32_t)sintable[(ang+2560)&2047]>>6)*
1227
                       ((int32_t)sintable[(tempint+512)&2047])>>6)
1227
                       ((int32_t)sintable[(tempint+512)&2047])>>6)
1228
                      <<pk_uedaccel);
1228
                      <<pk_uedaccel);
1229
            yvect = -((mousy*
1229
            yvect = -((mousy*
1230
                       ((int32_t)sintable[(ang+2048)&2047]>>6)*
1230
                       ((int32_t)sintable[(ang+2048)&2047]>>6)*
1231
                       ((int32_t)sintable[(tempint+512)&2047])>>6)
1231
                       ((int32_t)sintable[(tempint+512)&2047])>>6)
1232
                      <<pk_uedaccel);
1232
                      <<pk_uedaccel);
1233
1233
1234
            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));
1235
1235
1236
            move_and_update(xvect, yvect, 2);
1236
            move_and_update(xvect, yvect, 2);
1237
        }
1237
        }
1238
    }
1238
    }
1239
1239
1240
    if (mskip)
1240
    if (mskip)
1241
    {
1241
    {
1242
        // 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.
1243
        // Reset now.
1243
        // Reset now.
1244
        mskip = 0;
1244
        mskip = 0;
1245
    }
1245
    }
1246
    else
1246
    else
1247
    {
1247
    {
1248
        if (mlook && (unrealedlook==0 || (bstatus&(1|4))==0))
1248
        if (mlook && (unrealedlook==0 || (bstatus&(1|4))==0))
1249
        {
1249
        {
1250
            ang += mousx;
1250
            ang += mousx;
1251
            horiz -= mousy;
1251
            horiz -= mousy;
1252
1252
1253
            /*
1253
            /*
1254
            if (mousy && !(mousy/4))
1254
            if (mousy && !(mousy/4))
1255
                horiz--;
1255
                horiz--;
1256
            if (mousx && !(mousx/2))
1256
            if (mousx && !(mousx/2))
1257
                ang++;
1257
                ang++;
1258
            */
1258
            */
1259
1259
1260
            inpclamp(&horiz, -99, 299);
1260
            inpclamp(&horiz, -99, 299);
1261
1261
1262
            if (mlook == 1)
1262
            if (mlook == 1)
1263
            {
1263
            {
1264
                searchx = xdim>>1;
1264
                searchx = xdim>>1;
1265
                searchy = ydim>>1;
1265
                searchy = ydim>>1;
1266
            }
1266
            }
1267
            osearchx = searchx-mousx;
1267
            osearchx = searchx-mousx;
1268
            osearchy = searchy-mousy;
1268
            osearchy = searchy-mousy;
1269
1269
1270
            if (mousx || mousy)
1270
            if (mousx || mousy)
1271
            {
1271
            {
1272
                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);
1273
                getmessagetimeoff = (int32_t) totalclock+30;
1273
                getmessagetimeoff = (int32_t) totalclock+30;
1274
            }
1274
            }
1275
        }
1275
        }
1276
        else if (unrealedlook==0 || (bstatus&(1|2|4))==0)
1276
        else if (unrealedlook==0 || (bstatus&(1|2|4))==0)
1277
        {
1277
        {
1278
            osearchx = searchx;
1278
            osearchx = searchx;
1279
            osearchy = searchy;
1279
            osearchy = searchy;
1280
            searchx += mousx;
1280
            searchx += mousx;
1281
            searchy += mousy;
1281
            searchy += mousy;
1282
1282
1283
            inpclamp(&searchx, 12, xdim-13);
1283
            inpclamp(&searchx, 12, xdim-13);
1284
            inpclamp(&searchy, 12, ydim-13);
1284
            inpclamp(&searchy, 12, ydim-13);
1285
        }
1285
        }
1286
    }
1286
    }
1287
1287
1288
//    showmouse();
1288
//    showmouse();
1289
1289
1290
    if (keystatus[sc_F9])  // F9
1290
    if (keystatus[sc_F9])  // F9
1291
    {
1291
    {
1292
        if (mhk)
1292
        if (mhk)
1293
        {
1293
        {
1294
            Bmemset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES);
1294
            Bmemset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES);
1295
            Bmemset(spritesmooth, 0, sizeof(spritesmooth_t) * (MAXSPRITES+MAXUNIQHUDID));
1295
            Bmemset(spritesmooth, 0, sizeof(spritesmooth_t) * (MAXSPRITES+MAXUNIQHUDID));
1296
            engineClearLightsFromMHK();
1296
            engineClearLightsFromMHK();
1297
            mhk = 0;
1297
            mhk = 0;
1298
            message("Maphacks disabled");
1298
            message("Maphacks disabled");
1299
        }
1299
        }
1300
        else
1300
        else
1301
        {
1301
        {
1302
            mhk = 1;
1302
            mhk = 1;
1303
            loadmhk(1);
1303
            loadmhk(1);
1304
        }
1304
        }
1305
1305
1306
        keystatus[sc_F9] = 0;
1306
        keystatus[sc_F9] = 0;
1307
    }
1307
    }
1308
1308
1309
    mainloop_move();
1309
    mainloop_move();
1310
1310
1311
    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);
1312
/*
1312
/*
1313
{
1313
{
1314
    int32_t his = !(hihit&32768), los = !(lohit&32768);
1314
    int32_t his = !(hihit&32768), los = !(lohit&32768);
1315
    if (m32_numdebuglines<64)
1315
    if (m32_numdebuglines<64)
1316
        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,
1317
                 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);
1318
}
1318
}
1319
*/
1319
*/
1320
    oposz = pos.z;
1320
    oposz = pos.z;
1321
    if (zmode == 0)
1321
    if (zmode == 0)
1322
    {
1322
    {
1323
        goalz = loz-(kensplayerheight<<8);  //playerheight pixels above floor
1323
        goalz = loz-(kensplayerheight<<8);  //playerheight pixels above floor
1324
        if (goalz < hiz+(16<<8))  //ceiling&floor too close
1324
        if (goalz < hiz+(16<<8))  //ceiling&floor too close
1325
            goalz = (loz+hiz)>>1;
1325
            goalz = (loz+hiz)>>1;
1326
        goalz += mousz;
1326
        goalz += mousz;
1327
1327
1328
        if (DOWN_BK(MOVEUP))  //A (stand high)
1328
        if (DOWN_BK(MOVEUP))  //A (stand high)
1329
        {
1329
        {
1330
            goalz -= (16<<8);
1330
            goalz -= (16<<8);
1331
            if (DOWN_BK(RUN))
1331
            if (DOWN_BK(RUN))
1332
                goalz -= (24<<8);
1332
                goalz -= (24<<8);
1333
        }
1333
        }
1334
        if (DOWN_BK(MOVEDOWN))  //Z (stand low)
1334
        if (DOWN_BK(MOVEDOWN))  //Z (stand low)
1335
        {
1335
        {
1336
            goalz += (12<<8);
1336
            goalz += (12<<8);
1337
            if (DOWN_BK(RUN))
1337
            if (DOWN_BK(RUN))
1338
                goalz += (12<<8);
1338
                goalz += (12<<8);
1339
        }
1339
        }
1340
1340
1341
        if (goalz != pos.z)
1341
        if (goalz != pos.z)
1342
        {
1342
        {
1343
            if (pos.z < goalz) hvel += 64;
1343
            if (pos.z < goalz) hvel += 64;
1344
            if (pos.z > goalz) hvel = ((goalz-pos.z)>>3);
1344
            if (pos.z > goalz) hvel = ((goalz-pos.z)>>3);
1345
1345
1346
            pos.z += hvel;
1346
            pos.z += hvel;
1347
            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;
1348
            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;
1349
        }
1349
        }
1350
    }
1350
    }
1351
    else
1351
    else
1352
    {
1352
    {
1353
        goalz = pos.z;
1353
        goalz = pos.z;
1354
        if (DOWN_BK(MOVEUP))  //A
1354
        if (DOWN_BK(MOVEUP))  //A
1355
        {
1355
        {
1356
            if (eitherALT)
1356
            if (eitherALT)
1357
            {
1357
            {
1358
                horiz = max(-100,horiz-((DOWN_BK(RUN)+1)*synctics*2));
1358
                horiz = max(-100,horiz-((DOWN_BK(RUN)+1)*synctics*2));
1359
            }
1359
            }
1360
            else
1360
            else
1361
            {
1361
            {
1362
                if (zmode != 1)
1362
                if (zmode != 1)
1363
                    goalz -= (8<<8);
1363
                    goalz -= (8<<8);
1364
                else
1364
                else
1365
                {
1365
                {
1366
                    zlock += (4<<8);
1366
                    zlock += (4<<8);
1367
                    DOWN_BK(MOVEUP) = 0;
1367
                    DOWN_BK(MOVEUP) = 0;
1368
                }
1368
                }
1369
            }
1369
            }
1370
        }
1370
        }
1371
        if (DOWN_BK(MOVEDOWN))  //Z (stand low)
1371
        if (DOWN_BK(MOVEDOWN))  //Z (stand low)
1372
        {
1372
        {
1373
            if (eitherALT)
1373
            if (eitherALT)
1374
            {
1374
            {
1375
                horiz = min(300,horiz+((DOWN_BK(RUN)+1)*synctics*2));
1375
                horiz = min(300,horiz+((DOWN_BK(RUN)+1)*synctics*2));
1376
            }
1376
            }
1377
            else
1377
            else
1378
            {
1378
            {
1379
                if (zmode != 1)
1379
                if (zmode != 1)
1380
                    goalz += (8<<8);
1380
                    goalz += (8<<8);
1381
                else if (zlock > 0)
1381
                else if (zlock > 0)
1382
                {
1382
                {
1383
                    zlock -= (4<<8);
1383
                    zlock -= (4<<8);
1384
                    DOWN_BK(MOVEDOWN) = 0;
1384
                    DOWN_BK(MOVEDOWN) = 0;
1385
                }
1385
                }
1386
            }
1386
            }
1387
        }
1387
        }
1388
1388
1389
        if (m32_clipping)
1389
        if (m32_clipping)
1390
            inpclamp(&goalz, hiz+(4<<8), loz-(4<<8));
1390
            inpclamp(&goalz, hiz+(4<<8), loz-(4<<8));
1391
1391
1392
        if (zmode == 1) goalz = loz-zlock;
1392
        if (zmode == 1) goalz = loz-zlock;
1393
        if (m32_clipping && (goalz < hiz+(4<<8)))
1393
        if (m32_clipping && (goalz < hiz+(4<<8)))
1394
            goalz = ((loz+hiz)>>1);  //ceiling&floor too close
1394
            goalz = ((loz+hiz)>>1);  //ceiling&floor too close
1395
        if (zmode == 1) pos.z = goalz;
1395
        if (zmode == 1) pos.z = goalz;
1396
1396
1397
        if (goalz != pos.z)
1397
        if (goalz != pos.z)
1398
        {
1398
        {
1399
            //if (pos.z < goalz) hvel += (32<<DOWN_BK(RUN));
1399
            //if (pos.z < goalz) hvel += (32<<DOWN_BK(RUN));
1400
            //if (pos.z > goalz) hvel -= (32<<DOWN_BK(RUN));
1400
            //if (pos.z > goalz) hvel -= (32<<DOWN_BK(RUN));
1401
            if (pos.z < goalz)
1401
            if (pos.z < goalz)
1402
                hvel = ((192*synctics)<<DOWN_BK(RUN));
1402
                hvel = ((192*synctics)<<DOWN_BK(RUN));
1403
            else
1403
            else
1404
                hvel = -((192*synctics)<<DOWN_BK(RUN));
1404
                hvel = -((192*synctics)<<DOWN_BK(RUN));
1405
1405
1406
            pos.z += hvel;
1406
            pos.z += hvel;
1407
1407
1408
            if (m32_clipping)
1408
            if (m32_clipping)
1409
            {
1409
            {
1410
                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;
1411
                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;
1412
            }
1412
            }
1413
        }
1413
        }
1414
        else
1414
        else
1415
            hvel = 0;
1415
            hvel = 0;
1416
    }
1416
    }
1417
1417
1418
    {
1418
    {
1419
        int16_t ocursectnum = cursectnum;
1419
        int16_t ocursectnum = cursectnum;
1420
        updatesectorz(pos.x,pos.y,pos.z, &cursectnum);
1420
        updatesectorz(pos.x,pos.y,pos.z, &cursectnum);
1421
        if (cursectnum<0)
1421
        if (cursectnum<0)
1422
        {
1422
        {
1423
            if (zmode != 2)
1423
            if (zmode != 2)
1424
                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
1425
            cursectnum = ocursectnum;
1425
            cursectnum = ocursectnum;
1426
        }
1426
        }
1427
    }
1427
    }
1428
1428
1429
    if (pos.z != oposz && in3dmode())
1429
    if (pos.z != oposz && in3dmode())
1430
    {
1430
    {
1431
        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);
1432
        getmessagetimeoff = (int32_t) totalclock+30;
1432
        getmessagetimeoff = (int32_t) totalclock+30;
1433
    }
1433
    }
1434
1434
1435
    searchit = 2;
1435
    searchit = 2;
1436
    if (searchstat >= 0)
1436
    if (searchstat >= 0)
1437
    {
1437
    {
1438
        if ((bstatus&(1|2|4)) || keystatus[sc_Space])  // SPACE
1438
        if ((bstatus&(1|2|4)) || keystatus[sc_Space])  // SPACE
1439
            searchit = 0;
1439
            searchit = 0;
1440
1440
1441
        if (keystatus[sc_S])  //S (insert sprite) (3D)
1441
        if (keystatus[sc_S])  //S (insert sprite) (3D)
1442
        {
1442
        {
1443
            hitdata_t hit;
1443
            hitdata_t hit;
1444
            vec2_t osearch = {searchx, searchy};
1444
            vec2_t osearch = {searchx, searchy};
1445
            vec2_t bdim = {xdim, ydim};
1445
            vec2_t bdim = {xdim, ydim};
1446
            if (m32_is2d3dmode())
1446
            if (m32_is2d3dmode())
1447
            {
1447
            {
1448
                xdim = XSIZE_2D3D;
1448
                xdim = XSIZE_2D3D;
1449
                ydim = YSIZE_2D3D;
1449
                ydim = YSIZE_2D3D;
1450
                searchx -= m32_2d3d.x;
1450
                searchx -= m32_2d3d.x;
1451
                searchy -= m32_2d3d.y;
1451
                searchy -= m32_2d3d.y;
1452
            }
1452
            }
1453
1453
1454
            vec2_t da = { 16384, divscale14(searchx-(xdim>>1), xdim>>1) };
1454
            vec2_t da = { 16384, divscale14(searchx-(xdim>>1), xdim>>1) };
1455
1455
1456
            rotatepoint(zerovec, da, ang, &da);
1456
            rotatepoint(zerovec, da, ang, &da);
1457
1457
1458
#ifdef USE_OPENGL
1458
#ifdef USE_OPENGL
1459
            if (videoGetRenderMode() == REND_POLYMOST)
1459
            if (videoGetRenderMode() == REND_POLYMOST)
1460
                hit = polymost_hitdata;
1460
                hit = polymost_hitdata;
1461
            else
1461
            else
1462
#endif
1462
#endif
1463
                hitscan((const vec3_t *)&pos,cursectnum,              //Start position
1463
                hitscan((const vec3_t *)&pos,cursectnum,              //Start position
1464
                    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
1465
                    &hit,CLIPMASK1);
1465
                    &hit,CLIPMASK1);
1466
1466
1467
            if (hit.sect >= 0)
1467
            if (hit.sect >= 0)
1468
            {
1468
            {
1469
                da.x = hit.pos.x;
1469
                da.x = hit.pos.x;
1470
                da.y = hit.pos.y;
1470
                da.y = hit.pos.y;
1471
                if (gridlock && grid > 0)
1471
                if (gridlock && grid > 0)
1472
                {
1472
                {
1473
                    if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
1473
                    if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
1474
                        hit.pos.z &= 0xfffffc00;
1474
                        hit.pos.z &= 0xfffffc00;
1475
                    else
1475
                    else
1476
                        locktogrid(&da.x, &da.y);
1476
                        locktogrid(&da.x, &da.y);
1477
                }
1477
                }
1478
1478
1479
                i = insert_sprite_common(hit.sect, da.x, da.y);
1479
                i = insert_sprite_common(hit.sect, da.x, da.y);
1480
1480
1481
                if (i < 0)
1481
                if (i < 0)
1482
                    message("Couldn't insert sprite.");
1482
                    message("Couldn't insert sprite.");
1483
                else
1483
                else
1484
                {
1484
                {
1485
                    int32_t cz, fz;
1485
                    int32_t cz, fz;
1486
1486
1487
                    handle_sprite_in_clipboard(i);
1487
                    handle_sprite_in_clipboard(i);
1488
1488
1489
                    spriteoncfz(i, &cz, &fz);
1489
                    spriteoncfz(i, &cz, &fz);
1490
                    sprite[i].z = clamp2(hit.pos.z, cz, fz);
1490
                    sprite[i].z = clamp2(hit.pos.z, cz, fz);
1491
1491
1492
                    if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
1492
                    if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
1493
                    {
1493
                    {
1494
                        sprite[i].cstat &= ~48;
1494
                        sprite[i].cstat &= ~48;
1495
                        sprite[i].cstat |= (16+64);
1495
                        sprite[i].cstat |= (16+64);
1496
1496
1497
                        correct_ornamented_sprite(i, hit.wall);
1497
                        correct_ornamented_sprite(i, hit.wall);
1498
                    }
1498
                    }
1499
                    else
1499
                    else
1500
                        sprite[i].cstat |= (tilesiz[sprite[i].picnum].y>=32);
1500
                        sprite[i].cstat |= (tilesiz[sprite[i].picnum].y>=32);
1501
1501
1502
                    correct_sprite_yoffset(i);
1502
                    correct_sprite_yoffset(i);
1503
1503
1504
                    asksave = 1;
1504
                    asksave = 1;
1505
1505
1506
                    VM_OnEvent(EVENT_INSERTSPRITE3D, i);
1506
                    VM_OnEvent(EVENT_INSERTSPRITE3D, i);
1507
                }
1507
                }
1508
            }
1508
            }
1509
1509
1510
            xdim = bdim.x;
1510
            xdim = bdim.x;
1511
            ydim = bdim.y;
1511
            ydim = bdim.y;
1512
            searchx = osearch.x;
1512
            searchx = osearch.x;
1513
            searchy = osearch.y;
1513
            searchy = osearch.y;
1514
            keystatus[sc_S] = 0;
1514
            keystatus[sc_S] = 0;
1515
        }
1515
        }
1516
1516
1517
        if (keystatus[sc_F5]||keystatus[sc_F6])  //F5,F6
1517
        if (keystatus[sc_F5]||keystatus[sc_F6])  //F5,F6
1518
        {
1518
        {
1519
            switch (searchstat)
1519
            switch (searchstat)
1520
            {
1520
            {
1521
            case SEARCH_CEILING:
1521
            case SEARCH_CEILING:
1522
            case SEARCH_FLOOR:
1522
            case SEARCH_FLOOR:
1523
                CallExtShowSectorData(searchsector); break;
1523
                CallExtShowSectorData(searchsector); break;
1524
            case SEARCH_WALL:
1524
            case SEARCH_WALL:
1525
            case SEARCH_MASKWALL:
1525
            case SEARCH_MASKWALL:
1526
                CallExtShowWallData(searchwall); break;
1526
                CallExtShowWallData(searchwall); break;
1527
            case SEARCH_SPRITE:
1527
            case SEARCH_SPRITE:
1528
                CallExtShowSpriteData(searchwall); break;
1528
                CallExtShowSpriteData(searchwall); break;
1529
            }
1529
            }
1530
1530
1531
            keystatus[sc_F5] = keystatus[sc_F6] = 0;
1531
            keystatus[sc_F5] = keystatus[sc_F6] = 0;
1532
        }
1532
        }
1533
        if (keystatus[sc_F7]||keystatus[sc_F8])  //F7,F8
1533
        if (keystatus[sc_F7]||keystatus[sc_F8])  //F7,F8
1534
        {
1534
        {
1535
            switch (searchstat)
1535
            switch (searchstat)
1536
            {
1536
            {
1537
            case SEARCH_CEILING:
1537
            case SEARCH_CEILING:
1538
            case SEARCH_FLOOR:
1538
            case SEARCH_FLOOR:
1539
                CallExtEditSectorData(searchsector); break;
1539
                CallExtEditSectorData(searchsector); break;
1540
            case SEARCH_WALL:
1540
            case SEARCH_WALL:
1541
            case SEARCH_MASKWALL:
1541
            case SEARCH_MASKWALL:
1542
                CallExtEditWallData(searchwall); break;
1542
                CallExtEditWallData(searchwall); break;
1543
            case SEARCH_SPRITE:
1543
            case SEARCH_SPRITE:
1544
                CallExtEditSpriteData(searchwall); break;
1544
                CallExtEditSpriteData(searchwall); break;
1545
            }
1545
            }
1546
1546
1547
            keystatus[sc_F7] = keystatus[sc_F8] = 0;
1547
            keystatus[sc_F7] = keystatus[sc_F8] = 0;
1548
        }
1548
        }
1549
1549
1550
    }
1550
    }
1551
1551
1552
    if (keystatus[buildkeys[BK_MODE2D_3D]] && !m32_is2d3dmode())  // Enter
1552
    if (keystatus[buildkeys[BK_MODE2D_3D]] && !m32_is2d3dmode())  // Enter
1553
    {
1553
    {
1554
1554
1555
        vid_gamma_3d = g_videoGamma;
1555
        vid_gamma_3d = g_videoGamma;
1556
        vid_contrast_3d = g_videoContrast;
1556
        vid_contrast_3d = g_videoContrast;
1557
        vid_brightness_3d = g_videoBrightness;
1557
        vid_brightness_3d = g_videoBrightness;
1558
1558
1559
        g_videoGamma = g_videoContrast = 1.0;
1559
        g_videoGamma = g_videoContrast = 1.0;
1560
        g_videoBrightness = 0.0;
1560
        g_videoBrightness = 0.0;
1561
1561
1562
        videoSetPalette(0,0,0);
1562
        videoSetPalette(0,0,0);
1563
1563
1564
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
1564
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
1565
        overheadeditor();
1565
        overheadeditor();
1566
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
1566
        keystatus[buildkeys[BK_MODE2D_3D]] = 0;
1567
1567
1568
        g_videoGamma = vid_gamma_3d;
1568
        g_videoGamma = vid_gamma_3d;
1569
        g_videoContrast = vid_contrast_3d;
1569
        g_videoContrast = vid_contrast_3d;
1570
        g_videoBrightness = vid_brightness_3d;
1570
        g_videoBrightness = vid_brightness_3d;
1571
1571
1572
        vid_gamma_3d = vid_contrast_3d = vid_brightness_3d = -1;
1572
        vid_gamma_3d = vid_contrast_3d = vid_brightness_3d = -1;
1573
1573
1574
        videoSetPalette(GAMMA_CALC,0,0);
1574
        videoSetPalette(GAMMA_CALC,0,0);
1575
    }
1575
    }
1576
}
1576
}
1577
1577
1578
char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck)
1578
char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck)
1579
{
1579
{
1580
    if (dadir < 0)
1580
    if (dadir < 0)
1581
    {
1581
    {
1582
        if ((dachar > 0) || (boundcheck == 0))
1582
        if ((dachar > 0) || (boundcheck == 0))
1583
        {
1583
        {
1584
            dachar--;
1584
            dachar--;
1585
            if (smooshyalign > 0)
1585
            if (smooshyalign > 0)
1586
                dachar = (dachar&0xf8);
1586
                dachar = (dachar&0xf8);
1587
        }
1587
        }
1588
    }
1588
    }
1589
    else if (dadir > 0)
1589
    else if (dadir > 0)
1590
    {
1590
    {
1591
        if ((dachar < 255) || (boundcheck == 0))
1591
        if ((dachar < 255) || (boundcheck == 0))
1592
        {
1592
        {
1593
            dachar++;
1593
            dachar++;
1594
            if (smooshyalign > 0)
1594
            if (smooshyalign > 0)
1595
            {
1595
            {
1596
                if (dachar >= 256-8) dachar = 255;
1596
                if (dachar >= 256-8) dachar = 255;
1597
                else dachar = ((dachar+7)&0xf8);
1597
                else dachar = ((dachar+7)&0xf8);
1598
            }
1598
            }
1599
        }
1599
        }
1600
    }
1600
    }
1601
    return dachar;
1601
    return dachar;
1602
}
1602
}
1603
1603
1604
1604
1605
////////////////////// OVERHEADEDITOR //////////////////////
1605
////////////////////// OVERHEADEDITOR //////////////////////
1606
1606
1607
// some 2d mode state
1607
// some 2d mode state
1608
static struct overheadstate
1608
static struct overheadstate
1609
{
1609
{
1610
    // number of backed up drawn walls
1610
    // number of backed up drawn walls
1611
    int32_t bak_wallsdrawn;
1611
    int32_t bak_wallsdrawn;
1612
1612
1613
    // state related to line drawing
1613
    // state related to line drawing
1614
    int16_t suckwall, split;
1614
    int16_t suckwall, split;
1615
    int16_t splitsect;
1615
    int16_t splitsect;
1616
    int16_t splitstartwall;
1616
    int16_t splitstartwall;
1617
} ovh;
1617
} ovh;
1618
1618
1619
1619
1620
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,
1621
                             int32_t x, int32_t y, int16_t sectnum)
1621
                             int32_t x, int32_t y, int16_t sectnum)
1622
{
1622
{
1623
    if (!m32_sideview)
1623
    if (!m32_sideview)
1624
        return inside(x, y, sectnum);
1624
        return inside(x, y, sectnum);
1625
1625
1626
    // if in side-view mode, use the screen coords instead
1626
    // if in side-view mode, use the screen coords instead
1627
    {
1627
    {
1628
        int32_t dst = MAXSECTORS+M32_FIXME_SECTORS-1, i, oi;
1628
        int32_t dst = MAXSECTORS+M32_FIXME_SECTORS-1, i, oi;
1629
        int32_t srcw=sector[sectnum].wallptr, dstw=MAXWALLS;
1629
        int32_t srcw=sector[sectnum].wallptr, dstw=MAXWALLS;
1630
        int32_t ret;
1630
        int32_t ret;
1631
1631
1632
        if (sector[sectnum].wallnum > M32_FIXME_WALLS)
1632
        if (sector[sectnum].wallnum > M32_FIXME_WALLS)
1633
            return -1;
1633
            return -1;
1634
1634
1635
        Bmemcpy(&sector[dst], &sector[sectnum], sizeof(sectortype));
1635
        Bmemcpy(&sector[dst], &sector[sectnum], sizeof(sectortype));
1636
        sector[dst].wallptr = dstw;
1636
        sector[dst].wallptr = dstw;
1637
1637
1638
        Bmemcpy(&wall[dstw], &wall[srcw], sector[dst].wallnum*sizeof(walltype));
1638
        Bmemcpy(&wall[dstw], &wall[srcw], sector[dst].wallnum*sizeof(walltype));
1639
        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++)
1640
        {
1640
        {
1641
            wall[i].point2 += dstw-srcw;
1641
            wall[i].point2 += dstw-srcw;
1642
1642
1643
            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);
1644
            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);
1645
            wall[i].x += halfxdim16;
1645
            wall[i].x += halfxdim16;
1646
            wall[i].y += midydim16;
1646
            wall[i].y += midydim16;
1647
        }
1647
        }
1648
1648
1649
        i = numsectors;
1649
        i = numsectors;
1650
        numsectors = dst+1;
1650
        numsectors = dst+1;
1651
        ret = inside(searchx, searchy, dst);
1651
        ret = inside(searchx, searchy, dst);
1652
        numsectors = i;
1652
        numsectors = i;
1653
        return ret;
1653
        return ret;
1654
    }
1654
    }
1655
}
1655
}
1656
1656
1657
int32_t inside_editor_curpos(int16_t sectnum)
1657
int32_t inside_editor_curpos(int16_t sectnum)
1658
{
1658
{
1659
    // TODO: take care: mous[xy]plc global vs overheadeditor auto
1659
    // TODO: take care: mous[xy]plc global vs overheadeditor auto
1660
    return inside_editor(&pos, searchx,searchy, zoom, mousxplc,mousyplc, sectnum);
1660
    return inside_editor(&pos, searchx,searchy, zoom, mousxplc,mousyplc, sectnum);
1661
}
1661
}
1662
1662
1663
1663
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)
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)
1665
{
1665
{
1666
    editorDraw2dLine(bx+x1, by+y1, bx+x2, by+y2, col);
1666
    editorDraw2dLine(bx+x1, by+y1, bx+x2, by+y2, col);
1667
}
1667
}
1668
1668
1669
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)
1670
{
1670
{
1671
    editorGet2dScreenCoordinates(&dax,&day, dax-pos.x,day-pos.y, zoom);
1671
    editorGet2dScreenCoordinates(&dax,&day, dax-pos.x,day-pos.y, zoom);
1672
1672
1673
    if (m32_sideview)
1673
    if (m32_sideview)
1674
        day += getscreenvdisp(daz-pos.z, zoom);
1674
        day += getscreenvdisp(daz-pos.z, zoom);
1675
1675
1676
    int32_t const x1 = halfxdim16+dax-(Bstrlen(text)<<1);
1676
    int32_t const x1 = halfxdim16+dax-(Bstrlen(text)<<1);
1677
    int32_t const y1 = midydim16+day-4;
1677
    int32_t const y1 = midydim16+day-4;
1678
    int32_t const x2 = x1 + (Bstrlen(text)<<2)+2;
1678
    int32_t const x2 = x1 + (Bstrlen(text)<<2)+2;
1679
    int32_t const y2 = y1 + 7;
1679
    int32_t const y2 = y1 + 7;
1680
1680
1681
    int f = mulscale8(x2-x1, zoom);
1681
    int f = mulscale8(x2-x1, zoom);
1682
1682
1683
    if ((x1 <= -f) || (x2 >= xdim + f) || (y1 <= -f) || (y2 >= ydim16 + f))
1683
    if ((x1 <= -f) || (x2 >= xdim + f) || (y1 <= -f) || (y2 >= ydim16 + f))
1684
        return;
1684
        return;
1685
1685
1686
    printext16(x1,y1, col,backcol, text,1);
1686
    printext16(x1,y1, col,backcol, text,1);
1687
1687
1688
    editorDraw2dLine(x1-2, y1-2, x2-2, y1-2, border);
1688
    editorDraw2dLine(x1-2, y1-2, x2-2, y1-2, border);
1689
    editorDraw2dLine(x1-2, y2+1, x2-2, y2+1, border);
1689
    editorDraw2dLine(x1-2, y2+1, x2-2, y2+1, border);
1690
1690
1691
    editorDraw2dLine(x1-3, y1-1, x1-3, y2+0, border);
1691
    editorDraw2dLine(x1-3, y1-1, x1-3, y2+0, border);
1692
    editorDraw2dLine(x2-1, y1-1, x2-1, y2+0, border);
1692
    editorDraw2dLine(x2-1, y1-1, x2-1, y2+0, border);
1693
1693
1694
    editorDraw2dLine(x1-1,y1-1, x2-3,y1-1, backcol);
1694
    editorDraw2dLine(x1-1,y1-1, x2-3,y1-1, backcol);
1695
    editorDraw2dLine(x1-1,y2+0, x2-3,y2+0, backcol);
1695
    editorDraw2dLine(x1-1,y2+0, x2-3,y2+0, backcol);
1696
1696
1697
    editorDraw2dLine(x1-2,y1+0, x1-2,y2-1, backcol);
1697
    editorDraw2dLine(x1-2,y1+0, x1-2,y2-1, backcol);
1698
    editorDraw2dLine(x2-2,y1+0, x2-2,y2-1, backcol);
1698
    editorDraw2dLine(x2-2,y1+0, x2-2,y2-1, backcol);
1699
    editorDraw2dLine(x2-3,y1+0, x2-3,y2+0, backcol);
1699
    editorDraw2dLine(x2-3,y1+0, x2-3,y2+0, backcol);
1700
1700
1701
    videoBeginDrawing(); //{{{
1701
    videoBeginDrawing(); //{{{
1702
1702
1703
    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)
1704
    {
1704
    {
1705
        drawpixel((char *) (frameplace + ((y1-1) * bytesperline) + (x1-2)), border);
1705
        drawpixel((char *) (frameplace + ((y1-1) * bytesperline) + (x1-2)), border);
1706
        drawpixel((char *) (frameplace + ((y1-1) * bytesperline) + (x2-2)), border);
1706
        drawpixel((char *) (frameplace + ((y1-1) * bytesperline) + (x2-2)), border);
1707
    }
1707
    }
1708
1708
1709
    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)
1710
    {
1710
    {
1711
        drawpixel((char *) (frameplace + ((y2) * bytesperline) + (x1-2)), border);
1711
        drawpixel((char *) (frameplace + ((y2) * bytesperline) + (x1-2)), border);
1712
        drawpixel((char *) (frameplace + ((y2) * bytesperline) + (x2-2)), border);
1712
        drawpixel((char *) (frameplace + ((y2) * bytesperline) + (x2-2)), border);
1713
    }
1713
    }
1714
1714
1715
    videoEndDrawing();
1715
    videoEndDrawing();
1716
}
1716
}
1717
1717
1718
// backup highlighted sectors with sprites as mapinfo for later restoration
1718
// backup highlighted sectors with sprites as mapinfo for later restoration
1719
// return values:
1719
// return values:
1720
//  -1: highlightsectorcnt<=0
1720
//  -1: highlightsectorcnt<=0
1721
//   0: ok
1721
//   0: ok
1722
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo)
1722
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo)
1723
{
1723
{
1724
    int32_t i, j, k, m, tmpnumwalls=0, tmpnumsprites=0;
1724
    int32_t i, j, k, m, tmpnumwalls=0, tmpnumsprites=0;
1725
    int16_t *const otonsect = (int16_t *)tempxyar;  // STRICTALIASING
1725
    int16_t *const otonsect = (int16_t *)tempxyar;  // STRICTALIASING
1726
    int16_t *const otonwall = ((int16_t *)tempxyar) + MAXWALLS;
1726
    int16_t *const otonwall = ((int16_t *)tempxyar) + MAXWALLS;
1727
#ifdef YAX_ENABLE
1727
#ifdef YAX_ENABLE
1728
    int16_t otonbunch[YAX_MAXBUNCHES];
1728
    int16_t otonbunch[YAX_MAXBUNCHES];
1729
    int16_t numsectsofbunch[YAX_MAXBUNCHES];  // ceilings + floors
1729
    int16_t numsectsofbunch[YAX_MAXBUNCHES];  // ceilings + floors
1730
#endif
1730
#endif
1731
1731
1732
    if (highlightsectorcnt <= 0)
1732
    if (highlightsectorcnt <= 0)
1733
        return -1;
1733
        return -1;
1734
1734
1735
#ifdef YAX_ENABLE
1735
#ifdef YAX_ENABLE
1736
    for (i=0; i<numyaxbunches; i++)
1736
    for (i=0; i<numyaxbunches; i++)
1737
        numsectsofbunch[i] = 0;
1737
        numsectsofbunch[i] = 0;
1738
#endif
1738
#endif
1739
1739
1740
    // set up old-->new mappings
1740
    // set up old-->new mappings
1741
    j = 0;
1741
    j = 0;
1742
    k = 0;
1742
    k = 0;
1743
    for (i=0; i<numsectors; i++)
1743
    for (i=0; i<numsectors; i++)
1744
    {
1744
    {
1745
        int32_t startwall, endwall;
1745
        int32_t startwall, endwall;
1746
1746
1747
        if (hlsectorbitmap[i>>3]&pow2char[i&7])
1747
        if (hlsectorbitmap[i>>3]&pow2char[i&7])
1748
        {
1748
        {
1749
#ifdef YAX_ENABLE
1749
#ifdef YAX_ENABLE
1750
            int16_t bn[2], cf;
1750
            int16_t bn[2], cf;
1751
1751
1752
            yax_getbunches(i, &bn[0], &bn[1]);
1752
            yax_getbunches(i, &bn[0], &bn[1]);
1753
            for (cf=0; cf<2; cf++)
1753
            for (cf=0; cf<2; cf++)
1754
                if (bn[cf] >= 0)
1754
                if (bn[cf] >= 0)
1755
                    numsectsofbunch[bn[cf]]++;
1755
                    numsectsofbunch[bn[cf]]++;
1756
#endif
1756
#endif
1757
            otonsect[i] = j++;
1757
            otonsect[i] = j++;
1758
1758
1759
            for (WALLS_OF_SECTOR(i, m))
1759
            for (WALLS_OF_SECTOR(i, m))
1760
                otonwall[m] = k++;
1760
                otonwall[m] = k++;
1761
        }
1761
        }
1762
        else
1762
        else
1763
        {
1763
        {
1764
            otonsect[i] = -1;
1764
            otonsect[i] = -1;
1765
1765
1766
            for (WALLS_OF_SECTOR(i, m))
1766
            for (WALLS_OF_SECTOR(i, m))
1767
                otonwall[m] = -1;
1767
                otonwall[m] = -1;
1768
        }
1768
        }
1769
    }
1769
    }
1770
1770
1771
#ifdef YAX_ENABLE
1771
#ifdef YAX_ENABLE
1772
    j = 0;
1772
    j = 0;
1773
    for (i=0; i<numyaxbunches; i++)
1773
    for (i=0; i<numyaxbunches; i++)
1774
    {
1774
    {
1775
        // only back up complete bunches
1775
        // only back up complete bunches
1776
        if (numsectsofbunch[i] == yax_numsectsinbunch(i, 0)+yax_numsectsinbunch(i, 1))
1776
        if (numsectsofbunch[i] == yax_numsectsinbunch(i, 0)+yax_numsectsinbunch(i, 1))
1777
            otonbunch[i] = j++;  // kept bunch
1777
            otonbunch[i] = j++;  // kept bunch
1778
        else
1778
        else
1779
            otonbunch[i] = -1;  // discarded bunch
1779
            otonbunch[i] = -1;  // discarded bunch
1780
    }
1780
    }
1781
    mapinfo->numyaxbunches = j;
1781
    mapinfo->numyaxbunches = j;
1782
#endif
1782
#endif
1783
1783
1784
    // count walls & sprites
1784
    // count walls & sprites
1785
    for (i=0; i<highlightsectorcnt; i++)
1785
    for (i=0; i<highlightsectorcnt; i++)
1786
    {
1786
    {
1787
        tmpnumwalls += sector[highlightsector[i]].wallnum;
1787
        tmpnumwalls += sector[highlightsector[i]].wallnum;
1788
1788
1789
        m = headspritesect[highlightsector[i]];
1789
        m = headspritesect[highlightsector[i]];
1790
        while (m != -1)
1790
        while (m != -1)
1791
        {
1791
        {
1792
            tmpnumsprites++;
1792
            tmpnumsprites++;
1793
            m = nextspritesect[m];
1793
            m = nextspritesect[m];
1794
        }
1794
        }
1795
    }
1795
    }
1796
1796
1797
    // allocate temp storage
1797
    // allocate temp storage
1798
    mapinfo->sector = (usectortype *)Xmalloc(highlightsectorcnt * sizeof(sectortype));
1798
    mapinfo->sector = (usectortype *)Xmalloc(highlightsectorcnt * sizeof(sectortype));
1799
    mapinfo->wall = (uwalltype *)Xmalloc(tmpnumwalls * sizeof(walltype));
1799
    mapinfo->wall = (uwalltype *)Xmalloc(tmpnumwalls * sizeof(walltype));
1800
1800
1801
#ifdef YAX_ENABLE
1801
#ifdef YAX_ENABLE
1802
    if (mapinfo->numyaxbunches > 0)
1802
    if (mapinfo->numyaxbunches > 0)
1803
    {
1803
    {
1804
        mapinfo->bunchnum = (int16_t *)Xmalloc(highlightsectorcnt*2*sizeof(int16_t));
1804
        mapinfo->bunchnum = (int16_t *)Xmalloc(highlightsectorcnt*2*sizeof(int16_t));
1805
        mapinfo->ynextwall = (int16_t *)Xmalloc(tmpnumwalls*2*sizeof(int16_t));
1805
        mapinfo->ynextwall = (int16_t *)Xmalloc(tmpnumwalls*2*sizeof(int16_t));
1806