World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Файл MapBook.cpp

См. исходные тексты.

Функции

void DrawBook_Map_sub (unsigned int tl_x, unsigned int tl_y, unsigned int br_x, int br_y, int dummy)
 
const char * GetMapBookHintText (int mouse_x, int mouse_y)
 

Переменные

Imageui_book_map_background = nullptr
 

Функции

◆ DrawBook_Map_sub()

void DrawBook_Map_sub ( unsigned int  tl_x,
unsigned int  tl_y,
unsigned int  br_x,
int  br_y,
int  dummy 
)

См. определение в файле MapBook.cpp строка 180

180  {
181  int ScreenCenterX = (signed int)(tl_x + br_x) / 2;
182  int ScreenCenterY = (signed int)(tl_y + br_y) / 2;
183  render->SetUIClipRect(tl_x, tl_y, br_x, br_y);
184 
185  int pCenterX = viewparams->sViewCenterX;
186  int pCenterY = viewparams->sViewCenterY;
187 
188  if (viewparams->uMapBookMapZoom == 384) {
189  pCenterX = viewparams->indoor_center_x;
190  pCenterY = viewparams->indoor_center_y;
191  }
192 
193  if (uCurrentlyLoadedLevelType != LEVEL_Indoor) { // outdoors
194  int screenWidth = br_x - tl_x + 1;
195  int screenHeight = br_y - tl_y + 1;
196 
198  int scale_increment = (1 << (loc_power + 16)) / viewparams->uMapBookMapZoom;
199  double MapSizeScale = (double)(1 << (16 - loc_power));
200  int stepX_r_resets =
201  (unsigned int)(signed __int64)
202  ((double)(pCenterX - 22528 / (viewparams->uMapBookMapZoom / 384) + 32768) / MapSizeScale) << 16;
203  int stepY_r = (int)(signed __int64)
204  ((double)(-pCenterY - 22528 / (viewparams->uMapBookMapZoom / 384) + 32768) / MapSizeScale) << 16;
205  int scaled_posY = stepY_r >> 16;
206 
207  static Texture *minimaptemp = nullptr;
208  if (!minimaptemp) {
209  minimaptemp = render->CreateTexture_Blank(screenWidth, screenHeight, IMAGE_FORMAT_A8R8G8B8);
210  }
211  auto minitempix = (unsigned __int32 *)minimaptemp->GetPixels(IMAGE_FORMAT_A8R8G8B8);
212  auto minimap_pixels = (unsigned __int32 *)viewparams->location_minimap->GetPixels(IMAGE_FORMAT_A8R8G8B8);
213  int textr_width = viewparams->location_minimap->GetWidth();
214 
215  // nearest neiborhood scaling
216  // if (texture8_data)
217  {
218  for (uint i = 0; i < screenHeight; ++i) {
219  int map_tile_Y = (scaled_posY - 80) / 4;
220  int stepX_r = stepX_r_resets;
221  for (uint j = 0; j < screenWidth; ++j) {
222  int scaled_posX = stepX_r >> 16;
223  int map_tile_X = (scaled_posX - 80) / 4;
224  if (!pOutdoor->IsMapCellFullyRevealed(map_tile_X, map_tile_Y)) {
225  if (pOutdoor->IsMapCellPartiallyRevealed(map_tile_X,
226  map_tile_Y)) {
227  if (!((i + ScreenCenterX + j) % 2))
228  minitempix[j + i * screenWidth] = Color32(12, 12, 12); // greyed out
229  else
230  minitempix[j + i * screenWidth] = minimap_pixels[scaled_posX + scaled_posY * textr_width];
231  } else {
232  minitempix[j + i * screenWidth] = Color32(0, 0, 0); // black
233  }
234  } else {
235  minitempix[j + i * screenWidth] = minimap_pixels[scaled_posX + scaled_posY * textr_width];
236  }
237  stepX_r += scale_increment;
238  }
239  stepY_r += scale_increment;
240  scaled_posY = stepY_r >> 16;
241  }
242  }
243 
244  render->Update_Texture(minimaptemp);
245  render->DrawTextureAlphaNew(tl_x / 640., tl_y / 480., minimaptemp);
246  } else { // indoors
247  unsigned int Colour_Black = Color16(0, 0, 0);
248 
250  for (uint i = 0; i < pIndoor->pMapOutlines->uNumOutlines; ++i) {
251  BLVMapOutline *pOutline = &pIndoor->pMapOutlines->pOutlines[i];
252 
253  if (pIndoor->pFaces[pOutline->uFace1ID].Visible() &&
254  pIndoor->pFaces[pOutline->uFace2ID].Visible()) {
255  if (pIndoor->pFaces[pOutline->uFace1ID].uAttributes & FACE_RENDERED ||
256  pIndoor->pFaces[pOutline->uFace2ID].uAttributes & FACE_RENDERED) {
257  pOutline->uFlags = pOutline->uFlags | 1;
258  pIndoor->_visible_outlines[i >> 3] |= 1 << (7 - i % 8);
259 
260  int Vert1X = pIndoor->pVertices[pOutline->uVertex1ID].x - pCenterX;
261  int Vert2X = pIndoor->pVertices[pOutline->uVertex2ID].x - pCenterX;
262  int Vert1Y = pIndoor->pVertices[pOutline->uVertex1ID].y - pCenterY;
263  int Vert2Y = pIndoor->pVertices[pOutline->uVertex2ID].y - pCenterY;
264 
265  int linex = ScreenCenterX + fixpoint_mul(Vert1X, viewparams->uMapBookMapZoom);
266  int liney = ScreenCenterY - fixpoint_mul(Vert1Y, viewparams->uMapBookMapZoom);
267  int linez = ScreenCenterX + fixpoint_mul(Vert2X, viewparams->uMapBookMapZoom);
268  int linew = ScreenCenterY - fixpoint_mul(Vert2Y, viewparams->uMapBookMapZoom);
269 
270  render->RasterLine2D(linex, liney, linez, linew, Colour_Black);
271  }
272  }
273  }
274  }
275  }
276 
277  // Direction arrow drawing
278  int ArrowXPos = (fixpoint_mul((pParty->vPosition.x - pCenterX), viewparams->uMapBookMapZoom)) + ScreenCenterX - 3;
279  int ArrowYPos = ScreenCenterY - (fixpoint_mul((pParty->vPosition.y - pCenterY), viewparams->uMapBookMapZoom)) - 3;
280  bool DrawArrow = 1;
281 
282  if (ArrowXPos >= (signed int)tl_x) {
283  if (ArrowXPos > (signed int)br_x) {
284  if ((signed int)(ArrowXPos - 3) > (signed int)br_x) DrawArrow = 0;
285  ArrowXPos = br_x;
286  }
287  } else {
288  if ((signed int)(ArrowXPos + 3) < (signed int)tl_x) DrawArrow = 0;
289  ArrowXPos = tl_x;
290  }
291 
292  if (ArrowYPos >= (signed int)tl_y) {
293  if (ArrowYPos > br_y) {
294  if ((ArrowYPos - 3) > br_y) DrawArrow = 0;
295  ArrowYPos = br_y;
296  }
297  } else {
298  if ((ArrowYPos + 3) < (signed int)tl_y) DrawArrow = 0;
299  ArrowYPos = tl_y;
300  }
301 
302  if (DrawArrow == 1) {
303  int ArrowOctant = 0;
304  int PartyDirection = pParty->sRotationY & stru_5C6E00->uDoublePiMask;
305  if ((signed int)PartyDirection <= 1920) ArrowOctant = 6;
306  if ((signed int)PartyDirection < 1664) ArrowOctant = 5;
307  if ((signed int)PartyDirection <= 1408) ArrowOctant = 4;
308  if ((signed int)PartyDirection < 1152) ArrowOctant = 3;
309  if ((signed int)PartyDirection <= 896) ArrowOctant = 2;
310  if ((signed int)PartyDirection < 640) ArrowOctant = 1;
311  if ((signed int)PartyDirection <= 384) ArrowOctant = 0;
312  if ((signed int)PartyDirection < 128 || (signed int)PartyDirection > 1920) ArrowOctant = 7;
313 
314  render->DrawTransparentRedShade(ArrowXPos / 640.0f, ArrowYPos / 480.0f, game_ui_minimap_dirs[ArrowOctant]);
315  }
316 
317  if ((signed int)uNumLevelDecorations > 0) {
318  for (uint i = 0; i < (signed int)uNumLevelDecorations; ++i) {
320  int DecY = pLevelDecorations[i].vPosition.y - pCenterY;
321  int DecX = pLevelDecorations[i].vPosition.x - pCenterX;
322  int decxpos = ScreenCenterX + fixpoint_mul(DecX, viewparams->uMapBookMapZoom);
323  int decypos = ScreenCenterY - fixpoint_mul(DecY, viewparams->uMapBookMapZoom);
324 
325  if (viewparams->uMapBookMapZoom > 512) {
326  render->RasterLine2D(decxpos - 1, decypos - 1, decxpos - 1, decypos + 1, Color16(0xFFu, 0xFFu, 0xFFu));
327  render->RasterLine2D(decxpos, decypos - 1, decxpos, decypos + 1, Color16(0xFFu, 0xFFu, 0xFFu));
328  render->RasterLine2D(decxpos + 1, decypos - 1, decxpos + 1, decypos + 1, Color16(0xFFu, 0xFFu, 0xFFu));
329  } else {
330  render->RasterLine2D(decxpos, decypos, decxpos, decypos, Color16(0xFF, 0xFF, 0xFF));
331  }
332  }
333  }
334  }
335 }

Перекрестные ссылки IndoorLocation::_visible_outlines, Color16(), Color32(), fixpoint_mul(), game_ui_minimap_dirs, Image::GetPixels(), Image::GetWidth(), ImageHelper::GetWidthLn2(), IMAGE_FORMAT_A8R8G8B8, ViewingParams::indoor_center_x, ViewingParams::indoor_center_y, OutdoorLocation::IsMapCellFullyRevealed(), OutdoorLocation::IsMapCellPartiallyRevealed(), LEVEL_DECORATION_VISIBLE_ON_MAP, LEVEL_Indoor, ViewingParams::location_minimap, IndoorLocation::pFaces, pIndoor, pLevelDecorations, IndoorLocation::pMapOutlines, pOutdoor, BLVMapOutlines::pOutlines, pParty, IndoorLocation::pVertices, render, Party::sRotationY, stru_5C6E00, ViewingParams::sViewCenterX, ViewingParams::sViewCenterY, BLVFace::uAttributes, uCurrentlyLoadedLevelType, stru193_math::uDoublePiMask, BLVMapOutline::uFace1ID, BLVMapOutline::uFace2ID, BLVMapOutline::uFlags, ViewingParams::uMapBookMapZoom, uNumLevelDecorations, BLVMapOutlines::uNumOutlines, BLVMapOutline::uVertex1ID, BLVMapOutline::uVertex2ID, viewparams, BLVFace::Visible() и Party::vPosition.

Используется в GUIWindow_MapBook::Update().

+ Граф вызовов:
+ Граф вызова функции:

◆ GetMapBookHintText()

const char* GetMapBookHintText ( int  mouse_x,
int  mouse_y 
)

См. определение в файле MapBook.cpp строка 337

337  {
338  int v20 = viewparams->sViewCenterX;
339  int v21 = viewparams->sViewCenterY;
340  if (viewparams->uMapBookMapZoom == 384) {
343  }
344 
345  unsigned int pX = mouse_x;
346  unsigned int pY = mouse_y;
347 
348  double v0 = 1.0 / (float)((signed int)viewparams->uMapBookMapZoom * 0.000015258789);
349 
350  int global_coord_X = (__int64)((double)(pX - 229.) * v0 + (double)v20);
351  int global_coord_Y = (__int64)((double)v21 - (double)(pY - 181.) * v0);
352 
353  const char *result = "";
354 
355  // In the mapbook only lady Margaret dispays for defoult zoom(В
356  // книге карты только Леди Маргарита всплывает при дефолтном зуме)
357  int map_tile_X = abs(global_coord_X + 22528) / 512;
358  int map_tile_Y = abs(global_coord_Y - 22528) / 512;
359  if (pOutdoor->IsMapCellFullyRevealed(map_tile_X, map_tile_Y) &&
361  !pOutdoor->pBModels.empty()) {
362  for (BSPModel &model : pOutdoor->pBModels) {
364  abs((int)model.vBoundingCenter.x - global_coord_X),
365  abs((int)model.vBoundingCenter.y - global_coord_Y),
366  0) < model.sBoundingRadius) {
367  for (ODMFace &face : model.pFaces) {
368  if (face.sCogTriggeredID) {
369  if (!(face.uAttributes & FACE_HAS_EVENT)) {
370  if (GetEventHintString(face.sCogTriggeredID)) {
371  if (_stricmp(GetEventHintString(face.sCogTriggeredID), "")) {
372  result = GetEventHintString(face.sCogTriggeredID);
373  }
374  }
375  }
376  }
377  }
378  }
379  }
380  }
381 
382  return result;
383 }

Перекрестные ссылки GetEventHintString(), ViewingParams::indoor_center_x, ViewingParams::indoor_center_y, int_get_vector_length(), OutdoorLocation::IsMapCellFullyRevealed(), LEVEL_Outdoor, OutdoorLocation::pBModels, BSPModel::pFaces, pOutdoor, BSPModel::sBoundingRadius, ViewingParams::sViewCenterX, ViewingParams::sViewCenterY, uCurrentlyLoadedLevelType, ViewingParams::uMapBookMapZoom, BSPModel::vBoundingCenter и viewparams.

Используется в UI_OnMouseRightClick().

+ Граф вызовов:
+ Граф вызова функции:

Переменные

◆ ui_book_map_background

Image* ui_book_map_background = nullptr

См. определение в файле MapBook.cpp строка 27

Используется в GUIWindow_MapBook::GUIWindow_MapBook() и GUIWindow_MapBook::Update().

Party::vPosition
Vec3_int_ vPosition
Definition: Party.h:250
face
GLenum GLuint GLint GLenum face
Definition: SDL_opengl_glext.h:3022
int_get_vector_length
uint32_t int_get_vector_length(int32_t x, int32_t y, int32_t z)
Definition: VectorTypes.cpp:8
pLevelDecorations
std::array< LevelDecoration, 3000 > pLevelDecorations
Definition: Decoration.cpp:8
stru193_math::uDoublePiMask
static const unsigned int uDoublePiMask
Definition: OurMath.h:91
OutdoorLocation::pBModels
BSPModelList pBModels
Definition: Outdoor.h:119
OutdoorLocation::IsMapCellPartiallyRevealed
bool IsMapCellPartiallyRevealed(signed int a2, signed int a3)
Definition: Outdoor.cpp:1559
ViewingParams::location_minimap
class Image * location_minimap
Definition: Viewport.h:73
BLVMapOutlines::uNumOutlines
int uNumOutlines
Definition: Indoor.h:569
Texture
Definition: Texture.h:4
ViewingParams::indoor_center_x
int16_t indoor_center_x
Definition: Viewport.h:70
BSPModel::sBoundingRadius
int32_t sBoundingRadius
Definition: BSPModel.h:187
Color32
uint32_t Color32(uint16_t color16)
Definition: Engine.cpp:135
OutdoorLocation::IsMapCellFullyRevealed
bool IsMapCellFullyRevealed(signed int a2, signed int a3)
Definition: Outdoor.cpp:1549
BLVMapOutline
Definition: Indoor.h:412
pIndoor
IndoorLocation * pIndoor
Definition: Indoor.cpp:49
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9435
ImageHelper::GetWidthLn2
static int GetWidthLn2(Image *img)
Definition: Image.h:59
IMAGE_FORMAT_A8R8G8B8
@ IMAGE_FORMAT_A8R8G8B8
Definition: Image.h:7
LEVEL_DECORATION_VISIBLE_ON_MAP
@ LEVEL_DECORATION_VISIBLE_ON_MAP
Definition: Decoration.h:12
Image::GetWidth
unsigned int GetWidth()
Definition: Image.cpp:217
game_ui_minimap_dirs
std::array< Image *, 8 > game_ui_minimap_dirs
Definition: UIGame.cpp:70
pParty
Party * pParty
Definition: Party.cpp:30
ViewingParams::indoor_center_y
int16_t indoor_center_y
Definition: Viewport.h:71
viewparams
struct ViewingParams * viewparams
Definition: mm7_data.cpp:22
BLVMapOutline::uFace2ID
uint16_t uFace2ID
Definition: Indoor.h:416
BLVMapOutline::uFace1ID
uint16_t uFace1ID
Definition: Indoor.h:415
GetEventHintString
char * GetEventHintString(unsigned int uEventID)
Definition: Events.cpp:1159
BLVMapOutline::uFlags
uint16_t uFlags
Definition: Indoor.h:418
IndoorLocation::pMapOutlines
BLVMapOutlines * pMapOutlines
Definition: Indoor.h:641
fixpoint_mul
__int64 fixpoint_mul(int a1, int a2)
Definition: OurMath.cpp:138
uNumLevelDecorations
size_t uNumLevelDecorations
Definition: Decoration.cpp:9
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
LEVEL_Outdoor
@ LEVEL_Outdoor
Definition: Indoor.h:287
IndoorLocation::_visible_outlines
char _visible_outlines[875]
Definition: Indoor.h:650
LEVEL_Indoor
@ LEVEL_Indoor
Definition: Indoor.h:286
BLVMapOutlines::pOutlines
BLVMapOutline pOutlines[7000]
Definition: Indoor.h:570
uint
unsigned int uint
Definition: MM7.h:4
BLVFace::Visible
bool Visible() const
Definition: Indoor.h:447
BSPModel::pFaces
std::vector< ODMFace > pFaces
Definition: BSPModel.h:190
ODMFace
Definition: BSPModel.h:93
BSPModel::vBoundingCenter
Vec3_int_ vBoundingCenter
Definition: BSPModel.h:186
Image::GetPixels
const void * GetPixels(IMAGE_FORMAT format)
Definition: Image.cpp:270
stru_5C6E00
struct stru193_math * stru_5C6E00
Definition: mm7_data.cpp:19
IndoorLocation::pVertices
struct Vec3_short_ * pVertices
Definition: Indoor.h:628
ViewingParams::sViewCenterY
int sViewCenterY
Definition: Viewport.h:69
uCurrentlyLoadedLevelType
LEVEL_TYPE uCurrentlyLoadedLevelType
Definition: Indoor.cpp:52
IndoorLocation::pFaces
struct BLVFace * pFaces
Definition: Indoor.h:630
ViewingParams::sViewCenterX
int sViewCenterX
Definition: Viewport.h:68
v0
GLfloat v0
Definition: SDL_opengl_glext.h:693
BSPModel
Definition: BSPModel.h:163
BLVMapOutline::uVertex2ID
uint16_t uVertex2ID
Definition: Indoor.h:414
Color16
uint16_t Color16(uint32_t r, uint32_t g, uint32_t b)
Definition: Engine.cpp:148
pOutdoor
OutdoorLocation * pOutdoor
Definition: Outdoor.cpp:48
ViewingParams::uMapBookMapZoom
unsigned int uMapBookMapZoom
Definition: Viewport.h:67
BLVMapOutline::uVertex1ID
uint16_t uVertex1ID
Definition: Indoor.h:413
Party::sRotationY
int sRotationY
Definition: Party.h:251
BLVFace::uAttributes
unsigned int uAttributes
Definition: Indoor.h:475
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52