일단은 멀티로 접속이 됨..
This commit is contained in:
@@ -1,78 +1,104 @@
|
||||
#include "asteroid/game.h"
|
||||
|
||||
#include "vulkan_engine/vulkan/engine.h"
|
||||
|
||||
|
||||
void BeginPlay(veng::Engine& engine) {
|
||||
std::random_device rd;
|
||||
std::mt19937 gen = std::mt19937(rd());
|
||||
std::uniform_real_distribution<float> jitterDist = std::uniform_real_distribution<float>(-2, 2);
|
||||
std::uniform_real_distribution<float> jitterDist =
|
||||
std::uniform_real_distribution<float>(-2, 2);
|
||||
|
||||
veng::Model* const player = engine.SpawnLifedModel("player", "player", -1);
|
||||
player->position = glm::vec3(jitterDist(gen), jitterDist(gen), 0.f);
|
||||
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);
|
||||
std::shared_ptr<veng::Model> const player =
|
||||
engine.SpawnLifedModel("player", "player", -1);
|
||||
{
|
||||
std::lock_guard lock(player->modding);
|
||||
player->position = glm::vec3(jitterDist(gen), jitterDist(gen), 0.f);
|
||||
player->scale = glm::vec3(.02f);
|
||||
player->colision = true;
|
||||
player->OnColision = [](std::shared_ptr<veng::Model> self,
|
||||
std::shared_ptr<veng::Model> other) {
|
||||
auto self_owner = self->owner.lock();
|
||||
auto other_owner = other->owner.lock();
|
||||
if (other_owner == nullptr || self_owner == nullptr) return;
|
||||
if (other_owner->ID == self->ID) return;
|
||||
spdlog::info("[{}:{}] and [{}:{}] is nearby.", self->name,
|
||||
self->ID.snowflake, other->name, other->ID.snowflake);
|
||||
|
||||
spdlog::info("{} 's owner: {}", (void*)self, (void*)self->owner);
|
||||
spdlog::info("{} 's owner: {}", (void*)other, (void*)other->owner);
|
||||
spdlog::info("[{}:{}] 's owner: [{}:{}]", self->name, self->ID.snowflake,
|
||||
self_owner->name, self_owner->ID.snowflake);
|
||||
spdlog::info("[{}:{}] 's owner: [{}:{}]", other->name,
|
||||
other->ID.snowflake, other_owner->name,
|
||||
other_owner->ID.snowflake);
|
||||
|
||||
other->colision = false;
|
||||
other->visible = false;
|
||||
other->shouldBeDestroyed = true;
|
||||
};
|
||||
veng::Model* const player_flame =
|
||||
other->colision = false;
|
||||
other->visible = false;
|
||||
other->shouldBeDestroyed = true;
|
||||
};
|
||||
}
|
||||
|
||||
std::shared_ptr<veng::Model> const player_flame =
|
||||
engine.SpawnLifedModel("player_flame", "player_flame", -1);
|
||||
player_flame->scale = player->scale;
|
||||
player_flame->colision = false;
|
||||
player_flame->networkReplicated = false;
|
||||
{
|
||||
std::lock_guard lock(player_flame->modding);
|
||||
player_flame->scale = player->scale;
|
||||
player_flame->colision = false;
|
||||
player_flame->networkReplicated = true;
|
||||
player_flame->needsUpdate = true;
|
||||
}
|
||||
|
||||
spdlog::info("player addr: {}", (void*)player);
|
||||
std::shared_ptr<veng::Model> const other_player =
|
||||
engine.SpawnLifedModel("player", "other_player", -1);
|
||||
{
|
||||
std::lock_guard lock(other_player->modding);
|
||||
other_player->position = glm::vec3(1.f, 0.f, 0.f);
|
||||
other_player->scale = glm::vec3(.02f);
|
||||
other_player->colision = true;
|
||||
}
|
||||
|
||||
veng::Model* const other_player = engine.SpawnLifedModel("player", "other_player", -1);
|
||||
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);
|
||||
std::shared_ptr<veng::Model> const camera_lag =
|
||||
engine.SpawnLifedModel("", "camera_lag", -1);
|
||||
{
|
||||
std::lock_guard lock(camera_lag->modding);
|
||||
camera_lag->colision = false;
|
||||
camera_lag->position = player->position;
|
||||
}
|
||||
|
||||
spdlog::info("{} 's owner: {}", (void*)self, (void*)self->owner);
|
||||
spdlog::info("{} 's owner: {}", (void*)other, (void*)other->owner);
|
||||
std::shared_ptr<veng::Model> const background =
|
||||
engine.SpawnLifedModel("", "background", -1);
|
||||
{
|
||||
std::lock_guard lock(background->modding);
|
||||
background->colision = false;
|
||||
background->position = {background->position.x, background->position.y,
|
||||
30.f};
|
||||
background->scale *= 100;
|
||||
background->networkReplicated = false;
|
||||
}
|
||||
|
||||
other->colision = false;
|
||||
other->visible = false;
|
||||
other->shouldBeDestroyed = true;
|
||||
};
|
||||
|
||||
spdlog::info("other player addr: {}", (void*)other_player);
|
||||
|
||||
veng::Model* const camera_lag = engine.SpawnLifedModel("", "camera_lag", -1);
|
||||
camera_lag->colision = false;
|
||||
camera_lag->position = player->position;
|
||||
|
||||
veng::Model* const background = engine.SpawnLifedModel("", "background", -1);
|
||||
background->colision = false;
|
||||
background->position = {background->position.x, background->position.y, 30.f};
|
||||
background->scale *= 100;
|
||||
background->networkReplicated = false;
|
||||
|
||||
veng::Model* const background0 =
|
||||
std::shared_ptr<veng::Model> const background0 =
|
||||
engine.SpawnLifedModel("background", "background0", -1);
|
||||
background0->scale = background->scale;
|
||||
background0->networkReplicated = false;
|
||||
veng::Model* const background1 =
|
||||
{
|
||||
std::lock_guard lock(background0->modding);
|
||||
background0->scale = background->scale;
|
||||
background0->networkReplicated = false;
|
||||
}
|
||||
std::shared_ptr<veng::Model> const background1 =
|
||||
engine.SpawnLifedModel("background", "background1", -1);
|
||||
background1->scale = background->scale;
|
||||
background1->networkReplicated = false;
|
||||
veng::Model* const background2 =
|
||||
{
|
||||
std::lock_guard lock(background1->modding);
|
||||
background1->scale = background->scale;
|
||||
background1->networkReplicated = false;
|
||||
}
|
||||
std::shared_ptr<veng::Model> const background2 =
|
||||
engine.SpawnLifedModel("background", "background2", -1);
|
||||
background2->scale = background->scale;
|
||||
background2->networkReplicated = false;
|
||||
veng::Model* const background3 =
|
||||
{
|
||||
std::lock_guard lock(background2->modding);
|
||||
background2->scale = background->scale;
|
||||
background2->networkReplicated = false;
|
||||
}
|
||||
std::shared_ptr<veng::Model> const background3 =
|
||||
engine.SpawnLifedModel("background", "background3", -1);
|
||||
background3->scale = background->scale;
|
||||
background3->networkReplicated = false;
|
||||
{
|
||||
std::lock_guard lock(background3->modding);
|
||||
background3->scale = background->scale;
|
||||
background3->networkReplicated = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "socket/wsa_manager.h"
|
||||
#include "utils/log.h"
|
||||
#include "utils/snowflake.h"
|
||||
#include "utils/utils.h"
|
||||
#include "vulkan_engine/vulkan/engine.h"
|
||||
#include "vulkan_engine/vulkan/graphics.h"
|
||||
|
||||
@@ -28,28 +29,24 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
||||
|
||||
addr.set(AF_INET6, "::1", 9010);
|
||||
|
||||
Network::TCPSocket TCPSock;
|
||||
TCPSock.init(AF_INET6);
|
||||
if (TCPSock.connect(addr) == INVALID_SOCKET) {
|
||||
std::shared_ptr<Network::TCPSocket> TCPSock =
|
||||
std::make_shared<Network::TCPSocket>();
|
||||
TCPSock->init(AF_INET6);
|
||||
if (TCPSock->connect(addr) == INVALID_SOCKET) {
|
||||
spdlog::error("connect()");
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
iocp.registerTCPSocket(TCPSock, 16 * 1024);
|
||||
iocp.registerSocket(TCPSock);
|
||||
|
||||
auto result = iocp.recv(TCPSock, 14);
|
||||
auto header_serialized = utils::CvtListToVector(result.get());
|
||||
|
||||
while (iocp.GetRecvedBytes(TCPSock.sock) < 6);
|
||||
std::vector<char> header_serialized(6);
|
||||
iocp.recv(TCPSock, header_serialized);
|
||||
Packet::Header header;
|
||||
header.Deserialize(header_serialized);
|
||||
while (iocp.GetRecvedBytes(TCPSock.sock) < header.body_length);
|
||||
std::vector<char> data(header.body_length);
|
||||
iocp.recv(TCPSock, data);
|
||||
::memcpy(&CLIENTID, data.data(), 1); //id 받기
|
||||
|
||||
header.opcode = Packet::Opcode::CLIENTID;
|
||||
header.body_length = 0;
|
||||
header_serialized = header.Serialize();
|
||||
iocp.send(TCPSock, header_serialized);
|
||||
result = iocp.recv(TCPSock, header.body_length);
|
||||
std::vector<char> data = utils::CvtListToVector(result.get());
|
||||
::memcpy(&CLIENTID, data.data(), 1); // id 받기
|
||||
|
||||
const veng::GlfwInitialization _glfw;
|
||||
|
||||
@@ -69,11 +66,17 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
||||
|
||||
engine.init();
|
||||
|
||||
tp.enqueueJob(
|
||||
[engine = &engine, TCPSock](utils::ThreadPool* tp, std::uint32_t __) {
|
||||
engine->ResponseToServerAndRefresh(TCPSock);
|
||||
},
|
||||
0);
|
||||
|
||||
while (!window.ShouldClose()) {
|
||||
glfwPollEvents();
|
||||
|
||||
engine.Update();
|
||||
engine.NetUpdate(std::make_shared<Network::Socket>(TCPSock));
|
||||
engine.NetUpdate(TCPSock);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -5,15 +5,26 @@
|
||||
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");
|
||||
std::shared_ptr<veng::Model> const player = engine.GetSpawnedObject("player");
|
||||
std::shared_ptr<veng::Model> const player_flame = engine.GetSpawnedObject("player_flame");
|
||||
std::shared_ptr<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");
|
||||
std::shared_ptr<veng::Model> const background = engine.GetSpawnedObject("background");
|
||||
std::shared_ptr<veng::Model> const background0 = engine.GetSpawnedObject("background0");
|
||||
std::shared_ptr<veng::Model> const background1 = engine.GetSpawnedObject("background1");
|
||||
std::shared_ptr<veng::Model> const background2 = engine.GetSpawnedObject("background2");
|
||||
std::shared_ptr<veng::Model> const background3 = engine.GetSpawnedObject("background3");
|
||||
|
||||
std::lock_guard<std::mutex> lock[] = {
|
||||
std::lock_guard<std::mutex>(player->modding),
|
||||
std::lock_guard<std::mutex>(player_flame->modding),
|
||||
std::lock_guard<std::mutex>(camera_lag->modding),
|
||||
std::lock_guard<std::mutex>(background->modding),
|
||||
std::lock_guard<std::mutex>(background0->modding),
|
||||
std::lock_guard<std::mutex>(background1->modding),
|
||||
std::lock_guard<std::mutex>(background2->modding),
|
||||
std::lock_guard<std::mutex>(background3->modding)
|
||||
};
|
||||
|
||||
glm::vec3 forward = player->rotation * glm::vec3(0, 1, 0);
|
||||
glm::vec3 right = player->rotation * glm::vec3(1, 0, 0);
|
||||
@@ -43,8 +54,11 @@ void Tick(veng::Engine& engine, std::float_t delta_time) {
|
||||
GLFW_PRESS) {
|
||||
player->linear_acceleration = glm::normalize(forward) * 10.f;
|
||||
player_flame->visible = true;
|
||||
player->needsUpdate = true;
|
||||
w_laststate = true;
|
||||
|
||||
if (!w_laststate) {
|
||||
player->needsUpdate = true;
|
||||
w_laststate = true;
|
||||
}
|
||||
} else {
|
||||
player->linear_acceleration = forward * .0f;
|
||||
player_flame->visible = false;
|
||||
@@ -63,17 +77,35 @@ void Tick(veng::Engine& engine, std::float_t delta_time) {
|
||||
bullet_cooldown -= delta_time;
|
||||
} else {
|
||||
bullet_cooldown = .2f;
|
||||
veng::Model* const bullet =
|
||||
std::shared_ptr<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;
|
||||
bullet->OnColision = [](std::shared_ptr<veng::Model> self,
|
||||
std::shared_ptr<veng::Model> other) {
|
||||
auto self_owner = self->owner.lock();
|
||||
auto other_owner = other->owner.lock();
|
||||
if (other_owner == nullptr || self_owner == nullptr) return;
|
||||
if (other_owner->ID == self->ID) return;
|
||||
spdlog::info("[{}:{}] and [{}:{}] is nearby.", self->name,
|
||||
self->ID.snowflake, other->name, other->ID.snowflake);
|
||||
|
||||
spdlog::info("[{}:{}] 's owner: [{}:{}]", self->name,
|
||||
self->ID.snowflake, self_owner->name,
|
||||
self_owner->ID.snowflake);
|
||||
spdlog::info("[{}:{}] 's owner: [{}:{}]", other->name,
|
||||
other->ID.snowflake, other_owner->name,
|
||||
other_owner->ID.snowflake);
|
||||
|
||||
other->colision = false;
|
||||
other->visible = false;
|
||||
other->shouldBeDestroyed = true;
|
||||
};
|
||||
bullet->networkReplicated = true;
|
||||
bullet->needsUpdate = true;
|
||||
|
||||
spdlog::info("bullet address: {}", (void*)bullet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,14 +114,18 @@ void Tick(veng::Engine& engine, std::float_t delta_time) {
|
||||
GLFW_PRESS) {
|
||||
right = player->rotation * glm::vec3(0, 0, 1);
|
||||
player->angular_velocity = right * 6.f;
|
||||
player->needsUpdate = true;
|
||||
ad_laststate = true;
|
||||
if (!ad_laststate) {
|
||||
player->needsUpdate = true;
|
||||
ad_laststate = true;
|
||||
}
|
||||
} 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;
|
||||
player->needsUpdate = true;
|
||||
ad_laststate = true;
|
||||
if (!ad_laststate) {
|
||||
player->needsUpdate = true;
|
||||
ad_laststate = true;
|
||||
}
|
||||
} else {
|
||||
right = player->rotation * glm::vec3(0, 0, 1);
|
||||
player->angular_velocity = right * 0.f;
|
||||
|
||||
Reference in New Issue
Block a user