MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / viewportsUpdatePosition

Method viewportsUpdatePosition

src/OpenLoco/src/Ui/Window.cpp:282–390  ·  view source on GitHub ↗

0x004C6456

Source from the content-addressed store, hash-verified

280
281 // 0x004C6456
282 void Window::viewportsUpdatePosition()
283 {
284 for (int i = 0; i < 2; i++)
285 {
286 Viewport* viewport = this->viewports[i];
287 ViewportConfig* config = &this->viewportConfigurations[i];
288
289 if (viewport == nullptr)
290 {
291 continue;
292 }
293
294 viewport_pos centre;
295
296 if (config->viewportTargetSprite != EntityId::null)
297 {
298 auto entity = EntityManager::get<EntityBase>(config->viewportTargetSprite);
299
300 int z = (TileManager::getHeight(entity->position).landHeight) - 16;
301 bool underground = (entity->position.z < z);
302
303 viewportSetUndergroundFlag(underground, viewport);
304
305 centre = viewport->centre2dCoordinates(entity->position + Pos3{ 0, 0, 12 });
306 }
307 else
308 {
309 int16_t midX = config->savedViewX + (viewport->viewWidth / 2);
310 int16_t midY = config->savedViewY + (viewport->viewHeight / 2);
311
312 World::Pos2 mapCoord = viewportCoordToMapCoord(midX, midY, 128, viewport->getRotation());
313 viewportSetUndergroundFlag(false, viewport);
314
315 bool atMapEdge = false;
316 if (mapCoord.x < -256)
317 {
318 mapCoord.x = -256;
319 atMapEdge = true;
320 }
321 if (mapCoord.y < -256)
322 {
323 mapCoord.y = -256;
324 atMapEdge = true;
325 }
326 if (mapCoord.x > 0x30FE)
327 {
328 mapCoord.x = 0x30FE;
329 atMapEdge = true;
330 }
331 if (mapCoord.y > 0x30FE)
332 {
333 mapCoord.y = 0x30FE;
334 atMapEdge = true;
335 }
336
337 if (atMapEdge)
338 {
339 auto coord_2d = gameToScreen({ mapCoord.x, mapCoord.y, 128 }, viewport->getRotation());

Callers 2

handleStepFunction · 0.80
updateViewportsFunction · 0.80

Calls 8

hasFlagsMethod · 0.95
getHeightFunction · 0.85
viewportCoordToMapCoordFunction · 0.85
gameToScreenFunction · 0.85
viewportMoveFunction · 0.85
centre2dCoordinatesMethod · 0.80
getRotationMethod · 0.45

Tested by

no test coverage detected