| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/editor/WireframeGrWnd.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:39 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Wireframe view of mine |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 29 4/03/99 5:22p Matt |
| 30 | * Don't render wireframe when editor rendering disabled |
| 31 | * |
| 32 | * 28 2/05/99 3:49p Jason |
| 33 | * added more types to color coded topographical window |
| 34 | * |
| 35 | * 27 2/05/99 3:37p Jason |
| 36 | * added/fixed features for the designers |
| 37 | * |
| 38 | * 26 2/03/99 1:11p Matt |
| 39 | * Changed the paletted room current faces to be stored in a seperate |
| 40 | * array, instead of in the room structure. |
| 41 | * |
| 42 | * 25 1/20/99 10:50a Jason |
| 43 | * added new terrain |
| 44 | * |
| 45 | * 24 1/15/99 7:52p Chris |
| 46 | * Updated ObjSetPos() to include a f_update_attach_children flag |
| 47 | * |
| 48 | * 23 10/04/98 1:25p Matt |
| 49 | * |
| 50 | * 22 9/23/98 12:30p Jason |
| 51 | * fixed memory overwrite bug |
| 52 | * |
| 53 | * 21 5/20/98 3:48p Matt |
| 54 | * Added suport for variable-depth face selection in wireframe view. |
| 55 | * |
| 56 | * 20 5/01/98 3:51p Jason |
| 57 | * sped up terrain rendering by precaching all megacell lod bitmaps |
| 58 | * |
| 59 | * 19 4/23/98 6:53p Jason |
| 60 | * changed wireframe map to work with new bitmap changes |
| 61 | * |
| 62 | * 18 4/23/98 6:38p Jason |
| 63 | * made bitmaps use 1555 format |
| 64 | * |
| 65 | * 17 2/05/98 3:18p Matt |
| 66 | * Renamed GetSegmentFromPoint() to GetCellFromPoint() |
| 67 | * |
| 68 | * 16 2/05/98 2:57p Matt |
| 69 | * Changed code to use ObjSetPos() |
| 70 | * |
| 71 | * 15 2/04/98 6:23p Matt |
| 72 | * Changed object room number to indicate a terrain cell via a flag. Got |
| 73 | * rid of the object flag which used to indicate terrain. |
| 74 | * |
| 75 | * 14 12/03/97 6:21p Jason |
| 76 | * made selections undoable |
| 77 | * |
| 78 | * 13 10/15/97 5:20p Jason |
| 79 | * did a HUGE overhaul of the bitmap system |
| 80 | * |
| 81 | * 12 10/03/97 3:39p Matt |
| 82 | * Added seperate sets of wireframe view variables for mine & room views |
| 83 | * |
| 84 | * 11 9/17/97 11:34a Matt |
| 85 | * Ripped out segment code |
| 86 | * |
| 87 | * 10 9/08/97 4:13p Jason |
| 88 | * added colored lighting for the terrain |
| 89 | * |
| 90 | * 9 9/06/97 3:21p Matt |
| 91 | * Reset cur portal when room changes |
| 92 | * |
| 93 | * 8 9/04/97 4:39p Matt |
| 94 | * Added includes needed as a result of removing includes from d3edit.h |
| 95 | * |
| 96 | * 7 8/29/97 5:14p Matt |
| 97 | * Switched segment selection function to do rooms instead |
| 98 | * |
| 99 | * 6 8/21/97 3:45p Matt |
| 100 | * Reset curedge & curvert when changing curroom & curface |
| 101 | * |
| 102 | * 5 8/06/97 11:43a Jason |
| 103 | * made lightmaps work correctly in the terrain |
| 104 | * |
| 105 | * 4 7/29/97 12:18p Matt |
| 106 | * Made wireframe search work for rooms & faces |
| 107 | * |
| 108 | * 3 7/22/97 7:08p Matt |
| 109 | * Cleaned up D3EditState, moving some vars in and some out, and renaming |
| 110 | * and changing a few others |
| 111 | * |
| 112 | * 32 6/19/97 11:32a Jason |
| 113 | * fixed bug where you could draw into the topo map even if you weren't |
| 114 | * viewing terrain |
| 115 | * |
| 116 | * 31 6/12/97 12:43p Jason |
| 117 | * fixed simple bug where bottom-right edges were being included in |
| 118 | * terrain selection |
| 119 | * |
| 120 | * 30 6/11/97 2:11p Jason |
| 121 | * made magnification actually zoom into the texture you're looking at |
| 122 | * |
| 123 | * 29 5/22/97 5:16p Jason |
| 124 | * added "drawing" on the topo map |
| 125 | * |
| 126 | * 28 5/21/97 3:39p Jason |
| 127 | * added terrain editing stuff |
| 128 | * |
| 129 | * 27 5/19/97 5:10p Jason |
| 130 | * changes for our new abstracted renderer code |
| 131 | * |
| 132 | * 26 5/15/97 4:37p Jason |
| 133 | * fixed some terrain bugs |
| 134 | * |
| 135 | * 25 5/15/97 3:27a Jason |
| 136 | * implemented terrain magnification |
| 137 | * |
| 138 | * 24 4/11/97 4:20p Jason |
| 139 | * now draws the player on the wireframe terrain window |
| 140 | * |
| 141 | * 23 4/10/97 4:39p Jason |
| 142 | * Made selection manager stuff work with terrain topographical map |
| 143 | * |
| 144 | * 22 3/31/97 5:58p Matt |
| 145 | * Revamped mine update flags |
| 146 | * |
| 147 | * 21 3/20/97 5:54p Matt |
| 148 | * Made box selection code ignore very small boxes so normal mouse clicks |
| 149 | * would work |
| 150 | * |
| 151 | * 20 3/20/97 5:01p Matt |
| 152 | * Added new select-from-box code |
| 153 | * |
| 154 | * 19 3/20/97 3:02p Samir |
| 155 | * Implemented Selection Manager in Wireframe window. |
| 156 | * |
| 157 | * 18 3/20/97 11:55a Jason |
| 158 | * changes for terrain editing/drawing |
| 159 | * |
| 160 | * 17 3/02/97 4:25p Matt |
| 161 | * Added shift-click to select/deselect segments in the wireframe window |
| 162 | * |
| 163 | * 16 2/28/97 2:21p Samir |
| 164 | * You can drag a box within the wireframe window. |
| 165 | * |
| 166 | * 15 2/27/97 4:26p Matt |
| 167 | * Fixed curseg selection status messages |
| 168 | * |
| 169 | * 14 2/19/97 5:37p Matt |
| 170 | * Added code to set curseg from clicking in wireframe window |
| 171 | * |
| 172 | * 13 1/30/97 6:26p Samir |
| 173 | * Minor change to drawing caption text |
| 174 | * |
| 175 | * 12 1/23/97 4:56p Samir |
| 176 | * Handles saving screen positions of windows and tileability. |
| 177 | * |
| 178 | * 11 1/21/97 12:43p Samir |
| 179 | * Floatable-resizable view |
| 180 | * |
| 181 | * $NoKeywords: $ |
| 182 | */ |
| 183 | |
| 184 | #include "stdafx.h" |
| 185 | #include "editor.h" |
| 186 | #include "WireframeGrWnd.h" |
| 187 | #include "3d.h" |
| 188 | #include "gametexture.h" |
| 189 | #include "drawworld.h" |
| 190 | #include "moveworld.h" |
| 191 | #include "selectedroom.h" |
| 192 | #include "terrain.h" |
| 193 | #include "bitmap.h" |
| 194 | #include "erooms.h" |
| 195 | |
| 196 | #include "gr.h" |
| 197 | #include "mono.h" |
| 198 | #include "ddio.h" |
| 199 | #include "SelManager.h" |
| 200 | #include "room.h" |
| 201 | #include "lighting.h" |
| 202 | |
| 203 | #ifdef _DEBUG |
| 204 | #define new DEBUG_NEW |
| 205 | #undef THIS_FILE |
| 206 | static char THIS_FILE[] = __FILE__; |
| 207 | #endif |
| 208 | |
| 209 | ///////////////////////////////////////////////////////////////////////////// |
| 210 | // CWireframeGrWnd |
| 211 | |
| 212 | CWireframeGrWnd::CWireframeGrWnd() : CGrWnd("WireframeScreen") { |
| 213 | m_Movable = FALSE; |
| 214 | m_x1 = m_y1 = 0; |
| 215 | m_y2 = TERRAIN_DEPTH; |
| 216 | m_x2 = TERRAIN_WIDTH; |
| 217 | } |
| 218 | |
| 219 | CWireframeGrWnd::~CWireframeGrWnd() {} |
| 220 | |
| 221 | void DrawIntoTopoMap(int x, int y); |
| 222 | |
| 223 | void CWireframeGrWnd::GetHighlightedRect(int *left, int *top, int *right, int *bottom) { |
| 224 | *left = m_HighlightedRect.left; |
| 225 | *top = m_HighlightedRect.top; |
| 226 | *right = m_HighlightedRect.right; |
| 227 | *bottom = m_HighlightedRect.bottom; |
| 228 | } |
| 229 | |
| 230 | BEGIN_MESSAGE_MAP(CWireframeGrWnd, CWnd) |
| 231 | //{{AFX_MSG_MAP(CWireframeGrWnd) |
| 232 | ON_WM_CREATE() |
| 233 | ON_WM_DESTROY() |
| 234 | ON_WM_SIZE() |
| 235 | ON_WM_PAINT() |
| 236 | ON_WM_MOVE() |
| 237 | ON_WM_SYSCOMMAND() |
| 238 | ON_WM_NCACTIVATE() |
| 239 | ON_WM_NCPAINT() |
| 240 | ON_WM_LBUTTONDOWN() |
| 241 | ON_WM_MOUSEMOVE() |
| 242 | ON_WM_LBUTTONUP() |
| 243 | ON_WM_RBUTTONDOWN() |
| 244 | //}}AFX_MSG_MAP |
| 245 | END_MESSAGE_MAP() |
| 246 | |
| 247 | //??extern void RenderWireFrame (grViewport *my_viewport); |
| 248 | //??extern void RenderTexFrame (grViewport *); |
| 249 | |
| 250 | extern bool Disable_editor_rendering; |
| 251 | |
| 252 | void CWireframeGrWnd::Render() { |
| 253 | // Don't do a thing if these objects aren't created yet |
| 254 | if (!m_grScreen) |
| 255 | return; |
| 256 | if (!m_grViewport) |
| 257 | return; |
| 258 | |
| 259 | if (Disable_editor_rendering) |
| 260 | return; |
| 261 | |
| 262 | if (Editor_view_mode == VM_TERRAIN) |
| 263 | DrawTerrainWorld(m_grViewport, &Wireframe_view->target, &Wireframe_view->orient, Wireframe_view->dist); |
| 264 | else |
| 265 | DrawWorld(m_grViewport, &Wireframe_view->target, &Wireframe_view->orient, Wireframe_view->dist, 0, |
| 266 | Wireframe_view->rad); |
| 267 | } |
| 268 | |
| 269 | ///////////////////////////////////////////////////////////////////////////// |
| 270 | // CWireframeGrWnd message handlers |
| 271 | |
| 272 | BOOL CWireframeGrWnd::Create(RECT &rect, BOOL movable, CWnd *pParent) { |
| 273 | RECT new_rect; |
| 274 | DWORD dwstyle; |
| 275 | |
| 276 | dwstyle = (movable ? GRWND_STYLE : GRWND_STATIC_STYLE); |
| 277 | |
| 278 | ::CopyRect(&new_rect, &rect); |
| 279 | ::AdjustWindowRect(&new_rect, dwstyle, FALSE); |
| 280 | |
| 281 | // We want this window to start at rect.left, rect.top. |
| 282 | if (new_rect.left < rect.left) { |
| 283 | int offx; |
| 284 | offx = rect.left - new_rect.left; |
| 285 | new_rect.left += offx; |
| 286 | new_rect.right += offx; |
| 287 | } |
| 288 | if (new_rect.top < rect.top) { |
| 289 | int offy; |
| 290 | offy = rect.top - new_rect.top; |
| 291 | new_rect.top += offy; |
| 292 | new_rect.bottom += offy; |
| 293 | } |
| 294 | |
| 295 | ::CopyRect(&rect, &new_rect); |
| 296 | |
| 297 | m_grCreated = TRUE; |
| 298 | m_Movable = movable; |
| 299 | |
| 300 | lstrcpy(m_Name, "Wireframe"); |
| 301 | |
| 302 | return CWnd::Create(NULL, m_Name, dwstyle, rect, pParent, IDC_WIREFRAME_WND); |
| 303 | } |
| 304 | |
| 305 | int CWireframeGrWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { |
| 306 | if (CGrWnd::OnCreate(lpCreateStruct) == -1) |
| 307 | return -1; |
| 308 | |
| 309 | theApp.wireframe_view = this; |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | void CWireframeGrWnd::OnDestroy() { |
| 314 | CGrWnd::OnDestroy(); |
| 315 | theApp.wireframe_view = NULL; |
| 316 | } |
| 317 | |
| 318 | void CWireframeGrWnd::OnSize(UINT nType, int cx, int cy) { |
| 319 | CGrWnd::OnSize(nType, cx, cy); |
| 320 | |
| 321 | // TODO: Add your message handler code here |
| 322 | if (m_Movable) { // Don't change these values if this is a static window |
| 323 | D3EditState.wirescr_w = cx; |
| 324 | D3EditState.wirescr_h = cy; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | void CWireframeGrWnd::OnPaint() { |
| 329 | CPaintDC dc(this); // device context for painting |
| 330 | |
| 331 | // Draw what's on the screen back page to the desktop |
| 332 | m_grScreen->flip(); |
| 333 | draw_tile_caption(&dc); |
| 334 | } |
| 335 | |
| 336 | void CWireframeGrWnd::OnMove(int x, int y) { |
| 337 | CGrWnd::OnMove(x, y); |
| 338 | |
| 339 | // must do this because actual (left,top) of window should be from title bar, not client |
| 340 | if (m_Movable) { // Don't change these values if we aren't movable |
| 341 | RECT rect; |
| 342 | GetWindowRect(&rect); |
| 343 | GetParent()->ScreenToClient(&rect); |
| 344 | D3EditState.wirescr_x = rect.left; |
| 345 | D3EditState.wirescr_y = rect.top; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | // Given an x,y mouse point, returns the terrain cell number at that point |
| 350 | int CWireframeGrWnd::GetCellFromPoint(int x, int y) { |
| 351 | int width = m_grViewport->width(); |
| 352 | int height = m_grViewport->height(); |
| 353 | |
| 354 | float xstep = (float)(m_x2 - m_x1) / (float)width; |
| 355 | float ystep = (float)(abs(m_y2 - m_y1)) / (float)height; |
| 356 | |
| 357 | int destx = xstep * x; |
| 358 | int desty = ystep * y; |
| 359 | |
| 360 | destx += m_x1; |
| 361 | desty += m_y1; |
| 362 | |
| 363 | desty = (TERRAIN_DEPTH - 1) - desty; // flip due to origin difference |
| 364 | |
| 365 | return (desty * TERRAIN_WIDTH + destx); |
| 366 | } |
| 367 | |
| 368 | void CWireframeGrWnd::OnSysCommand(UINT nID, LPARAM lParam) { |
| 369 | // TODO: Add your message handler code here and/or call default |
| 370 | |
| 371 | switch (nID) { |
| 372 | case SC_CLOSE: |
| 373 | D3EditState.wirescr_visible = 0; |
| 374 | break; |
| 375 | } |
| 376 | |
| 377 | CWnd::OnSysCommand(nID, lParam); |
| 378 | } |
| 379 | |
| 380 | BOOL CWireframeGrWnd::OnNcActivate(BOOL bActive) { return CGrWnd::OnNcActivate(bActive); } |
| 381 | |
| 382 | void CWireframeGrWnd::OnNcPaint() { CGrWnd::OnNcPaint(); } |
| 383 | |
| 384 | void CWireframeGrWnd::draw_tile_caption(CDC *dc) { |
| 385 | if (!m_Movable) { |
| 386 | dc->SetBkMode(TRANSPARENT); |
| 387 | dc->SetTextColor(RGB(192, 192, 192)); |
| 388 | if (Editor_view_mode == VM_TERRAIN) |
| 389 | dc->TextOut(10, 10, "Topographical", lstrlen("Topographical")); |
| 390 | else |
| 391 | dc->TextOut(10, 10, m_Name, lstrlen(m_Name)); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // These functions handle special mouse operations within the wireframe window |
| 396 | void EndWireframeSel(editorSelectorManager *esm); |
| 397 | |
| 398 | void CWireframeGrWnd::OnLButtonDown(UINT nFlags, CPoint point) { |
| 399 | if (Editor_view_mode == VM_TERRAIN) { |
| 400 | if (KEY_STATE(KEY_LCTRL)) { |
| 401 | int cellnum = GetCellFromPoint(point.x, point.y); |
| 402 | vector pos; |
| 403 | |
| 404 | ComputeTerrainSegmentCenter(&pos, cellnum); |
| 405 | ObjSetPos(Viewer_object, &pos, MAKE_ROOMNUM(cellnum), NULL, false); |
| 406 | |
| 407 | State_changed = 1; |
| 408 | } else if (KEY_STATE(KEY_LSHIFT)) { |
| 409 | int seg = GetCellFromPoint(point.x, point.y); |
| 410 | |
| 411 | Terrain_tex_seg[Terrain_seg[seg].texseg_index].tex_index = D3EditState.texdlg_texture; |
| 412 | World_changed = 1; |
| 413 | |
| 414 | } else |
| 415 | SelManager.StartSelection(this, EndWireframeSel, point.x, point.y); |
| 416 | |
| 417 | } else // mine or room mode |
| 418 | { |
| 419 | int found_segnum, found_facenum; |
| 420 | int find_mode = FM_CLOSEST; |
| 421 | |
| 422 | // See if we're clicking on the current face |
| 423 | found_segnum = ROOMNUM(Curroomp); |
| 424 | found_facenum = Curface; |
| 425 | if (WireframeFindRoomFace(m_grViewport, point.x, point.y, &found_segnum, &found_facenum, FM_SPECIFIC)) { |
| 426 | find_mode = FM_NEXT; |
| 427 | } |
| 428 | |
| 429 | find_again:; |
| 430 | |
| 431 | if (WireframeFindRoomFace(m_grViewport, point.x, point.y, &found_segnum, &found_facenum, find_mode)) { |
| 432 | if (KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT)) { // ctrl + click means toggle select state |
| 433 | int newstate; |
| 434 | newstate = ToggleRoomSelectedState(found_segnum); |
| 435 | State_changed = 1; |
| 436 | EditorStatus("Room %d %s", found_segnum, newstate ? "selected" : "deselected"); |
| 437 | } else { |
| 438 | if (Editor_view_mode == VM_ROOM) { |
| 439 | ASSERT(found_segnum == D3EditState.current_room); |
| 440 | Current_faces[D3EditState.current_room - FIRST_PALETTE_ROOM] = found_facenum; |
| 441 | EditorStatus("Current face set to %d", found_facenum); |
| 442 | } else { |
| 443 | Curroomp = &Rooms[found_segnum]; |
| 444 | Curface = found_facenum; |
| 445 | Curedge = Curvert = 0; |
| 446 | Curportal = -1; |
| 447 | EditorStatus("Current room:face set to %d:%d", ROOMNUM(Curroomp), Curface); |
| 448 | } |
| 449 | State_changed = 1; |
| 450 | } |
| 451 | } else if (find_mode == FM_NEXT) { |
| 452 | find_mode = FM_CLOSEST; |
| 453 | goto find_again; |
| 454 | } |
| 455 | |
| 456 | // no more dragging, but something is highlighted. |
| 457 | // so we will redraw world if mouse is pressed |
| 458 | |
| 459 | SelManager.StartSelection(this, EndWireframeSel, point.x, point.y); |
| 460 | } |
| 461 | |
| 462 | CWnd::OnLButtonDown(nFlags, point); |
| 463 | } |
| 464 | |
| 465 | void CWireframeGrWnd::OnMouseMove(UINT nFlags, CPoint point) { |
| 466 | if (Editor_view_mode == VM_TERRAIN) |
| 467 | DrawIntoTopoMap(point.x, point.y); |
| 468 | CWnd::OnMouseMove(nFlags, point); |
| 469 | } |
| 470 | |
| 471 | void CWireframeGrWnd::OnLButtonUp(UINT nFlags, CPoint point) { CWnd::OnLButtonUp(nFlags, point); } |
| 472 | |
| 473 | // How big a box needs to be before we recognize it |
| 474 | #define MIN_BOX_SIZE 3 |
| 475 | |
| 476 | void EndWireframeSel(editorSelectorManager *esm) { |
| 477 | int left, top, right, bot; |
| 478 | int n; |
| 479 | |
| 480 | esm->GetSelectedRect(&left, &top, &right, &bot); |
| 481 | |
| 482 | if ((right - left < MIN_BOX_SIZE) || (bot - top < MIN_BOX_SIZE)) |
| 483 | return; |
| 484 | |
| 485 | if (Editor_view_mode == VM_TERRAIN) { |
| 486 | int i; |
| 487 | |
| 488 | if (!(KEY_STATE(KEY_RALT))) { |
| 489 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) |
| 490 | TerrainSelected[i] = 0; |
| 491 | Num_terrain_selected = 0; |
| 492 | } |
| 493 | |
| 494 | RECT rect; |
| 495 | int x1, y1, x2, y2; |
| 496 | esm->m_OwnerWnd->GetWindowRect(&rect); |
| 497 | esm->m_OwnerWnd->ScreenToClient(&rect); |
| 498 | theApp.wireframe_view->GetMagCoords(&x1, &y1, &x2, &y2); |
| 499 | |
| 500 | float xstep = (float)(x2 - x1) / (float)rect.right; |
| 501 | float ystep = (float)(abs(y2 - y1)) / (float)rect.bottom; |
| 502 | |
| 503 | left *= xstep; |
| 504 | right *= xstep; |
| 505 | top *= ystep; |
| 506 | bot *= ystep; |
| 507 | |
| 508 | left += x1; |
| 509 | right += x1; |
| 510 | top += y1; |
| 511 | bot += y1; |
| 512 | |
| 513 | // We switch top and bottom due to the fact that our origin is in the bottom |
| 514 | // left instead of the top left |
| 515 | bot = (TERRAIN_DEPTH - 1) - bot; |
| 516 | top = (TERRAIN_DEPTH - 1) - top; |
| 517 | |
| 518 | int t; |
| 519 | int state = 1; |
| 520 | if (KEY_STATE(KEY_RALT)) |
| 521 | state = 0; |
| 522 | |
| 523 | for (i = bot; i <= top; i++) { |
| 524 | for (t = left; t <= right; t++) { |
| 525 | if (!state) { |
| 526 | if (TerrainSelected[i * TERRAIN_WIDTH + t]) |
| 527 | Num_terrain_selected--; |
| 528 | TerrainSelected[i * TERRAIN_WIDTH + t] = 0; |
| 529 | } else { |
| 530 | TerrainSelected[i * TERRAIN_WIDTH + t] = 1; |
| 531 | Num_terrain_selected++; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | if (KEY_STATE(KEY_LALT)) { |
| 537 | |
| 538 | theApp.wireframe_view->SetMagCoords(left, (TERRAIN_DEPTH - 1) - top, right, (TERRAIN_DEPTH - 1) - bot); |
| 539 | } |
| 540 | |
| 541 | World_changed = 1; |
| 542 | } else { |
| 543 | if (!(KEY_STATE(KEY_LCTRL) || KEY_STATE(KEY_RCTRL))) // ctrl + select means add to list |
| 544 | ClearRoomSelectedList(); |
| 545 | |
| 546 | n = SelectRoomsInBox(NULL, left, top, right, bot); |
| 547 | EditorStatus("%d rooms selected", n); |
| 548 | } |
| 549 | |
| 550 | esm->EndSelection(); |
| 551 | } |
| 552 | |
| 553 | void CWireframeGrWnd::DrawPlayerOnTerrain() { |
| 554 | static int lastx = -1, lastz = -1; |
| 555 | static uint16_t last_color; |
| 556 | |
| 557 | int seg = GetTerrainCellFromPos(&Viewer_object->pos); |
| 558 | if (seg < 0) |
| 559 | return; |
| 560 | |
| 561 | int x = seg % TERRAIN_WIDTH; |
| 562 | int z = seg / TERRAIN_WIDTH; |
| 563 | |
| 564 | // x-=(m_x1); |
| 565 | // z-=m_y1; |
| 566 | |
| 567 | z = (TERRAIN_DEPTH - 1) - z; |
| 568 | |
| 569 | RECT rect; |
| 570 | |
| 571 | GetWindowRect(&rect); |
| 572 | ScreenToClient(&rect); |
| 573 | |
| 574 | float xstep = (float)(m_x2 - m_x1) / (float)(rect.right - rect.left); |
| 575 | float ystep = (float)(abs(m_y2 - m_y1)) / (float)(rect.bottom - rect.top); |
| 576 | |
| 577 | m_grViewport->lock(); |
| 578 | |
| 579 | x = (float)x / xstep; |
| 580 | z = (float)z / ystep; |
| 581 | |
| 582 | if (x < 0 || x > rect.right) |
| 583 | goto getout; |
| 584 | if (z < 0 || z > rect.bottom) |
| 585 | goto getout; |
| 586 | |
| 587 | if (lastx != -1 && lastx < (rect.right - rect.left) && lastz < (rect.bottom - rect.top)) |
| 588 | m_grViewport->setpixel(last_color, lastx, lastz); |
| 589 | |
| 590 | lastx = x; |
| 591 | lastz = z; |
| 592 | last_color = m_grViewport->getpixel(lastx, lastz); |
| 593 | |
| 594 | m_grViewport->setpixel(GR_RGB(255, 255, 255), x, z); |
| 595 | |
| 596 | getout: |
| 597 | m_grViewport->unlock(); |
| 598 | m_grScreen->flip(); |
| 599 | } |
| 600 | |
| 601 | void DrawPlayerOnWireframe() { |
| 602 | if (theApp.wireframe_view) |
| 603 | theApp.wireframe_view->DrawPlayerOnTerrain(); |
| 604 | } |
| 605 | |
| 606 | void CWireframeGrWnd::GetMagCoords(int *x1, int *y1, int *x2, int *y2) { |
| 607 | *x1 = m_x1; |
| 608 | *x2 = m_x2; |
| 609 | *y1 = m_y1; |
| 610 | *y2 = m_y2; |
| 611 | } |
| 612 | void CWireframeGrWnd::SetMagCoords(int x1, int y1, int x2, int y2) { |
| 613 | m_x1 = x1; |
| 614 | m_x2 = x2; |
| 615 | m_y1 = y1; |
| 616 | m_y2 = y2; |
| 617 | } |
| 618 | |
| 619 | // Redraws only one terrain cell in the wireframe view |
| 620 | void CWireframeGrWnd::DrawTerrainCell(int seg) { |
| 621 | grSurface *cur_surf; |
| 622 | uint16_t *destptr; |
| 623 | int i, t, x, y; |
| 624 | int segx = seg % TERRAIN_WIDTH; |
| 625 | int segz = seg / TERRAIN_WIDTH; |
| 626 | |
| 627 | cur_surf = m_grViewport->lock(); |
| 628 | destptr = (uint16_t *)cur_surf->data(); |
| 629 | int rowsize = cur_surf->rowsize() / 2; |
| 630 | int x1, y1, x2, y2; |
| 631 | |
| 632 | theApp.wireframe_view->GetMagCoords(&x1, &y1, &x2, &y2); |
| 633 | |
| 634 | fix xstep = IntToFix(x2 - x1) / cur_surf->width(); |
| 635 | fix ystep = IntToFix(abs(y2 - y1)) / cur_surf->height(); |
| 636 | |
| 637 | float cellwidth = 1.0 / FixToFloat(xstep); |
| 638 | float cellheight = 1.0 / FixToFloat(ystep); |
| 639 | |
| 640 | int ystart = cellheight * (((TERRAIN_DEPTH - 1) - segz) - y1); |
| 641 | int xstart = cellwidth * (segx - x1); |
| 642 | |
| 643 | cellheight = ceil(cellheight); |
| 644 | cellwidth = ceil(cellwidth); |
| 645 | |
| 646 | x = segx; |
| 647 | y = segz; // flip due to origin difference |
| 648 | uint16_t fadepixel = 0; |
| 649 | |
| 650 | int bm_handle = GameTextures[Terrain_tex_seg[Terrain_seg[(y * TERRAIN_WIDTH + x)].texseg_index].tex_index].bm_handle; |
| 651 | |
| 652 | uint16_t pix = *bm_data(bm_handle, 0); |
| 653 | |
| 654 | if (TerrainSelected[y * TERRAIN_WIDTH + x]) { |
| 655 | int red = ((fadepixel >> 10) & 0x1f) << 3; |
| 656 | int green = ((fadepixel >> 5) & 0x1f) << 3; |
| 657 | int blue = (fadepixel & 0x1f) << 3; |
| 658 | |
| 659 | red <<= 2; |
| 660 | green <<= 2; |
| 661 | blue <<= 2; |
| 662 | |
| 663 | red = std::min(255, red); |
| 664 | green = std::min(255, green); |
| 665 | blue = std::min(255, blue); |
| 666 | |
| 667 | fadepixel = GR_RGB16(red, green, blue); |
| 668 | } |
| 669 | |
| 670 | for (i = 0; i < (int)cellheight; i++) |
| 671 | for (t = 0; t < (int)cellwidth; t++) { |
| 672 | |
| 673 | destptr[(i + ystart) * rowsize + t + xstart] = fadepixel; |
| 674 | } |
| 675 | m_grViewport->unlock(); |
| 676 | } |
| 677 | /* |
| 678 | |
| 679 | // draws a topographical representation of our terrain in the wireframe window |
| 680 | void CWireframeGrWnd::DrawTerrainWorld(grViewport *vp,vector *view_target,matrix *view_orient,float view_dist) |
| 681 | { |
| 682 | grSurface *cur_surf; |
| 683 | uint16_t *destptr; |
| 684 | int lightval; |
| 685 | int i,t; |
| 686 | |
| 687 | cur_surf=vp->lock(); |
| 688 | destptr=(uint16_t*)cur_surf->data(); |
| 689 | int rowsize=cur_surf->rowsize()/2; |
| 690 | int x1,y1,x2,y2; |
| 691 | |
| 692 | theApp.wireframe_view->GetMagCoords (&x1,&y1,&x2,&y2); |
| 693 | |
| 694 | fix xstep=IntToFix(x2-x1)/cur_surf->width(); |
| 695 | fix ystep=IntToFix(abs(y2-y1))/cur_surf->height(); |
| 696 | fix u=IntToFix (x1); |
| 697 | fix v=IntToFix (y1); |
| 698 | |
| 699 | for (i=0;i<cur_surf->height();i++,v+=ystep,u=IntToFix(x1)) |
| 700 | for (t=0;t<cur_surf->width();t++,u+=xstep) |
| 701 | { |
| 702 | int x,y; |
| 703 | x=FixToInt (u); |
| 704 | y=FixToInt (v); |
| 705 | |
| 706 | y=(TERRAIN_DEPTH-1)-y; // flip due to origin difference |
| 707 | |
| 708 | uint16_t fadepixel; |
| 709 | |
| 710 | int bm_handle=GameTextures[Terrain_seg[y*TERRAIN_WIDTH+x].tex_index].bm_handle; |
| 711 | lightval=(Terrain_seg[y*TERRAIN_WIDTH+x].light)*(MAX_TEXTURE_SHADES-1); |
| 712 | |
| 713 | uint16_t pix; |
| 714 | |
| 715 | pix=*bm_data(bm_handle,0); |
| 716 | fadepixel=(TexShadeTable16[lightval][pix>>8])+TexShadeTable8[lightval][pix & 0xFF]; |
| 717 | |
| 718 | |
| 719 | if (TerrainSelected[y*TERRAIN_WIDTH+x]) |
| 720 | { |
| 721 | int red=(fadepixel>>11)<<3; |
| 722 | int green=((fadepixel >> 5)&0x3f)<<2; |
| 723 | int blue=(fadepixel & 0x1f)<<3; |
| 724 | |
| 725 | red<<=2; |
| 726 | green<<=2; |
| 727 | blue<<=2; |
| 728 | |
| 729 | red=std::min(255,red); |
| 730 | green=std::min(255,green); |
| 731 | blue=std::min(255,blue); |
| 732 | |
| 733 | |
| 734 | |
| 735 | fadepixel=GR_RGB16(red,green,blue); |
| 736 | } |
| 737 | |
| 738 | |
| 739 | destptr[i*rowsize+t]=fadepixel; |
| 740 | } |
| 741 | vp->unlock(); |
| 742 | |
| 743 | }*/ |
| 744 | |
| 745 | // draws a topographical representation of our terrain in the wireframe window |
| 746 | void CWireframeGrWnd::DrawTerrainWorld(grViewport *vp, vector *view_target, matrix *view_orient, float view_dist) { |
| 747 | grSurface *cur_surf; |
| 748 | uint16_t *destptr; |
| 749 | float lightval; |
| 750 | int i, t; |
| 751 | |
| 752 | cur_surf = vp->lock(); |
| 753 | destptr = (uint16_t *)cur_surf->data(); |
| 754 | int rowsize = cur_surf->rowsize() / 2; |
| 755 | int x1, y1, x2, y2; |
| 756 | |
| 757 | theApp.wireframe_view->GetMagCoords(&x1, &y1, &x2, &y2); |
| 758 | |
| 759 | fix xstep = IntToFix(x2 - x1) / cur_surf->width(); |
| 760 | fix ystep = IntToFix(abs(y2 - y1)) / cur_surf->height(); |
| 761 | fix u = IntToFix(x1); |
| 762 | fix v = IntToFix(y1); |
| 763 | |
| 764 | fix subx, suby; |
| 765 | |
| 766 | for (i = 0; i < cur_surf->height(); i++, v += ystep, u = IntToFix(x1)) |
| 767 | for (t = 0; t < cur_surf->width(); t++, u += xstep) { |
| 768 | int x, y; |
| 769 | x = FixToInt(u); |
| 770 | y = FixToInt(v); |
| 771 | |
| 772 | y = (TERRAIN_DEPTH - 1) - y; // flip due to origin difference |
| 773 | |
| 774 | uint16_t fadepixel; |
| 775 | |
| 776 | int bm_handle = |
| 777 | GameTextures[Terrain_tex_seg[Terrain_seg[y * TERRAIN_WIDTH + x].texseg_index].tex_index].bm_handle; |
| 778 | lightval = Ubyte_to_float[(Terrain_seg[y * TERRAIN_WIDTH + x].l)]; |
| 779 | |
| 780 | uint16_t pix; |
| 781 | uint16_t *data = bm_data(bm_handle, 0); |
| 782 | int w = bm_w(bm_handle, 0); |
| 783 | |
| 784 | subx = (u & 0xFFFF) * w; |
| 785 | suby = (v & 0xFFFF) * bm_h(bm_handle, 0); |
| 786 | subx >>= 16; |
| 787 | suby >>= 16; |
| 788 | |
| 789 | pix = data[suby * w + subx]; |
| 790 | ddgr_color pix32 = GR_16_TO_COLOR(pix); |
| 791 | |
| 792 | int pred = (GR_COLOR_RED(pix32) * lightval); |
| 793 | int pgreen = (GR_COLOR_GREEN(pix32) * lightval); |
| 794 | int pblue = (GR_COLOR_BLUE(pix32) * lightval); |
| 795 | |
| 796 | fadepixel = GR_RGB16(pred, pgreen, pblue); |
| 797 | |
| 798 | if (TerrainSelected[y * TERRAIN_WIDTH + x]) { |
| 799 | int red = ((fadepixel >> 10) & 0x1f) << 3; |
| 800 | int green = ((fadepixel >> 5) & 0x1f) << 3; |
| 801 | int blue = (fadepixel & 0x1f) << 3; |
| 802 | |
| 803 | red <<= 2; |
| 804 | green <<= 2; |
| 805 | blue <<= 2; |
| 806 | |
| 807 | red = std::min(255, red); |
| 808 | green = std::min(255, green); |
| 809 | blue = std::min(255, blue); |
| 810 | |
| 811 | fadepixel = GR_RGB16(red, green, blue); |
| 812 | } |
| 813 | |
| 814 | if (Terrain_seg[y * TERRAIN_WIDTH + x].objects != -1) { |
| 815 | object *obj = &Objects[Terrain_seg[y * TERRAIN_WIDTH + x].objects]; |
| 816 | |
| 817 | if (obj->type == OBJ_ROBOT) |
| 818 | fadepixel = GR_RGB16(255, 0, 0); |
| 819 | else if (obj->type == OBJ_POWERUP) |
| 820 | fadepixel = GR_RGB16(0, 128, 255); |
| 821 | else if (obj->type == OBJ_PLAYER || obj->type == OBJ_GHOST) |
| 822 | fadepixel = GR_RGB16(0, 255, 0); |
| 823 | else if (obj->type == OBJ_CLUTTER) |
| 824 | fadepixel = GR_RGB16(255, 0, 255); |
| 825 | } |
| 826 | |
| 827 | destptr[i * rowsize + t] = fadepixel; |
| 828 | } |
| 829 | vp->unlock(); |
| 830 | } |
| 831 | |
| 832 | void CWireframeGrWnd::OnRButtonDown(UINT nFlags, CPoint point) { |
| 833 | if (Editor_view_mode == VM_TERRAIN) { |
| 834 | m_x1 = 0; |
| 835 | m_y1 = 0; |
| 836 | m_x2 = TERRAIN_WIDTH; |
| 837 | m_y2 = TERRAIN_DEPTH; |
| 838 | |
| 839 | State_changed = 1; |
| 840 | } |
| 841 | CWnd::OnRButtonDown(nFlags, point); |
| 842 | } |
| 843 | |
| 844 | // Lets the user draw free hand into the topographical map |
| 845 | void DrawIntoTopoMap(int x, int y) { |
| 846 | int i, t, segx, segz; |
| 847 | |
| 848 | if (KEY_STATE(KEY_LSHIFT)) { |
| 849 | int seg = theApp.wireframe_view->GetCellFromPoint(x, y); |
| 850 | if (seg < 0 || seg >= TERRAIN_WIDTH * TERRAIN_DEPTH) |
| 851 | Int3(); // get Jason |
| 852 | |
| 853 | for (i = -1; i <= 1; i++) { |
| 854 | for (t = -1; t <= 1; t++) { |
| 855 | segx = seg % TERRAIN_WIDTH; |
| 856 | segz = seg / TERRAIN_WIDTH; |
| 857 | |
| 858 | if ((segz + i) < 0 || segz + i >= TERRAIN_DEPTH) |
| 859 | continue; |
| 860 | if ((segx + t) < 0 || segx + t >= TERRAIN_WIDTH) |
| 861 | continue; |
| 862 | |
| 863 | segz += i; |
| 864 | segx += t; |
| 865 | |
| 866 | Terrain_tex_seg[Terrain_seg[(segz * TERRAIN_WIDTH) + segx].texseg_index].tex_index = D3EditState.texdlg_texture; |
| 867 | theApp.wireframe_view->DrawTerrainCell((segz * TERRAIN_WIDTH) + segx); |
| 868 | } |
| 869 | } |
| 870 | theApp.wireframe_view->Invalidate(); |
| 871 | } |
| 872 | } |