93 lines
2.6 KiB
C++
93 lines
2.6 KiB
C++
#include "asteroid/game.h"
|
|
#include "glfw/glfw_initialization.h"
|
|
#include "glfw/glfw_monitor.h"
|
|
#include "glfw/glfw_window.h"
|
|
#include "socket/iocp.h"
|
|
#include "socket/packet.h"
|
|
#include "socket/tcp_socket.h"
|
|
#include "socket/udp_socket.h"
|
|
#include "socket/wsa_manager.h"
|
|
#include "utils/ConfigManager.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"
|
|
|
|
std::uint8_t CLIENTID = 0;
|
|
|
|
std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
|
Network::WSAManager wsamanager;
|
|
|
|
auto config = utils::ConfigManager::load();
|
|
utils::setDefaultLogger(config.logLevel, config.logFileName,
|
|
config.logfileSize, config.logfileCount);
|
|
|
|
utils::ThreadPool tp(0);
|
|
Network::IOCP iocp;
|
|
iocp.init(&tp, SessionProtocol::TCP);
|
|
|
|
Network::Address addr;
|
|
|
|
addr.set(config.ipVersion, config.IP, config.Port);
|
|
|
|
std::shared_ptr<Network::TCPSocket> TCPSock =
|
|
std::make_shared<Network::TCPSocket>(config.ipVersion);
|
|
if (TCPSock->connect(addr) == INVALID_SOCKET) {
|
|
spdlog::error("connect()");
|
|
std::exit(EXIT_FAILURE);
|
|
}
|
|
iocp.registerSocket(TCPSock);
|
|
|
|
auto result = iocp.recv(TCPSock, 14);
|
|
auto header_serialized = utils::CvtListToVector(result.get());
|
|
|
|
Packet::Header header;
|
|
header.Deserialize(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;
|
|
|
|
veng::Window window("Asteroid", {800, 600});
|
|
window.TryMoveToMonitor(0);
|
|
|
|
veng::Graphics graphics(&window);
|
|
veng::Engine engine(&graphics, &tp, &iocp);
|
|
|
|
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 = [ID64 = config.playerid](veng::Engine& engine) {
|
|
utils::Snowflake ID;
|
|
ID.snowflake = ID64;
|
|
BeginPlay(engine, ID);
|
|
};
|
|
engine.Tick = Tick;
|
|
|
|
engine.init();
|
|
|
|
std::shared_ptr<veng::Model> const player = engine.GetSpawnedObject("player");
|
|
config.playerid = player->ID.snowflake;
|
|
utils::ConfigManager::save(config);
|
|
|
|
tp.enqueueJob(
|
|
[engine = &engine, TCPSock](utils::ThreadPool* tp, std::uint32_t __) {
|
|
engine->ResponseToServerAndRefresh(TCPSock);
|
|
},
|
|
0);
|
|
|
|
while (!window.ShouldClose()) {
|
|
glfwPollEvents();
|
|
|
|
engine.Update();
|
|
engine.NetUpdate(TCPSock);
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|