iocp 구현하기

This commit is contained in:
2025-05-31 03:19:58 +09:00
parent 466a80f02b
commit a65483a9c3
55 changed files with 608 additions and 683 deletions

View File

@@ -0,0 +1,64 @@
#include "asteroid/game.h"
#include "vulkan_engine/vulkan/engine.h"
void BeginPlay(veng::Engine& engine) {
veng::Model* const player = engine.SpawnModel("player", "player");
player->scale = glm::vec3(.02f);
player->colision = true;
player->OnColision = [](veng::Model* self, veng::Model* other) {
if (other->owner == self) return;
spdlog::info("{} and {} is nearby.", (void*)self, (void*)other);
spdlog::info("{} 's owner: {}", (void*)self, (void*)self->owner);
spdlog::info("{} 's owner: {}", (void*)other, (void*)other->owner);
other->colision = false;
other->visible = false;
};
veng::Model* const player_flame =
engine.SpawnModel("player_flame", "player_flame");
player_flame->scale = player->scale;
player_flame->colision = false;
spdlog::info("player addr: {}", (void*)player);
veng::Model* const other_player = engine.SpawnModel("player", "other_player");
other_player->position = glm::vec3(1.f, 0.f, 0.f);
other_player->scale = glm::vec3(.02f);
other_player->colision = true;
other_player->OnColision = [](veng::Model* self, veng::Model* other) {
if (other->owner == self) return;
spdlog::info("{} and {} is nearby.", (void*)self, (void*)other);
spdlog::info("{} 's owner: {}", (void*)self, (void*)self->owner);
spdlog::info("{} 's owner: {}", (void*)other, (void*)other->owner);
other->colision = false;
other->visible = false;
};
spdlog::info("other player addr: {}", (void*)other_player);
veng::Model* const camera_lag = engine.SpawnModel("", "camera_lag");
camera_lag->colision = false;
camera_lag->position = player->position;
veng::Model* const background = engine.SpawnModel("", "background");
background->colision = false;
background->position = {background->position.x, background->position.y, 30.f};
background->scale *= 100;
veng::Model* const background0 =
engine.SpawnModel("background", "background0");
background0->scale = background->scale;
veng::Model* const background1 =
engine.SpawnModel("background", "background1");
background1->scale = background->scale;
veng::Model* const background2 =
engine.SpawnModel("background", "background2");
background2->scale = background->scale;
veng::Model* const background3 =
engine.SpawnModel("background", "background3");
background3->scale = background->scale;
}

View File

@@ -0,0 +1,37 @@
#include "asteroid/game.h"
#include "glfw/glfw_initialization.h"
#include "glfw/glfw_monitor.h"
#include "glfw/glfw_window.h"
#include "vulkan_engine/vulkan/engine.h"
#include "vulkan_engine/vulkan/graphics.h"
#include "socket/iocp.h"
std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
Network::IOCP iocp;
const veng::GlfwInitialization _glfw;
veng::Window window("Vulkan Engine", {800, 600});
window.TryMoveToMonitor(0);
veng::Graphics graphics(&window);
veng::Engine engine(&graphics);
engine.LoadModelAsset("assets/player.fbx", "player");
engine.LoadModelAsset("assets/player_flame.fbx", "player_flame");
engine.LoadModelAsset("assets/bullet.fbx", "bullet");
engine.LoadModelAsset("assets/background.fbx", "background");
engine.BeginPlay = BeginPlay;
engine.Tick = Tick;
engine.init();
while (!window.ShouldClose()) {
glfwPollEvents();
engine.Update();
}
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,107 @@
#include "asteroid/game.h"
#include "vulkan_engine/vulkan/engine.h"
void Tick(veng::Engine& engine, std::float_t delta_time) {
static std::float_t bullet_cooldown = 0.f;
veng::Model* const player = engine.GetSpawnedObject("player");
veng::Model* const player_flame = engine.GetSpawnedObject("player_flame");
veng::Model* const camera_lag = engine.GetSpawnedObject("camera_lag");
veng::Model* const background = engine.GetSpawnedObject("background");
veng::Model* const background0 = engine.GetSpawnedObject("background0");
veng::Model* const background1 = engine.GetSpawnedObject("background1");
veng::Model* const background2 = engine.GetSpawnedObject("background2");
veng::Model* const background3 = engine.GetSpawnedObject("background3");
glm::vec3 forward = player->rotation * glm::vec3(0, 1, 0);
glm::vec3 right = player->rotation * glm::vec3(1, 0, 0);
std::float_t stiffness =
500.0f * ((glm::length(player->linear_velocity) > 1.f)
? glm::length(player->linear_velocity)
: 1.f); // 더 크면 빠르게 따라감
std::float_t damping = 10.f * glm::sqrt(stiffness); // 임계 감쇠
// 감쇠 스프링 업데이트
glm::vec3 displacement = camera_lag->position - player->position;
camera_lag->linear_velocity +=
(-stiffness * displacement - damping * camera_lag->linear_velocity) *
delta_time;
engine.view = glm::lookAt(
glm::vec3(camera_lag->position.x, camera_lag->position.y, -5.f),
camera_lag->position, glm::vec3(0.f, -1.f, 0.f));
if (glfwGetKey(engine.vulkan_graphics->window->GetHandle(), GLFW_KEY_W) ==
GLFW_PRESS) {
player->linear_acceleration = glm::normalize(forward) * 10.f;
player_flame->visible = true;
} else {
player->linear_acceleration = forward * .0f;
player_flame->visible = false;
}
if (bullet_cooldown > std::numeric_limits<std::float_t>::epsilon()) {
bullet_cooldown -= delta_time;
}
if (glfwGetKey(engine.vulkan_graphics->window->GetHandle(), GLFW_KEY_SPACE) ==
GLFW_PRESS) {
if (bullet_cooldown > std::numeric_limits<std::float_t>::epsilon()) {
bullet_cooldown -= delta_time;
} else {
bullet_cooldown = .2f;
veng::Model* const bullet =
engine.SpawnLifedModel("bullet", "bullet", 10.f);
bullet->linear_velocity = player->linear_velocity + forward * 10.f;
bullet->position = player->position + forward * player->scale.x * 10.f;
bullet->owner = player;
bullet->scale = player->scale;
bullet->colision = true;
spdlog::info("bullet address: {}", (void*)bullet);
}
}
if (glfwGetKey(engine.vulkan_graphics->window->GetHandle(), GLFW_KEY_A) ==
GLFW_PRESS) {
right = player->rotation * glm::vec3(0, 0, 1);
player->angular_velocity = right * 6.f;
} else if (glfwGetKey(engine.vulkan_graphics->window->GetHandle(),
GLFW_KEY_D) == GLFW_PRESS) {
right = player->rotation * glm::vec3(0, 0, 1);
player->angular_velocity = right * -6.f;
} else {
right = player->rotation * glm::vec3(0, 0, 1);
player->angular_velocity = right * 0.f;
}
player_flame->rotation = player->rotation;
player_flame->position =
player->position + player->rotation * player_flame->original_offset *
0.5f * player_flame->scale;
if (player->position.x - background->position.x >= background->scale.x)
background->position += glm::vec3(2.f, 0.f, 0.f) * background->scale;
if (player->position.x - background->position.x < -background->scale.x)
background->position -= glm::vec3(2.f, 0.f, 0.f) * background->scale;
if (player->position.y - background->position.y >= background->scale.y)
background->position += glm::vec3(0.f, 2.f, 0.f) * background->scale;
if (player->position.y - background->position.y < -background->scale.y)
background->position -= glm::vec3(0.f, 2.f, 0.f) * background->scale;
glm::vec3 sparse;
sparse = glm::vec3(1.f, 1.f, 0.f);
background0->position = background->position + sparse * background->scale;
sparse = glm::vec3(-1.f, 1.f, 0.f);
background1->position = background->position + sparse * background->scale;
sparse = glm::vec3(1.f, -1.f, 0.f);
background2->position = background->position + sparse * background->scale;
sparse = glm::vec3(-1.f, -1.f, 0.f);
background3->position = background->position + sparse * background->scale;
}