add player ID labels for ships
This commit is contained in:
parent
f41228acf8
commit
e18484ea62
@ -155,7 +155,7 @@ int main() {
|
|||||||
try {
|
try {
|
||||||
net::io_context ioc;
|
net::io_context ioc;
|
||||||
tcp::acceptor acceptor{ ioc, {tcp::v4(), 8080} };
|
tcp::acceptor acceptor{ ioc, {tcp::v4(), 8080} };
|
||||||
int next_id = 1000;
|
int next_id = 0;
|
||||||
|
|
||||||
std::cout << "Server started on port 8080...\n";
|
std::cout << "Server started on port 8080...\n";
|
||||||
|
|
||||||
|
|||||||
56
src/Game.cpp
56
src/Game.cpp
@ -656,6 +656,7 @@ namespace ZL
|
|||||||
}
|
}
|
||||||
drawShip();
|
drawShip();
|
||||||
drawRemoteShips();
|
drawRemoteShips();
|
||||||
|
drawRemoteShipsLabels();
|
||||||
drawBoxes();
|
drawBoxes();
|
||||||
drawBoxesLabels();
|
drawBoxesLabels();
|
||||||
|
|
||||||
@ -729,6 +730,59 @@ namespace ZL
|
|||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::drawRemoteShipsLabels()
|
||||||
|
{
|
||||||
|
if (!textRenderer) return;
|
||||||
|
|
||||||
|
#ifdef NETWORK
|
||||||
|
// 2D поверх 3D
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
// Берем удаленных игроков
|
||||||
|
latestRemotePlayers = networkClient->getRemotePlayers();
|
||||||
|
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
now -= std::chrono::milliseconds(CLIENT_DELAY);
|
||||||
|
|
||||||
|
for (auto const& [id, remotePlayer] : latestRemotePlayers)
|
||||||
|
{
|
||||||
|
if (!remotePlayer.canFetchClientStateAtTime(now))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ClientState st = remotePlayer.fetchClientStateAtTime(now);
|
||||||
|
|
||||||
|
// Позиция корабля в мире
|
||||||
|
Vector3f shipWorld = st.position;
|
||||||
|
|
||||||
|
// Значение положения лейбла
|
||||||
|
Vector3f labelWorld = shipWorld + Vector3f{ 0.0f, -5.0f, 0.0f };
|
||||||
|
|
||||||
|
float sx, sy, depth;
|
||||||
|
if (!worldToScreen(labelWorld, sx, sy, depth))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float uiX = sx;
|
||||||
|
float uiY = sy;
|
||||||
|
|
||||||
|
// Масштаб по расстоянию
|
||||||
|
float dist = (Environment::shipState.position - shipWorld).norm();
|
||||||
|
float scale = std::clamp(140.0f / (dist + 1.0f), 0.6f, 1.2f);
|
||||||
|
|
||||||
|
// Дефолтный лейбл
|
||||||
|
std::string label = "Player (" + std::to_string(st.id) + ")";
|
||||||
|
|
||||||
|
// TODO: nickname sync
|
||||||
|
|
||||||
|
textRenderer->drawText(label, uiX, uiY, scale, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Game::processTickCount() {
|
void Game::processTickCount() {
|
||||||
|
|
||||||
if (lastTickCount == 0) {
|
if (lastTickCount == 0) {
|
||||||
@ -749,7 +803,7 @@ namespace ZL
|
|||||||
size_t delta = newTickCount - lastTickCount;
|
size_t delta = newTickCount - lastTickCount;
|
||||||
if (delta > CONST_MAX_TIME_INTERVAL)
|
if (delta > CONST_MAX_TIME_INTERVAL)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Synchronization is lost");
|
//throw std::runtime_error("Synchronization is lost");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto now_ms = newTickCount;
|
auto now_ms = newTickCount;
|
||||||
|
|||||||
@ -50,6 +50,7 @@ namespace ZL {
|
|||||||
void drawBoxesLabels();
|
void drawBoxesLabels();
|
||||||
void drawUI();
|
void drawUI();
|
||||||
void drawRemoteShips();
|
void drawRemoteShips();
|
||||||
|
void drawRemoteShipsLabels();
|
||||||
void fireProjectiles();
|
void fireProjectiles();
|
||||||
|
|
||||||
bool worldToScreen(const Vector3f& world, float& outX, float& outY, float& outDepth) const;
|
bool worldToScreen(const Vector3f& world, float& outX, float& outY, float& outDepth) const;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user