merge
This commit is contained in:
commit
8f3528f9a1
20 files changed
+1130
-287
No files matched your search
+216
-177
@@ -14,6 +14,12 @@
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#ifdef NETWORK
|
||||
#include "network/WebSocketClient.h"
|
||||
#else
|
||||
#include "network/LocalClient.h"
|
||||
#endif
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
#ifdef EMSCRIPTEN
|
||||
@@ -134,33 +140,6 @@ namespace ZL
|
||||
ZL::BindOpenGlFunctions();
|
||||
ZL::CheckGlError();
|
||||
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "Game", "Start for Android");
|
||||
|
||||
const char* testFiles[] = {
|
||||
"resources/shaders/default.vertex",
|
||||
"resources/shaders/default_web.fragment",
|
||||
nullptr
|
||||
};
|
||||
|
||||
for (int i = 0; testFiles[i] != nullptr; i++) {
|
||||
SDL_RWops* file = SDL_RWFromFile(testFiles[i], "rb");
|
||||
if (file) {
|
||||
Sint64 size = SDL_RWsize(file);
|
||||
__android_log_print(ANDROID_LOG_INFO, "Game", "Found: %s (size: %lld)", testFiles[i], size);
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
else {
|
||||
__android_log_print(ANDROID_LOG_WARN, "Game", "Not found: %s (SDL error: %s)",
|
||||
testFiles[i], SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR, "ShaderManager",
|
||||
"Step 1xxxxxxx");
|
||||
#endif
|
||||
// Initialize renderer
|
||||
|
||||
|
||||
#ifndef SIMPLIFIED
|
||||
renderer.shaderManager.AddShaderFromFiles("defaultColor", "resources/shaders/defaultColor.vertex", "resources/shaders/defaultColor_web.fragment", CONST_ZIP_FILE);
|
||||
@@ -173,37 +152,11 @@ namespace ZL
|
||||
|
||||
#else
|
||||
renderer.shaderManager.AddShaderFromFiles("default", "resources/shaders/default.vertex", "resources/shaders/default_web.fragment", CONST_ZIP_FILE);
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_ERROR, "ShaderManager",
|
||||
"Step 2xxxxxxx");
|
||||
#endif
|
||||
renderer.shaderManager.AddShaderFromFiles("env_sky", "resources/shaders/default_env.vertex", "resources/shaders/default_env_web.fragment", CONST_ZIP_FILE);
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "ShaderManager",
|
||||
"Step 2");
|
||||
#endif
|
||||
renderer.shaderManager.AddShaderFromFiles("defaultAtmosphere", "resources/shaders/default_texture.vertex", "resources/shaders/default_texture_web.fragment", CONST_ZIP_FILE);
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "ShaderManager",
|
||||
"Step 3");
|
||||
#endif
|
||||
|
||||
renderer.shaderManager.AddShaderFromFiles("planetBake", "resources/shaders/default_texture.vertex", "resources/shaders/default_texture_web.fragment", CONST_ZIP_FILE);
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "ShaderManager",
|
||||
"Step 4");
|
||||
#endif
|
||||
renderer.shaderManager.AddShaderFromFiles("planetStone", "resources/shaders/default_texture.vertex", "resources/shaders/default_texture_web.fragment", CONST_ZIP_FILE);
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "ShaderManager",
|
||||
"Step 5");
|
||||
#endif
|
||||
renderer.shaderManager.AddShaderFromFiles("planetLand", "resources/shaders/default_texture.vertex", "resources/shaders/default_texture_web.fragment", CONST_ZIP_FILE);
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "ShaderManager",
|
||||
"Step 1");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
bool cfgLoaded = sparkEmitter.loadFromJsonFile("resources/config/spark_config.json", renderer, CONST_ZIP_FILE);
|
||||
@@ -284,16 +237,12 @@ namespace ZL
|
||||
});
|
||||
|
||||
uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) {
|
||||
Environment::shipVelocity = value * 1000.f;
|
||||
int newVel = roundf(value * 10);
|
||||
if (newVel != Environment::shipState.selectedVelocity) {
|
||||
newShipVelocity = newVel;
|
||||
}
|
||||
});
|
||||
|
||||
/*uiManager.setSliderCallback("musicVolumeSlider", [this](const std::string& name, float value) {
|
||||
std::cerr << "Music volume slider changed to: " << value << std::endl;
|
||||
musicVolume = value;
|
||||
Environment::shipVelocity = musicVolume * 20.0f;
|
||||
});
|
||||
//#endif*/
|
||||
|
||||
cubemapTexture = std::make_shared<Texture>(
|
||||
std::array<TextureDataStruct, 6>{
|
||||
CreateTextureDataFromPng("resources/sky/space1.png", CONST_ZIP_FILE),
|
||||
@@ -325,10 +274,6 @@ namespace ZL
|
||||
spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix());
|
||||
|
||||
spaceshipBase.Move(Vector3f{ 1.2, 0, -5 });
|
||||
//spaceshipBase.Move(Vector3f{ -0.52998, -13, 0 });
|
||||
//spaceshipBase.Move(Vector3f{ -0.52998, -10, 10 });
|
||||
//spaceshipBase.Move(Vector3f{ -0.52998, 0, 10 });
|
||||
|
||||
|
||||
spaceship.AssignFrom(spaceshipBase);
|
||||
spaceship.RefreshVBO();
|
||||
@@ -338,16 +283,8 @@ namespace ZL
|
||||
boxTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/box/box.png", CONST_ZIP_FILE));
|
||||
boxBase = LoadFromTextFile02("resources/box/box.txt", CONST_ZIP_FILE);
|
||||
|
||||
std::cout << "Init step 1 " << std::endl;
|
||||
|
||||
boxCoordsArr = generateRandomBoxCoords(50);
|
||||
|
||||
std::cout << "Init step 2 " << std::endl;
|
||||
|
||||
boxRenderArr.resize(boxCoordsArr.size());
|
||||
|
||||
std::cout << "Init step 3x " << std::endl;
|
||||
|
||||
for (int i = 0; i < boxCoordsArr.size(); i++)
|
||||
{
|
||||
boxRenderArr[i].AssignFrom(boxBase);
|
||||
@@ -357,25 +294,24 @@ namespace ZL
|
||||
|
||||
boxAlive.resize(boxCoordsArr.size(), true);
|
||||
|
||||
std::cout << "Init step 4 " << std::endl;
|
||||
|
||||
if (!cfgLoaded)
|
||||
{
|
||||
throw std::runtime_error("Failed to load spark emitter config file!");
|
||||
}
|
||||
std::cout << "Init step 5 " << std::endl;
|
||||
|
||||
renderer.InitOpenGL();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
std::cout << "Init step 6 " << std::endl;
|
||||
planetObject.init();
|
||||
|
||||
std::cout << "Init step 7 " << std::endl;
|
||||
//rockTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/rock.png", CONST_ZIP_FILE));
|
||||
|
||||
std::cout << "Init step 8 " << std::endl;
|
||||
#ifdef NETWORK
|
||||
networkClient = std::make_unique<WebSocketClient>(taskManager.getIOContext());
|
||||
networkClient->Connect("127.0.0.1", 8080);
|
||||
#else
|
||||
networkClient = std::make_unique<LocalClient>();
|
||||
networkClient->Connect("", 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Game::drawCubemap(float skyPercent)
|
||||
@@ -414,7 +350,7 @@ namespace ZL
|
||||
|
||||
// 1. Вектор направления от центра планеты к игроку (в мировых координатах)
|
||||
// Предполагаем, что планета в (0,0,0). Если нет, то (shipPosition - planetCenter)
|
||||
Vector3f playerDirWorld = Environment::shipPosition.normalized();
|
||||
Vector3f playerDirWorld = Environment::shipState.position.normalized();
|
||||
|
||||
// 2. Направление света в мировом пространстве
|
||||
//Vector3f worldLightDir = Vector3f(1.0f, -1.0f, -1.0f).normalized();
|
||||
@@ -526,7 +462,7 @@ namespace ZL
|
||||
renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||
renderer.RotateMatrix(Environment::inverseShipMatrix);
|
||||
renderer.TranslateMatrix(-Environment::shipPosition);
|
||||
renderer.TranslateMatrix(-Environment::shipState.position);
|
||||
renderer.TranslateMatrix({ 0.f, 0.f, 45000.f });
|
||||
renderer.TranslateMatrix(boxCoordsArr[i].pos);
|
||||
renderer.RotateMatrix(boxCoordsArr[i].m);
|
||||
@@ -584,7 +520,7 @@ namespace ZL
|
||||
CheckGlError();
|
||||
|
||||
float skyPercent = 0.0;
|
||||
float distance = planetObject.distanceToPlanetSurface(Environment::shipPosition);
|
||||
float distance = planetObject.distanceToPlanetSurface(Environment::shipState.position);
|
||||
if (distance > 1500.f)
|
||||
{
|
||||
skyPercent = 0.0f;
|
||||
@@ -601,65 +537,179 @@ namespace ZL
|
||||
|
||||
drawCubemap(skyPercent);
|
||||
planetObject.draw(renderer);
|
||||
if (planetObject.distanceToPlanetSurface(Environment::shipPosition) > 100.f)
|
||||
if (planetObject.distanceToPlanetSurface(Environment::shipState.position) > 100.f)
|
||||
{
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
drawShip();
|
||||
drawRemoteShips();
|
||||
drawBoxes();
|
||||
|
||||
drawUI();
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
void Game::drawRemoteShips() {
|
||||
// Используем те же константы имен для шейдеров, что и в drawShip
|
||||
static const std::string defaultShaderName = "default";
|
||||
static const std::string vPositionName = "vPosition";
|
||||
static const std::string vTexCoordName = "vTexCoord";
|
||||
static const std::string textureUniformName = "Texture";
|
||||
|
||||
// Активируем шейдер и текстуру (предполагаем, что меш у всех одинаковый)
|
||||
renderer.shaderManager.PushShader(defaultShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
|
||||
renderer.EnableVertexAttribArray(vPositionName);
|
||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||
|
||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||
|
||||
// Биндим текстуру корабля один раз для всех удаленных игроков (оптимизация батчинга)
|
||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||
|
||||
auto now = std::chrono::system_clock::now();
|
||||
|
||||
//Apply server delay:
|
||||
now -= std::chrono::milliseconds(CLIENT_DELAY);
|
||||
|
||||
latestRemotePlayers = networkClient->getRemotePlayers();
|
||||
|
||||
// Итерируемся по актуальным данным из extrapolateRemotePlayers
|
||||
for (auto const& [id, remotePlayer] : latestRemotePlayers) {
|
||||
|
||||
if (!remotePlayer.canFetchClientStateAtTime(now))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ClientState playerState = remotePlayer.fetchClientStateAtTime(now);
|
||||
|
||||
|
||||
renderer.PushMatrix();
|
||||
renderer.LoadIdentity();
|
||||
|
||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||
renderer.TranslateMatrix({ 0, -6.f, 0 }); //Ship camera offset
|
||||
renderer.RotateMatrix(Environment::inverseShipMatrix);
|
||||
renderer.TranslateMatrix(-Environment::shipState.position);
|
||||
|
||||
|
||||
Eigen::Vector3f relativePos = playerState.position;// -Environment::shipPosition;
|
||||
renderer.TranslateMatrix(relativePos);
|
||||
|
||||
// 3. Поворот врага
|
||||
renderer.RotateMatrix(playerState.rotation);
|
||||
|
||||
renderer.DrawVertexRenderStruct(spaceship);
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
|
||||
renderer.PopProjectionMatrix();
|
||||
renderer.DisableVertexAttribArray(vPositionName);
|
||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
||||
renderer.shaderManager.PopShader();
|
||||
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
void Game::processTickCount() {
|
||||
|
||||
if (lastTickCount == 0) {
|
||||
lastTickCount = SDL_GetTicks64();
|
||||
//lastTickCount = SDL_GetTicks64();
|
||||
lastTickCount = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()
|
||||
).count();
|
||||
return;
|
||||
}
|
||||
|
||||
newTickCount = SDL_GetTicks64();
|
||||
//newTickCount = SDL_GetTicks64();
|
||||
newTickCount = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()
|
||||
).count();
|
||||
|
||||
if (newTickCount - lastTickCount > CONST_TIMER_INTERVAL) {
|
||||
size_t delta = (newTickCount - lastTickCount > CONST_MAX_TIME_INTERVAL) ?
|
||||
CONST_MAX_TIME_INTERVAL : newTickCount - lastTickCount;
|
||||
|
||||
size_t delta = newTickCount - lastTickCount;
|
||||
if (delta > CONST_MAX_TIME_INTERVAL)
|
||||
{
|
||||
throw std::runtime_error("Synchronization is lost");
|
||||
}
|
||||
|
||||
auto now_ms = newTickCount;
|
||||
|
||||
sparkEmitter.update(static_cast<float>(delta));
|
||||
planetObject.update(static_cast<float>(delta));
|
||||
|
||||
if (Environment::tapDownHold) {
|
||||
static float pingTimer = 0.0f;
|
||||
pingTimer += delta;
|
||||
if (pingTimer >= 1000.0f) {
|
||||
std::string pingMsg = "UPD:" + std::to_string(now_ms) + ":" + Environment::shipState.formPingMessageContent();
|
||||
|
||||
networkClient->Send(pingMsg);
|
||||
std::cout << "Sending: " << pingMsg << std::endl;
|
||||
pingTimer = 0.0f;
|
||||
}
|
||||
|
||||
//Handle input:
|
||||
|
||||
if (newShipVelocity != Environment::shipState.selectedVelocity)
|
||||
{
|
||||
Environment::shipState.selectedVelocity = newShipVelocity;
|
||||
|
||||
std::string msg = "UPD:" + std::to_string(now_ms) + ":" + Environment::shipState.formPingMessageContent();
|
||||
networkClient->Send(msg);
|
||||
}
|
||||
|
||||
float discreteMag;
|
||||
int discreteAngle;
|
||||
|
||||
if (Environment::tapDownHold) {
|
||||
float diffx = Environment::tapDownCurrentPos(0) - Environment::tapDownStartPos(0);
|
||||
float diffy = Environment::tapDownCurrentPos(1) - Environment::tapDownStartPos(1);
|
||||
|
||||
if (abs(diffy) > 5.0 || abs(diffx) > 5.0) //threshold
|
||||
float rawMag = sqrtf(diffx * diffx + diffy * diffy);
|
||||
float maxRadius = 200.0f; // Максимальный вынос джойстика
|
||||
|
||||
if (rawMag > 10.0f) { // Мертвая зона
|
||||
// 1. Дискретизируем отклонение (0.0 - 1.0 с шагом 0.1)
|
||||
float normalizedMag = min(rawMag / maxRadius, 1.0f);
|
||||
discreteMag = std::round(normalizedMag * 10.0f) / 10.0f;
|
||||
|
||||
// 2. Дискретизируем угол (0-359 градусов)
|
||||
// atan2 возвращает радианы, переводим в градусы
|
||||
float radians = atan2f(diffy, diffx);
|
||||
discreteAngle = static_cast<int>(radians * 180.0f / M_PI);
|
||||
if (discreteAngle < 0) discreteAngle += 360;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
float rotationPower = sqrtf(diffx * diffx + diffy * diffy);
|
||||
float deltaAlpha = rotationPower * delta * static_cast<float>(M_PI) / 500000.f;
|
||||
|
||||
Eigen::Vector3f rotationDirection(diffy, diffx, 0.0f);
|
||||
rotationDirection.normalize(); // Eigen-way нормализация
|
||||
|
||||
// Создаем кватернион через AngleAxis
|
||||
// Конструктор принимает (угол_в_радианах, ось_вращения)
|
||||
Eigen::Quaternionf rotateQuat(Eigen::AngleAxisf(deltaAlpha, rotationDirection));
|
||||
|
||||
Matrix3f rotateMat = rotateQuat.toRotationMatrix();
|
||||
|
||||
Environment::shipMatrix = Environment::shipMatrix * rotateMat;
|
||||
Environment::inverseShipMatrix = Environment::shipMatrix.inverse();
|
||||
|
||||
discreteAngle = -1;
|
||||
discreteMag = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (fabs(Environment::shipVelocity) > 0.01f)
|
||||
else
|
||||
{
|
||||
Vector3f velocityDirection = { 0,0, -Environment::shipVelocity * delta / 1000.f };
|
||||
Vector3f velocityDirectionAdjusted = Environment::shipMatrix * velocityDirection;
|
||||
Environment::shipPosition = Environment::shipPosition + velocityDirectionAdjusted;
|
||||
discreteAngle = -1;
|
||||
discreteMag = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
if (discreteAngle != Environment::shipState.discreteAngle || discreteMag != Environment::shipState.discreteMag) {
|
||||
Environment::shipState.discreteAngle = discreteAngle;
|
||||
Environment::shipState.discreteMag = discreteMag;
|
||||
|
||||
std::string msg = "UPD:" + std::to_string(now_ms) + ":" + Environment::shipState.formPingMessageContent();
|
||||
networkClient->Send(msg);
|
||||
std::cout << "Sending: " << msg << std::endl;
|
||||
}
|
||||
|
||||
Environment::shipState.simulate_physics(delta);
|
||||
Environment::inverseShipMatrix = Environment::shipState.rotation.inverse();
|
||||
|
||||
for (auto& p : projectiles) {
|
||||
if (p && p->isActive()) {
|
||||
p->update(static_cast<float>(delta), renderer);
|
||||
@@ -670,7 +720,7 @@ namespace ZL
|
||||
for (const auto& p : projectiles) {
|
||||
if (p && p->isActive()) {
|
||||
Vector3f worldPos = p->getPosition();
|
||||
Vector3f rel = worldPos - Environment::shipPosition;
|
||||
Vector3f rel = worldPos - Environment::shipState.position;
|
||||
Vector3f camPos = Environment::inverseShipMatrix * rel;
|
||||
projCameraPoints.push_back(camPos);
|
||||
}
|
||||
@@ -705,15 +755,16 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
if (shipAlive) {
|
||||
float distToSurface = planetObject.distanceToPlanetSurface(Environment::shipPosition);
|
||||
float distToSurface = planetObject.distanceToPlanetSurface(Environment::shipState.position);
|
||||
if (distToSurface <= 0.0f) {
|
||||
Vector3f dir = (Environment::shipPosition - PlanetData::PLANET_CENTER_OFFSET).normalized();
|
||||
|
||||
Vector3f dir = (Environment::shipState.position - PlanetData::PLANET_CENTER_OFFSET).normalized();
|
||||
Vector3f collisionPoint = PlanetData::PLANET_CENTER_OFFSET + dir * PlanetData::PLANET_RADIUS;
|
||||
Environment::shipPosition = PlanetData::PLANET_CENTER_OFFSET + dir * (PlanetData::PLANET_RADIUS + shipCollisionRadius + 0.1f);
|
||||
Environment::shipState.position = PlanetData::PLANET_CENTER_OFFSET + dir * (PlanetData::PLANET_RADIUS + shipCollisionRadius + 0.1f);
|
||||
|
||||
shipAlive = false;
|
||||
gameOver = true;
|
||||
Environment::shipVelocity = 0.0f;
|
||||
Environment::shipState.velocity = 0.0f;
|
||||
showExplosion = true;
|
||||
|
||||
explosionEmitter.setUseWorldSpace(true);
|
||||
@@ -731,12 +782,14 @@ namespace ZL
|
||||
this->uiGameOverShown = false;
|
||||
this->showExplosion = false;
|
||||
this->explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||
Environment::shipPosition = Vector3f{ 0, 0, 45000.f };
|
||||
Environment::shipVelocity = 0.0f;
|
||||
Environment::shipMatrix = Eigen::Matrix3f::Identity();
|
||||
|
||||
Environment::shipState.position = Vector3f{ 0, 0, 45000.f };
|
||||
Environment::shipState.velocity = 0.0f;
|
||||
Environment::shipState.rotation = Eigen::Matrix3f::Identity();
|
||||
Environment::inverseShipMatrix = Eigen::Matrix3f::Identity();
|
||||
Environment::zoom = 18.f;
|
||||
Environment::zoom = DEFAULT_ZOOM;
|
||||
Environment::tapDownHold = false;
|
||||
|
||||
uiManager.popMenu();
|
||||
std::cerr << "Game restarted\n";
|
||||
});
|
||||
@@ -772,7 +825,7 @@ namespace ZL
|
||||
for (const auto& inst : instances) {
|
||||
|
||||
Vector3f stoneWorld = inst.position;
|
||||
Vector3f diff = Environment::shipPosition - stoneWorld;
|
||||
Vector3f diff = Environment::shipState.position - stoneWorld;
|
||||
|
||||
float maxScale = (std::max)({ inst.scale(0), inst.scale(1), inst.scale(2) });
|
||||
float stoneRadius = StoneParams::BASE_SCALE * maxScale * 0.9f;
|
||||
@@ -791,17 +844,17 @@ namespace ZL
|
||||
}
|
||||
|
||||
if (stoneCollided) {
|
||||
Vector3f away = (Environment::shipPosition - collidedStonePos);
|
||||
Vector3f away = (Environment::shipState.position - collidedStonePos);
|
||||
if (away.squaredNorm() <= 1e-6f) {
|
||||
away = Vector3f{ 0.0f, 1.0f, 0.0f };
|
||||
}
|
||||
away.normalize();
|
||||
|
||||
Environment::shipPosition = collidedStonePos + away * (collidedStoneRadius + shipCollisionRadius + 0.1f);
|
||||
Environment::shipState.position = collidedStonePos + away * (collidedStoneRadius + shipCollisionRadius + 0.1f);
|
||||
|
||||
shipAlive = false;
|
||||
gameOver = true;
|
||||
Environment::shipVelocity = 0.0f;
|
||||
Environment::shipState.velocity = 0.0f;
|
||||
showExplosion = true;
|
||||
|
||||
explosionEmitter.setUseWorldSpace(true);
|
||||
@@ -833,11 +886,11 @@ namespace ZL
|
||||
this->uiGameOverShown = false;
|
||||
this->showExplosion = false;
|
||||
this->explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||
Environment::shipPosition = Vector3f{ 0, 0, 45000.f };
|
||||
Environment::shipVelocity = 0.0f;
|
||||
Environment::shipMatrix = Eigen::Matrix3f::Identity();
|
||||
Environment::shipState.position = Vector3f{ 0, 0, 45000.f };
|
||||
Environment::shipState.velocity = 0.0f;
|
||||
Environment::shipState.rotation = Eigen::Matrix3f::Identity();
|
||||
Environment::inverseShipMatrix = Eigen::Matrix3f::Identity();
|
||||
Environment::zoom = 18.f;
|
||||
Environment::zoom = DEFAULT_ZOOM;
|
||||
Environment::tapDownHold = false;
|
||||
uiManager.popMenu();
|
||||
std::cerr << "Game restarted\n";
|
||||
@@ -860,7 +913,7 @@ namespace ZL
|
||||
for (int i = 0; i < boxCoordsArr.size(); ++i) {
|
||||
if (!boxAlive[i]) continue;
|
||||
Vector3f boxWorld = boxCoordsArr[i].pos + Vector3f{ 0.0f, 0.0f, 45000.0f };
|
||||
Vector3f diff = Environment::shipPosition - boxWorld;
|
||||
Vector3f diff = Environment::shipState.position - boxWorld;
|
||||
float thresh = shipCollisionRadius + boxCollisionRadius;
|
||||
if (diff.squaredNorm() <= thresh * thresh) {
|
||||
boxAlive[i] = false;
|
||||
@@ -871,7 +924,7 @@ namespace ZL
|
||||
boxRenderArr[i].texCoordVBO.reset();
|
||||
showExplosion = true;
|
||||
|
||||
Vector3f rel = boxWorld - Environment::shipPosition;
|
||||
Vector3f rel = boxWorld - Environment::shipState.position;
|
||||
Vector3f camPos = Environment::inverseShipMatrix * rel;
|
||||
explosionEmitter.setUseWorldSpace(true);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ boxWorld });
|
||||
@@ -886,7 +939,7 @@ namespace ZL
|
||||
for (auto& p : projectiles) {
|
||||
if (!p || !p->isActive()) continue;
|
||||
Vector3f ppos = p->getPosition();
|
||||
Vector3f projInBoxSpace = Environment::inverseShipMatrix * (ppos - Environment::shipPosition);
|
||||
Vector3f projInBoxSpace = Environment::inverseShipMatrix * (ppos - Environment::shipState.position);
|
||||
for (int i = 0; i < boxCoordsArr.size(); ++i) {
|
||||
if (!boxAlive[i]) continue;
|
||||
Vector3f boxWorld = boxCoordsArr[i].pos + Vector3f{ 0.0f, 6.0f, 45000.0f };
|
||||
@@ -913,7 +966,6 @@ namespace ZL
|
||||
}
|
||||
|
||||
uiManager.update(static_cast<float>(delta));
|
||||
//#endif
|
||||
lastTickCount = newTickCount;
|
||||
}
|
||||
}
|
||||
@@ -929,11 +981,11 @@ namespace ZL
|
||||
const float size = 0.5f;
|
||||
|
||||
Vector3f localForward = { 0,0,-1 };
|
||||
Vector3f worldForward = (Environment::shipMatrix * localForward).normalized();
|
||||
Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized();
|
||||
|
||||
for (const auto& lo : localOffsets) {
|
||||
Vector3f worldPos = Environment::shipPosition + Environment::shipMatrix * lo;
|
||||
Vector3f worldVel = worldForward * (projectileSpeed + Environment::shipVelocity);
|
||||
Vector3f worldPos = Environment::shipState.position + Environment::shipState.rotation * lo;
|
||||
Vector3f worldVel = worldForward * (projectileSpeed + Environment::shipState.velocity);
|
||||
|
||||
for (auto& p : projectiles) {
|
||||
if (!p->isActive()) {
|
||||
@@ -992,31 +1044,6 @@ namespace ZL
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
int mx = event.button.x;
|
||||
int my = event.button.y;
|
||||
|
||||
uiManager.onMouseDown(mx, my);
|
||||
|
||||
bool uiHandled = false;
|
||||
|
||||
for (const auto& button : uiManager.findButton("") ? std::vector<std::shared_ptr<UiButton>>{} : std::vector<std::shared_ptr<UiButton>>{}) {
|
||||
(void)button;
|
||||
}
|
||||
|
||||
auto pressedSlider = [&]() -> std::shared_ptr<UiSlider> {
|
||||
for (const auto& slider : uiManager.findSlider("") ? std::vector<std::shared_ptr<UiSlider>>{} : std::vector<std::shared_ptr<UiSlider>>{}) {
|
||||
(void)slider;
|
||||
}
|
||||
return nullptr;
|
||||
}();
|
||||
|
||||
if (!uiManager.isUiInteraction()) {
|
||||
Environment::tapDownHold = true;
|
||||
|
||||
Environment::tapDownStartPos(0) = mx;
|
||||
Environment::tapDownStartPos(1) = my;
|
||||
|
||||
Environment::tapDownCurrentPos(0) = mx;
|
||||
Environment::tapDownCurrentPos(1) = my;
|
||||
}
|
||||
handleDown(mx, my);
|
||||
}
|
||||
if (event.type == SDL_MOUSEBUTTONUP) {
|
||||
@@ -1032,6 +1059,7 @@ namespace ZL
|
||||
handleMotion(mx, my);
|
||||
|
||||
}
|
||||
/*
|
||||
if (event.type == SDL_MOUSEWHEEL) {
|
||||
static const float zoomstep = 2.0f;
|
||||
if (event.wheel.y > 0) {
|
||||
@@ -1048,27 +1076,14 @@ namespace ZL
|
||||
{
|
||||
if (event.key.keysym.sym == SDLK_i)
|
||||
{
|
||||
Environment::shipVelocity += 500.f;
|
||||
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_k)
|
||||
{
|
||||
Environment::shipVelocity -= 500.f;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_o)
|
||||
{
|
||||
Environment::shipVelocity += 50.f;
|
||||
//x = x + 2.0;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_l)
|
||||
{
|
||||
Environment::shipVelocity -= 50.f;
|
||||
//x = x - 2.0;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
render();
|
||||
mainThreadHandler.processMainThreadTasks();
|
||||
networkClient->Poll();
|
||||
}
|
||||
|
||||
void Game::handleDown(int mx, int my)
|
||||
@@ -1101,6 +1116,7 @@ namespace ZL
|
||||
Environment::tapDownCurrentPos(1) = my;
|
||||
}
|
||||
}
|
||||
|
||||
void Game::handleUp(int mx, int my)
|
||||
{
|
||||
int uiX = mx;
|
||||
@@ -1126,5 +1142,28 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
std::string Game::formPingMessageContent()
|
||||
{
|
||||
Eigen::Quaternionf q(Environment::shipMatrix);
|
||||
|
||||
std::string pingMsg = std::to_string(Environment::shipPosition.x()) + ":"
|
||||
+ std::to_string(Environment::shipPosition.y()) + ":"
|
||||
+ std::to_string(Environment::shipPosition.z()) + ":"
|
||||
+ std::to_string(q.w()) + ":"
|
||||
+ std::to_string(q.x()) + ":"
|
||||
+ std::to_string(q.y()) + ":"
|
||||
+ std::to_string(q.z()) + ":"
|
||||
+ std::to_string(Environment::currentAngularVelocity.x()) + ":"
|
||||
+ std::to_string(Environment::currentAngularVelocity.y()) + ":"
|
||||
+ std::to_string(Environment::currentAngularVelocity.z()) + ":"
|
||||
+ std::to_string(Environment::shipVelocity) + ":"
|
||||
+ std::to_string(Environment::shipSelectedVelocity) + ":"
|
||||
+ std::to_string(Environment::lastSentMagnitude) + ":" // Используем те же static переменные из блока ROT
|
||||
+ std::to_string(Environment::lastSentAngle);
|
||||
|
||||
return pingMsg;
|
||||
}*/
|
||||
|
||||
|
||||
} // namespace ZL
|
||||
Reference in new issue
Block a user