added sync projectiles/boxes
This commit is contained in:
1 parent
cacc18dc7e
commit
e8fb14b809
7 files changed
+338
-192
No files matched your search
+59
-6
@@ -232,7 +232,24 @@ namespace ZL
|
||||
uint64_t now = SDL_GetTicks64();
|
||||
if (now - lastProjectileFireTime >= static_cast<uint64_t>(projectileCooldownMs)) {
|
||||
lastProjectileFireTime = now;
|
||||
fireProjectiles();
|
||||
|
||||
Eigen::Vector3f localForward = { 0, 0, -1 };
|
||||
Eigen::Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized();
|
||||
|
||||
Eigen::Vector3f centerPos = Environment::shipState.position +
|
||||
Environment::shipState.rotation * Vector3f{ 0, 0.9f, 5.0f };
|
||||
|
||||
std::string fireMsg = "FIRE:" +
|
||||
std::to_string(now) + ":" +
|
||||
std::to_string(centerPos.x()) + ":" +
|
||||
std::to_string(centerPos.y()) + ":" +
|
||||
std::to_string(centerPos.z()) + ":" +
|
||||
std::to_string(worldForward.x()) + ":" +
|
||||
std::to_string(worldForward.y()) + ":" +
|
||||
std::to_string(worldForward.z()) + ":" +
|
||||
"2";
|
||||
|
||||
networkClient->Send(fireMsg);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -582,7 +599,7 @@ namespace ZL
|
||||
auto sboxes = networkClient->getServerBoxes();
|
||||
if (!sboxes.empty()) {
|
||||
boxCoordsArr.clear();
|
||||
for (auto &b : sboxes) {
|
||||
for (auto& b : sboxes) {
|
||||
BoxCoords bc;
|
||||
bc.pos = b.first;
|
||||
bc.m = b.second;
|
||||
@@ -607,7 +624,7 @@ namespace ZL
|
||||
}
|
||||
|
||||
ClientState playerState = remotePlayer.fetchClientStateAtTime(now);
|
||||
|
||||
|
||||
|
||||
renderer.PushMatrix();
|
||||
renderer.LoadIdentity();
|
||||
@@ -704,7 +721,7 @@ namespace ZL
|
||||
float radians = atan2f(diffy, diffx);
|
||||
discreteAngle = static_cast<int>(radians * 180.0f / M_PI);
|
||||
if (discreteAngle < 0) discreteAngle += 360;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -718,7 +735,7 @@ namespace ZL
|
||||
discreteMag = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (discreteAngle != Environment::shipState.discreteAngle || discreteMag != Environment::shipState.discreteMag) {
|
||||
Environment::shipState.discreteAngle = discreteAngle;
|
||||
Environment::shipState.discreteMag = discreteMag;
|
||||
@@ -1097,7 +1114,7 @@ namespace ZL
|
||||
{
|
||||
if (event.key.keysym.sym == SDLK_i)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
@@ -1105,6 +1122,42 @@ namespace ZL
|
||||
render();
|
||||
mainThreadHandler.processMainThreadTasks();
|
||||
networkClient->Poll();
|
||||
|
||||
if (networkClient) {
|
||||
auto pending = networkClient->getPendingProjectiles();
|
||||
if (!pending.empty()) {
|
||||
const float projectileSpeed = 60.0f;
|
||||
const float lifeMs = 5000.0f;
|
||||
const float size = 0.5f;
|
||||
|
||||
for (const auto& pi : pending) {
|
||||
Eigen::Vector3f dir = pi.direction;
|
||||
float len = dir.norm();
|
||||
if (len <= 1e-6f) continue;
|
||||
dir /= len;
|
||||
Eigen::Vector3f baseVel = dir * projectileSpeed;
|
||||
|
||||
int shotCount = 1;
|
||||
shotCount = 2;
|
||||
|
||||
std::vector<Eigen::Vector3f> localOffsets = {
|
||||
{-1.5f, 0.9f, 5.0f},
|
||||
{ 1.5f, 0.9f, 5.0f}
|
||||
};
|
||||
|
||||
for (int i = 0; i < shotCount; ++i) {
|
||||
Eigen::Vector3f shotPos = pi.position + localOffsets[i];
|
||||
|
||||
for (auto& p : projectiles) {
|
||||
if (!p->isActive()) {
|
||||
p->init(shotPos, baseVel, lifeMs, size, projectileTexture, renderer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::handleDown(int mx, int my)
|
||||
|
||||
Reference in new issue
Block a user