Added trails to other ships toos
This commit is contained in:
1 parent
59b5bea540
commit
24aa7007bb
7 files changed
+128
-88
No files matched your search
+91
-57
@@ -33,6 +33,8 @@ namespace ZL
|
||||
extern const char* CONST_ZIP_FILE;
|
||||
|
||||
extern float x;
|
||||
extern float y;
|
||||
extern float z;
|
||||
|
||||
Eigen::Quaternionf generateRandomQuaternion(std::mt19937& gen)
|
||||
{
|
||||
@@ -507,17 +509,7 @@ namespace ZL
|
||||
}
|
||||
|
||||
|
||||
renderer.PushMatrix();
|
||||
renderer.RotateMatrix(Environment::inverseShipMatrix);
|
||||
renderer.TranslateMatrix(- /*0.5 * */ Environment::shipState.position);
|
||||
std::cout << "Ship pos draw: " << Environment::shipState.position.transpose() << "\n";
|
||||
if (Environment::shipState.shipType == 1) {
|
||||
sparkEmitterCargo.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
}
|
||||
else {
|
||||
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
}
|
||||
renderer.PopMatrix();
|
||||
drawShipSparkEmitters();
|
||||
}
|
||||
|
||||
renderer.PopMatrix();
|
||||
@@ -591,16 +583,7 @@ namespace ZL
|
||||
|
||||
glViewport(0, 0, Environment::width, Environment::height);
|
||||
|
||||
// Готовим данные всех эмиттеров (CPU + VBO upload) до начала отрисовки,
|
||||
// чтобы draw() делал только GPU-вызовы без пауз между кораблём и частицами.
|
||||
sparkEmitter.prepareForDraw(true);
|
||||
sparkEmitterCargo.prepareForDraw(true);
|
||||
explosionEmitter.prepareForDraw(false);
|
||||
for (const auto& p : projectiles) {
|
||||
if (p && p->isActive()) {
|
||||
p->projectileEmitter.prepareForDraw(true);
|
||||
}
|
||||
}
|
||||
prepareSparkEmittersForDraw();
|
||||
|
||||
CheckGlError();
|
||||
|
||||
@@ -1431,6 +1414,89 @@ namespace ZL
|
||||
targetWasVisible = false;
|
||||
}
|
||||
|
||||
void Space::updateSparkEmitters(float deltaMs)
|
||||
{
|
||||
// Local ship
|
||||
SparkEmitter* sparkEmitterPtr;
|
||||
if (Environment::shipState.shipType == 1) {
|
||||
sparkEmitterPtr = &sparkEmitterCargo;
|
||||
static std::vector<Vector3f> emissionPoints = { Vector3f(0, 0, 0), Vector3f(0, 0, 0) };
|
||||
emissionPoints[0] = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ 0.0, 2.8, -6.5 + 16.0 };
|
||||
emissionPoints[1] = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ 0.0, 1.5, -6.5 + 16.0 };
|
||||
sparkEmitterPtr->setEmissionPoints(emissionPoints);
|
||||
}
|
||||
else {
|
||||
sparkEmitterPtr = &sparkEmitter;
|
||||
static std::vector<Vector3f> emissionPoints = { Vector3f(0, 0, 0), Vector3f(0, 0, 0) };
|
||||
emissionPoints[0] = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ -0.9, 1.4 - 1.0, -8.5 + 16.0 };
|
||||
emissionPoints[1] = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ 0.9, 1.4 - 1.0, -8.5 + 16.0 };
|
||||
sparkEmitterPtr->setEmissionPoints(emissionPoints);
|
||||
}
|
||||
sparkEmitterPtr->setIsActive(Environment::shipState.velocity > 0.1f);
|
||||
sparkEmitterPtr->update(deltaMs);
|
||||
|
||||
// Remote ships
|
||||
for (auto const& [id, playerState] : remotePlayerStates) {
|
||||
if (deadRemotePlayers.count(id)) continue;
|
||||
if (!remoteShipSparkEmitters.count(id)) {
|
||||
remoteShipSparkEmitters.emplace(id, playerState.shipType == 1 ? sparkEmitterCargo : sparkEmitter);
|
||||
}
|
||||
auto& remEmitter = remoteShipSparkEmitters.at(id);
|
||||
std::vector<Vector3f> remEmitPts(2);
|
||||
if (playerState.shipType == 1) {
|
||||
remEmitPts[0] = playerState.position + playerState.rotation * Vector3f{ 0.0f, -0.4f+2.8f, 8.4f };
|
||||
remEmitPts[1] = playerState.position + playerState.rotation * Vector3f{ 0.0f, -0.4f+1.5f, 8.4f };
|
||||
} else {
|
||||
remEmitPts[0] = playerState.position + playerState.rotation * Vector3f{ -0.9f, -0.2,5.6 };
|
||||
remEmitPts[1] = playerState.position + playerState.rotation * Vector3f{ 0.9f,-0.2,5.6 };
|
||||
}
|
||||
remEmitter.setEmissionPoints(remEmitPts);
|
||||
remEmitter.setIsActive(playerState.velocity > 0.1f);
|
||||
remEmitter.update(deltaMs);
|
||||
}
|
||||
}
|
||||
|
||||
void Space::prepareSparkEmittersForDraw()
|
||||
{
|
||||
sparkEmitter.prepareForDraw(true);
|
||||
sparkEmitterCargo.prepareForDraw(true);
|
||||
for (auto& [id, emitter] : remoteShipSparkEmitters) {
|
||||
if (!deadRemotePlayers.count(id)) emitter.prepareForDraw(true);
|
||||
}
|
||||
explosionEmitter.prepareForDraw(false);
|
||||
for (const auto& p : projectiles) {
|
||||
if (p && p->isActive()) {
|
||||
p->projectileEmitter.prepareForDraw(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Space::drawShipSparkEmitters()
|
||||
{
|
||||
renderer.PushMatrix();
|
||||
renderer.RotateMatrix(Environment::inverseShipMatrix);
|
||||
renderer.TranslateMatrix(-Environment::shipState.position);
|
||||
if (Environment::shipState.shipType == 1) {
|
||||
sparkEmitterCargo.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
} else {
|
||||
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
}
|
||||
|
||||
for (auto& [id, emitter] : remoteShipSparkEmitters) {
|
||||
if (!deadRemotePlayers.count(id)) {
|
||||
|
||||
renderer.PushMatrix();
|
||||
renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||
renderer.RotateMatrix(Environment::inverseShipMatrix);
|
||||
renderer.TranslateMatrix(-Environment::shipState.position);
|
||||
emitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
}
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
|
||||
void Space::processTickCount(int64_t newTickCount, int64_t delta) {
|
||||
|
||||
auto now_ms = newTickCount;
|
||||
@@ -1522,7 +1588,7 @@ namespace ZL
|
||||
|
||||
std::string msg = "UPD:" + std::to_string(now_ms) + ":" + Environment::shipState.formPingMessageContent();
|
||||
networkClient->Send(msg);
|
||||
std::cout << "Sending: " << msg << std::endl;
|
||||
//std::cout << "Sending: " << msg << std::endl;
|
||||
}
|
||||
|
||||
long long leftoverDelta = delta;
|
||||
@@ -1545,41 +1611,6 @@ namespace ZL
|
||||
}
|
||||
|
||||
|
||||
//--------------
|
||||
|
||||
SparkEmitter* sparkEmitterPtr;
|
||||
|
||||
if (Environment::shipState.shipType == 1) {
|
||||
sparkEmitterPtr = &sparkEmitterCargo;
|
||||
static std::vector<Vector3f> emissionPoints = { Vector3f(0, 0, 0), Vector3f(0, 0, 0) };
|
||||
emissionPoints[0] = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ 0.0, 2.8, -6.5 + 16.0 };
|
||||
emissionPoints[1] = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ 0.0, 1.5, -6.5 + 16.0 };
|
||||
sparkEmitterPtr->setEmissionPoints(emissionPoints);
|
||||
}
|
||||
else
|
||||
{
|
||||
sparkEmitterPtr = &sparkEmitter;
|
||||
static std::vector<Vector3f> emissionPoints = { Vector3f(0, 0, 0), Vector3f(0, 0, 0) };
|
||||
emissionPoints[0] = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ -0.9, 1.4 - 1.0, -8.5 + 16.0 };
|
||||
emissionPoints[1] = Environment::shipState.position + Environment::shipState.rotation * Vector3f{ 0.9, 1.4 - 1.0, -8.5 + 16.0 };
|
||||
sparkEmitterPtr->setEmissionPoints(emissionPoints);
|
||||
//sparkEmitterPtr->setEmissionPoints({ /*0.5* */Environment::shipState.position });
|
||||
//sparkEmitterPtr->setEmissionPoints({ Vector3f(0, 0, 0) });
|
||||
std::cout << "Ship pos empo: " << Environment::shipState.position.transpose() << "\n";
|
||||
}
|
||||
|
||||
if (Environment::shipState.velocity > 0.1f)
|
||||
{
|
||||
sparkEmitterPtr->setIsActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
sparkEmitterPtr->setIsActive(false);
|
||||
}
|
||||
|
||||
sparkEmitterPtr->update(static_cast<float>(delta));
|
||||
|
||||
|
||||
auto latestRemotePlayers = networkClient->getRemotePlayers();
|
||||
|
||||
std::chrono::system_clock::time_point nowRoundedWithDelay{ std::chrono::milliseconds(newTickCount - CLIENT_DELAY) };
|
||||
@@ -1601,6 +1632,8 @@ namespace ZL
|
||||
remotePlayerStates[id] = playerState;
|
||||
}
|
||||
|
||||
updateSparkEmitters(static_cast<float>(delta));
|
||||
|
||||
for (auto& p : projectiles) {
|
||||
if (p && p->isActive()) {
|
||||
p->update(static_cast<float>(delta), renderer);
|
||||
@@ -1875,6 +1908,7 @@ namespace ZL
|
||||
for (int pid : disconnects) {
|
||||
remotePlayerStates.erase(pid);
|
||||
deadRemotePlayers.erase(pid);
|
||||
remoteShipSparkEmitters.erase(pid);
|
||||
if (trackedTargetId == pid) {
|
||||
trackedTargetId = -1;
|
||||
targetAcquireAnim = 0.f;
|
||||
|
||||
Reference in new issue
Block a user