일단 오늘은 이걸로..
This commit is contained in:
@@ -146,7 +146,7 @@ void Engine::Update() {
|
||||
vulkan_graphics->RenderModel(it.second);
|
||||
}
|
||||
|
||||
physics_controller_.invokeOnColisionEvent(thread_pool_, models_);
|
||||
Physics::invokeOnColisionEvent(thread_pool_, models_);
|
||||
|
||||
vulkan_graphics->EndFrame();
|
||||
}
|
||||
@@ -240,7 +240,7 @@ void Engine::ResponseToServerAndRefresh(std::shared_ptr<Network::Socket> sock) {
|
||||
for (auto& it : models_) {
|
||||
if (it.second->ID == model->ID) {
|
||||
Interpolation(header, it.second, model);
|
||||
spdlog::debug("model updated: [{}:{}]", model->name, model->ID.snowflake);
|
||||
// spdlog::debug("model updated: [{}:{}]", model->name, model->ID.snowflake);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -250,8 +250,17 @@ void Engine::ResponseToServerAndRefresh(std::shared_ptr<Network::Socket> sock) {
|
||||
auto spawnedModel =
|
||||
SpawnLifedModel(model->asset_name, model->name, model->lifespan);
|
||||
std::lock_guard lock(spawnedModel->modding);
|
||||
|
||||
spawnedModel->ID = model->ID;
|
||||
spawnedModel->position = model->position;
|
||||
spawnedModel->linear_velocity = model->linear_velocity;
|
||||
spawnedModel->linear_acceleration = model->linear_acceleration;
|
||||
|
||||
spawnedModel->rotation = model->rotation;
|
||||
spawnedModel->angular_velocity = model->angular_velocity;
|
||||
spawnedModel->angular_acceleration = model->angular_acceleration;
|
||||
|
||||
spawnedModel->scale = model->scale;
|
||||
spawnedModel->transform = model->transform;
|
||||
|
||||
spawnedModel->original_offset = model->original_offset;
|
||||
spawnedModel->radius = model->radius;
|
||||
@@ -260,11 +269,21 @@ void Engine::ResponseToServerAndRefresh(std::shared_ptr<Network::Socket> sock) {
|
||||
spawnedModel->visible = model->visible;
|
||||
spawnedModel->colision = model->colision;
|
||||
spawnedModel->networkReplicated = false;
|
||||
|
||||
Interpolation(header, spawnedModel, model);
|
||||
spdlog::info("model spawned: {}", model->ID.snowflake);
|
||||
}
|
||||
} break;
|
||||
case Packet::Opcode::DESPAWNMODEL: {
|
||||
std::shared_ptr<veng::Model> model = std::make_shared<veng::Model>();
|
||||
model->Deserialize(recv_data);
|
||||
|
||||
for (auto it = models_.begin(); it != models_.end();) {
|
||||
if (it->second->ID == model->ID) {
|
||||
models_.erase(it);
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
spdlog::error("unknown data type");
|
||||
}
|
||||
|
||||
@@ -12,18 +12,23 @@ void Physics::invokeOnColisionEvent(
|
||||
for (std::unordered_map<std::string, std::shared_ptr<Model>>::iterator
|
||||
iter_A = models.begin();
|
||||
iter_A != models.end(); iter_A++) {
|
||||
auto model_A = iter_A->second;
|
||||
if (!model_A->colision) continue;
|
||||
for (auto iter_B = std::next(iter_A); iter_B != models.end(); iter_B++) {
|
||||
auto model_A = iter_A->second;
|
||||
std::lock_guard<std::mutex> Alock(model_A->modding);
|
||||
auto model_B = iter_B->second;
|
||||
if (!model_B->colision) continue;
|
||||
std::lock_guard<std::mutex> Block(model_B->modding);
|
||||
if (!model_A->colision || !model_B->colision) continue;
|
||||
std::float_t distance =
|
||||
glm::distance(model_A->position, model_B->position);
|
||||
std::float_t modelA_radius = model_A->radius * model_A->scale.x;
|
||||
std::float_t modelB_radius = model_B->radius * model_B->scale.x;
|
||||
if (distance <= modelA_radius + modelB_radius) {
|
||||
model_A = iter_A->second;
|
||||
model_B = iter_B->second;
|
||||
if (model_A->OnColision)
|
||||
thread_pool->enqueueJob(model_A->OnColision, model_A, model_B);
|
||||
model_A = iter_A->second;
|
||||
model_B = iter_B->second;
|
||||
if (model_B->OnColision)
|
||||
thread_pool->enqueueJob(model_B->OnColision, model_A, model_B);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user