MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / queueUpdatePackets

Method queueUpdatePackets

source/game/StarWorldServer.cpp:1900–2008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1898}
1899
1900void WorldServer::queueUpdatePackets(ConnectionId clientId, bool sendRemoteUpdates) {
1901 auto const& clientInfo = m_clientInfo.get(clientId);
1902 clientInfo->outgoingPackets.append(make_shared<StepUpdatePacket>(m_currentTime));
1903
1904 if (shouldRunThisStep("environmentUpdate")) {
1905 ByteArray skyDelta;
1906 tie(skyDelta, clientInfo->skyNetVersion) = m_sky->writeUpdate(clientInfo->skyNetVersion, clientInfo->clientState.netCompatibilityRules());
1907
1908 ByteArray weatherDelta;
1909 tie(weatherDelta, clientInfo->weatherNetVersion) = m_weather.writeUpdate(clientInfo->weatherNetVersion, clientInfo->clientState.netCompatibilityRules());
1910
1911 if (!skyDelta.empty() || !weatherDelta.empty())
1912 clientInfo->outgoingPackets.append(make_shared<EnvironmentUpdatePacket>(std::move(skyDelta), std::move(weatherDelta)));
1913 }
1914
1915 for (auto sector : clientInfo->pendingSectors.values()) {
1916 if (!m_worldStorage->sectorActive(sector))
1917 continue;
1918
1919 auto tileArrayUpdate = make_shared<TileArrayUpdatePacket>();
1920 auto sectorTiles = m_tileArray->sectorRegion(sector);
1921 tileArrayUpdate->min = sectorTiles.min();
1922 tileArrayUpdate->array.resize(Vec2S(sectorTiles.width(), sectorTiles.height()));
1923 for (int x = sectorTiles.xMin(); x < sectorTiles.xMax(); ++x) {
1924 for (int y = sectorTiles.yMin(); y < sectorTiles.yMax(); ++y)
1925 writeNetTile({x, y}, tileArrayUpdate->array(x - sectorTiles.xMin(), y - sectorTiles.yMin()));
1926 }
1927
1928 clientInfo->outgoingPackets.append(tileArrayUpdate);
1929 clientInfo->pendingSectors.remove(sector);
1930 }
1931
1932 for (auto pos : clientInfo->pendingTileUpdates) {
1933 auto tileUpdate = make_shared<TileUpdatePacket>();
1934 tileUpdate->position = pos;
1935 writeNetTile(pos, tileUpdate->tile);
1936
1937 clientInfo->outgoingPackets.append(tileUpdate);
1938 }
1939 clientInfo->pendingTileUpdates.clear();
1940
1941 for (auto pair : clientInfo->pendingTileDamageUpdates) {
1942 auto tile = m_tileArray->tile(pair.first);
1943 if (pair.second == TileLayer::Foreground)
1944 clientInfo->outgoingPackets.append(
1945 make_shared<TileDamageUpdatePacket>(pair.first, TileLayer::Foreground, tile.foregroundDamage));
1946 else
1947 clientInfo->outgoingPackets.append(
1948 make_shared<TileDamageUpdatePacket>(pair.first, TileLayer::Background, tile.backgroundDamage));
1949 }
1950 clientInfo->pendingTileDamageUpdates.clear();
1951
1952 for (auto pos : clientInfo->pendingLiquidUpdates) {
1953 auto tile = m_tileArray->tile(pos);
1954 clientInfo->outgoingPackets.append(make_shared<TileLiquidUpdatePacket>(pos, tile.liquid.netUpdate()));
1955 }
1956 clientInfo->pendingLiquidUpdates.clear();
1957

Callers

nothing calls this directly

Calls 15

singletonClass · 0.85
ByteArrayClass · 0.85
connectionForEntityFunction · 0.85
sectorActiveMethod · 0.80
sectorRegionMethod · 0.80
xMinMethod · 0.80
xMaxMethod · 0.80
yMinMethod · 0.80
yMaxMethod · 0.80
netUpdateMethod · 0.80
entityFactoryMethod · 0.80
entityIdMethod · 0.80

Tested by

no test coverage detected