MCPcopy Create free account
hub / github.com/ddnet/ddnet / RenderSwitchEntities

Method RenderSwitchEntities

src/game/editor/editor.cpp:6929–6987  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6927}
6928
6929void CEditor::RenderSwitchEntities(const std::shared_ptr<CLayerTiles> &pTiles)
6930{
6931 const CGameClient *pGameClient = (CGameClient *)Kernel()->RequestInterface<IGameClient>();
6932 const float TileSize = 32.f;
6933
6934 std::function<unsigned char(int, int, unsigned char &)> GetIndex;
6935 if(pTiles->m_HasSwitch)
6936 {
6937 CLayerSwitch *pSwitchLayer = ((CLayerSwitch *)(pTiles.get()));
6938 GetIndex = [pSwitchLayer](int y, int x, unsigned char &Number) -> unsigned char {
6939 if(x < 0 || y < 0 || x >= pSwitchLayer->m_Width || y >= pSwitchLayer->m_Height)
6940 return 0;
6941 Number = pSwitchLayer->m_pSwitchTile[y * pSwitchLayer->m_Width + x].m_Number;
6942 return pSwitchLayer->m_pSwitchTile[y * pSwitchLayer->m_Width + x].m_Type - ENTITY_OFFSET;
6943 };
6944 }
6945 else
6946 {
6947 GetIndex = [pTiles](int y, int x, unsigned char &Number) -> unsigned char {
6948 if(x < 0 || y < 0 || x >= pTiles->m_Width || y >= pTiles->m_Height)
6949 return 0;
6950 Number = 0;
6951 return pTiles->m_pTiles[y * pTiles->m_Width + x].m_Index - ENTITY_OFFSET;
6952 };
6953 }
6954
6955 ivec2 aOffsets[] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
6956
6957 const ColorRGBA OuterColor = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClLaserDoorOutlineColor));
6958 const ColorRGBA InnerColor = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClLaserDoorInnerColor));
6959 const float TicksHead = Client()->GlobalTime() * Client()->GameTickSpeed();
6960
6961 for(int y = 0; y < pTiles->m_Height; y++)
6962 {
6963 for(int x = 0; x < pTiles->m_Width; x++)
6964 {
6965 unsigned char Number = 0;
6966 const unsigned char Index = GetIndex(y, x, Number);
6967
6968 if(Index == ENTITY_DOOR)
6969 {
6970 for(size_t i = 0; i < sizeof(aOffsets) / sizeof(ivec2); ++i)
6971 {
6972 unsigned char NumberDoorLength = 0;
6973 unsigned char IndexDoorLength = GetIndex(y + aOffsets[i].y, x + aOffsets[i].x, NumberDoorLength);
6974 if(IndexDoorLength >= ENTITY_LASER_SHORT && IndexDoorLength <= ENTITY_LASER_LONG)
6975 {
6976 float XOff = std::cos(i * pi / 4.0f);
6977 float YOff = std::sin(i * pi / 4.0f);
6978 int Length = (IndexDoorLength - ENTITY_LASER_SHORT + 1) * 3;
6979 vec2 Pos(x + 0.5f, y + 0.5f);
6980 vec2 To(x + XOff * Length + 0.5f, y + YOff * Length + 0.5f);
6981 pGameClient->m_Items.RenderLaser(To * TileSize, Pos * TileSize, OuterColor, InnerColor, 1.0f, TicksHead, (int)LASERTYPE_DOOR);
6982 }
6983 }
6984 }
6985 }
6986 }

Callers 1

RenderMethod · 0.80

Calls 7

GetIndexFunction · 0.85
getMethod · 0.80
GlobalTimeMethod · 0.80
RenderLaserMethod · 0.80
ClientFunction · 0.70
ColorHSLAClass · 0.50
GameTickSpeedMethod · 0.45

Tested by

no test coverage detected