Compare commits
No commits in common. "c6d9a2cd777aab63031fd462be167e4603c189ab" and "35008f9304e2f7d2d08224fe50eeb72026dcbc70" have entirely different histories.
c6d9a2cd77
...
35008f9304
39
shell.html
39
shell.html
@ -3,7 +3,7 @@
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Fekalni gtacko</title>
|
||||
<title>PortalGame</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||
|
||||
<style>
|
||||
@ -14,7 +14,6 @@
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
background: black;
|
||||
color: aqua;
|
||||
}
|
||||
|
||||
canvas {
|
||||
@ -26,30 +25,15 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<canvas id="canvas" oncontextmenu="event.preventDefault()" style="display:none"></canvas>
|
||||
|
||||
<div id="loginform">
|
||||
<h1>fekální gtačko</h1>
|
||||
|
||||
<form>
|
||||
kdo <input type="text" name="name" id="name"><br>
|
||||
kam <input type="text" name="url" id="url"><br>
|
||||
<input type="button" value="0k" onclick="ok()">
|
||||
</form>
|
||||
</div>
|
||||
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
|
||||
|
||||
<script>
|
||||
var inited = false;
|
||||
|
||||
var Module = {
|
||||
preRun: [],
|
||||
postRun: [],
|
||||
canvas: (function() {
|
||||
return document.getElementById('canvas');
|
||||
})(),
|
||||
onRuntimeInitialized: function() {
|
||||
inited = true;
|
||||
}
|
||||
})()
|
||||
};
|
||||
|
||||
// Resize canvas to fit the window and inform SDL (via Emscripten)
|
||||
@ -67,23 +51,6 @@
|
||||
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
window.addEventListener('load', resizeCanvas);
|
||||
|
||||
function ok()
|
||||
{
|
||||
if (!inited)
|
||||
return;
|
||||
|
||||
const name = document.getElementById("name").value;
|
||||
const url = document.getElementById("url").value;
|
||||
|
||||
Module.ccall("SetName", name);
|
||||
Module.ccall("SetUrl", url);
|
||||
|
||||
document.getElementById("loginform").style = "display:none";
|
||||
document.getElementById("canvas").style = "";
|
||||
|
||||
Module.ccall("RunMain");
|
||||
}
|
||||
</script>
|
||||
|
||||
{{{ SCRIPT }}}
|
||||
|
||||
@ -4,13 +4,13 @@
|
||||
|
||||
#include "utils/bufferput.hpp"
|
||||
|
||||
assets::MeshBuilder::MeshBuilder(gfx::MeshFlags mflags) : mflags_(mflags)
|
||||
{
|
||||
mesh_ = std::make_shared<Mesh>();
|
||||
}
|
||||
assets::MeshBuilder::MeshBuilder(gfx::MeshFlags mflags) : mflags_(mflags) {}
|
||||
|
||||
void assets::MeshBuilder::BeginSurface(gfx::SurfaceFlags sflags, const std::string& name, std::shared_ptr<const gfx::Texture> texture)
|
||||
{
|
||||
if (!mesh_)
|
||||
mesh_ = std::make_shared<Mesh>();
|
||||
|
||||
FinalizeSurface();
|
||||
|
||||
gfx::Surface surface;
|
||||
|
||||
@ -34,9 +34,6 @@ public:
|
||||
void SetTime(float time) { time_ = time; }
|
||||
void SetViewportSize(int width, int height) { viewport_size_ = {width, height}; }
|
||||
|
||||
void SetUserName(const std::string& username) { username_ = username; }
|
||||
const std::string& GetUserName() const { return username_; }
|
||||
|
||||
void Input(game::PlayerInputType in, bool pressed, bool repeated);
|
||||
void MouseMove(const glm::vec2& delta);
|
||||
|
||||
@ -74,7 +71,6 @@ private:
|
||||
|
||||
audio::Master audiomaster_;
|
||||
|
||||
std::string username_;
|
||||
std::unique_ptr<game::view::ClientSession> session_;
|
||||
|
||||
std::deque<ChatMessage> chat_;
|
||||
|
||||
@ -28,20 +28,11 @@
|
||||
#include "app.hpp"
|
||||
#include "gl.hpp"
|
||||
|
||||
static std::string s_username;
|
||||
static std::string s_url;
|
||||
|
||||
static SDL_Window *s_window = nullptr;
|
||||
static SDL_GLContext s_context = nullptr;
|
||||
static bool s_quit = false;
|
||||
static std::unique_ptr<App> s_app;
|
||||
|
||||
struct ClientConfig
|
||||
{
|
||||
std::string username;
|
||||
std::string url;
|
||||
};
|
||||
|
||||
static void ThrowSDLError(const std::string& message)
|
||||
{
|
||||
std::string error = SDL_GetError();
|
||||
@ -75,7 +66,7 @@ static void InitSDL()
|
||||
|
||||
std::cout << "Creating SDL window..." << std::endl;
|
||||
s_window =
|
||||
SDL_CreateWindow("Fekalni gtacko", 100, 100, 640, 480,
|
||||
SDL_CreateWindow("PortalGame", 100, 100, 640, 480,
|
||||
SDL_WINDOW_SHOWN /* | SDL_WINDOW_MAXIMIZED */| SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
if (!s_window)
|
||||
{
|
||||
@ -154,7 +145,6 @@ static const std::map<SDL_Scancode, game::PlayerInputType> s_inputmap = {
|
||||
{ SDL_SCANCODE_A, game::IN_LEFT },
|
||||
{ SDL_SCANCODE_D, game::IN_RIGHT },
|
||||
{ SDL_SCANCODE_SPACE, game::IN_JUMP },
|
||||
{ SDL_SCANCODE_LSHIFT, game::IN_SPRINT },
|
||||
{ SDL_SCANCODE_LCTRL, game::IN_CROUCH },
|
||||
{ SDL_SCANCODE_E, game::IN_USE },
|
||||
{ SDL_SCANCODE_F3, game::IN_DEBUG1 },
|
||||
@ -393,10 +383,7 @@ static void Frame()
|
||||
}
|
||||
|
||||
static void Main() {
|
||||
if (s_url.empty())
|
||||
s_url = WS_URL;
|
||||
|
||||
if (!WSInit(s_url.c_str()))
|
||||
if (!WSInit(WS_URL))
|
||||
return;
|
||||
|
||||
InitSDL();
|
||||
@ -413,10 +400,8 @@ static void Main() {
|
||||
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
|
||||
|
||||
s_app = std::make_unique<App>();
|
||||
s_app->SetUserName(s_username);
|
||||
s_app->AddChatMessagePrefix("WebSocket", "připojování na " + s_url);
|
||||
s_app->AddChatMessagePrefix("WebSocket", "připojování na " + std::string(WS_URL));
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten_set_main_loop(Frame, 0, true);
|
||||
@ -453,10 +438,7 @@ static void Main() {
|
||||
#endif // EMSCRIPTEN
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void RunMain()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
try {
|
||||
Main();
|
||||
@ -464,35 +446,8 @@ void RunMain()
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "[ERROR] " << e.what() << std::endl;
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", e.what(), nullptr);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
void SetName(const char* name)
|
||||
{
|
||||
s_username = name;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void SetUrl(const char* url)
|
||||
{
|
||||
s_url = url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SetName("random guvno");
|
||||
RunMain();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -155,9 +155,7 @@ void game::Character::SyncTransformFromController()
|
||||
void game::Character::UpdateMovement()
|
||||
{
|
||||
constexpr float dt = 1.0f / 25.0f;
|
||||
constexpr float running_mult = 3.0f;
|
||||
bool walking = false;
|
||||
bool running = false;
|
||||
glm::vec2 movedir(0.0f);
|
||||
|
||||
if (in_ & (1 << CIN_FORWARD))
|
||||
@ -177,19 +175,11 @@ void game::Character::UpdateMovement()
|
||||
if (movedir.x != 0.0f || movedir.y != 0.0f)
|
||||
{
|
||||
walking = true;
|
||||
|
||||
if (in_ & (1 << CIN_SPRINT))
|
||||
running = true;
|
||||
|
||||
float target_yaw = forward_yaw_ + std::atan2(movedir.y, movedir.x);
|
||||
Turn(yaw_, target_yaw, 8.0f * dt);
|
||||
Turn(yaw_, target_yaw, 4.0f * dt);
|
||||
|
||||
glm::vec3 forward_dir(glm::cos(yaw_), glm::sin(yaw_), 0.0f);
|
||||
walkdir = forward_dir * walk_speed_ * dt;
|
||||
|
||||
if (running)
|
||||
walkdir *= running_mult;
|
||||
|
||||
}
|
||||
|
||||
if (controller_)
|
||||
@ -207,8 +197,6 @@ void game::Character::UpdateMovement()
|
||||
float run_blend_target = walking ? 0.5f : 0.0f;
|
||||
MoveToward(animstate_.loco_blend, run_blend_target, dt * 2.0f);
|
||||
float anim_speed = glm::mix(0.5f, 1.5f, UnMix(0.0f, 0.5f, animstate_.loco_blend));
|
||||
if (running)
|
||||
anim_speed *= running_mult;
|
||||
animstate_.loco_phase = glm::mod(animstate_.loco_phase + anim_speed * dt, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ enum CharacterInputType
|
||||
CIN_LEFT,
|
||||
CIN_RIGHT,
|
||||
CIN_JUMP,
|
||||
CIN_SPRINT,
|
||||
};
|
||||
|
||||
struct CapsuleShape
|
||||
|
||||
@ -18,7 +18,7 @@ namespace game
|
||||
|
||||
static const char* GetRandomCarModel()
|
||||
{
|
||||
const char* vehicles[] = {"pickup_hd", "passat", "twingo", "polskifiat", "cow_static"};
|
||||
const char* vehicles[] = {"pickup_hd", "passat", "twingo", "polskifiat"};
|
||||
return vehicles[rand() % (sizeof(vehicles) / sizeof(vehicles[0]))];
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ game::OpenWorld::OpenWorld() : World("openworld")
|
||||
|
||||
constexpr size_t in_row = 20;
|
||||
|
||||
for (size_t i = 0; i < 100; ++i)
|
||||
for (size_t i = 0; i < 1500; ++i)
|
||||
{
|
||||
Schedule(i * 40, [this, i] {
|
||||
size_t col = i % in_row;
|
||||
@ -173,7 +173,7 @@ void game::OpenWorld::CreatePlayerCharacter(Player& player)
|
||||
RemovePlayerCharacter(player);
|
||||
|
||||
auto& character = SpawnRandomCharacter<PlayerCharacter>(*this, player);
|
||||
// character.SetNametag("player (" + std::to_string(character.GetEntNum()) + ")");
|
||||
character.SetNametag("player (" + std::to_string(character.GetEntNum()) + ")");
|
||||
character.SetPosition({100.0f, 100.0f, 5.0f});
|
||||
|
||||
player_characters_[&player] = &character;
|
||||
|
||||
@ -65,7 +65,7 @@ void game::Player::SetCamera(net::EntNum entnum)
|
||||
msg.Write(entnum);
|
||||
}
|
||||
|
||||
void game::Player::SendChat(const std::string& text)
|
||||
void game::Player::SendChat(const std::string text)
|
||||
{
|
||||
auto msg = BeginMsg(net::MSG_CHAT);
|
||||
net::ChatMessage chatm = text;
|
||||
|
||||
@ -28,9 +28,7 @@ public:
|
||||
void SetWorld(std::shared_ptr<World> world);
|
||||
|
||||
void SetCamera(net::EntNum entnum);
|
||||
void SendChat(const std::string& text);
|
||||
|
||||
const std::string& GetName() const { return name_; }
|
||||
void SendChat(const std::string text);
|
||||
|
||||
PlayerInputFlags GetInput() const { return in_; }
|
||||
float GetViewYaw() const { return view_yaw_; }
|
||||
|
||||
@ -5,8 +5,6 @@ game::PlayerCharacter::PlayerCharacter(World& world, OpenWorld& openworld, Playe
|
||||
{
|
||||
EnablePhysics(true);
|
||||
VehicleChanged();
|
||||
|
||||
SetNametag(player.GetName());
|
||||
}
|
||||
|
||||
void game::PlayerCharacter::Update()
|
||||
@ -95,11 +93,6 @@ void game::PlayerCharacter::UpdateInputs()
|
||||
c_in |= 1 << CIN_JUMP;
|
||||
}
|
||||
|
||||
if (in & (1 << IN_SPRINT))
|
||||
{
|
||||
c_in |= 1 << CIN_SPRINT;
|
||||
}
|
||||
|
||||
if (vehicle_)
|
||||
{
|
||||
SetInputs(0);
|
||||
|
||||
@ -14,7 +14,6 @@ namespace game
|
||||
IN_RIGHT,
|
||||
IN_JUMP,
|
||||
IN_CROUCH,
|
||||
IN_SPRINT,
|
||||
IN_USE,
|
||||
IN_ATTACK,
|
||||
IN_DEBUG1,
|
||||
|
||||
@ -5,14 +5,13 @@
|
||||
// #include <glm/gtx/common.hpp>
|
||||
|
||||
#include "vehicleview.hpp"
|
||||
#include "utils/version.hpp"
|
||||
|
||||
game::view::ClientSession::ClientSession(App& app) : app_(app)
|
||||
{
|
||||
// send login
|
||||
auto msg = BeginMsg(net::MSG_ID);
|
||||
msg.Write<net::Version>(FEKAL_VERSION);
|
||||
msg.Write(net::PlayerName(app.GetUserName()));
|
||||
net::PlayerName name;
|
||||
msg.Write(name);
|
||||
}
|
||||
|
||||
bool game::view::ClientSession::ProcessMessage(net::InMessage& msg)
|
||||
|
||||
@ -55,7 +55,7 @@ enum MessageType : uint8_t
|
||||
MSG_COUNT,
|
||||
};
|
||||
|
||||
using PlayerName = FixedStr<64>;
|
||||
using PlayerName = FixedStr<24>;
|
||||
using MapName = FixedStr<32>;
|
||||
using ModelName = FixedStr<64>;
|
||||
using ChatMessage = FixedStr<1024>;
|
||||
@ -131,8 +131,4 @@ using ObjCount = ObjNum;
|
||||
|
||||
using NumTexels = uint16_t;
|
||||
|
||||
// version
|
||||
|
||||
using Version = uint32_t;
|
||||
|
||||
} // namespace net
|
||||
@ -1,10 +1,7 @@
|
||||
#include "client.hpp"
|
||||
|
||||
#include <format>
|
||||
|
||||
#include "server.hpp"
|
||||
#include "utils/validate.hpp"
|
||||
#include "utils/version.hpp"
|
||||
|
||||
sv::Client::Client(Server& server, WSConnId id) : server_(server), id_(id) {}
|
||||
|
||||
@ -34,7 +31,13 @@ bool sv::Client::ProcessSingleMessage(net::MessageType type, net::InMessage& msg
|
||||
if (type != net::MSG_ID)
|
||||
return false;
|
||||
|
||||
return ProcessLoginMsg(msg);
|
||||
net::PlayerName name;
|
||||
if (!msg.Read(name) || !utils::IsAlphanumeric(name))
|
||||
return false;
|
||||
|
||||
player_ = std::make_unique<game::Player>(server_.GetGame(), name);
|
||||
state_ = CS_PLAYER;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -55,45 +58,7 @@ void sv::Client::Update()
|
||||
}
|
||||
}
|
||||
|
||||
void sv::Client::SendChat(const std::string& text)
|
||||
{
|
||||
// not buffering till update here (unlike in Player), sent instantly
|
||||
static std::vector<char> msg_buf;
|
||||
msg_buf.clear();
|
||||
net::OutMessage msg(msg_buf);
|
||||
msg.Write(net::MSG_CHAT);
|
||||
msg.Write(net::ChatMessage(text));
|
||||
|
||||
Send(std::string(msg_buf.data(), msg_buf.size()));
|
||||
}
|
||||
|
||||
void sv::Client::Disconnect()
|
||||
{
|
||||
server_.Disconnect(*this);
|
||||
}
|
||||
|
||||
void sv::Client::Send(std::string msg)
|
||||
{
|
||||
server_.Send(*this, std::move(msg));
|
||||
}
|
||||
|
||||
bool sv::Client::ProcessLoginMsg(net::InMessage& msg)
|
||||
{
|
||||
net::Version ver = 0;
|
||||
msg.Read(ver);
|
||||
|
||||
// check ver
|
||||
if (ver != FEKAL_VERSION)
|
||||
{
|
||||
SendChat(std::format("^f55špatná verze {}, server je na verzi {}", ver, FEKAL_VERSION));
|
||||
return false;
|
||||
}
|
||||
|
||||
net::PlayerName name;
|
||||
if (!msg.Read(name) || !utils::IsAlphanumeric(name))
|
||||
return false;
|
||||
|
||||
player_ = std::make_unique<game::Player>(server_.GetGame(), name);
|
||||
state_ = CS_PLAYER;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -28,9 +28,7 @@ public:
|
||||
|
||||
void Update();
|
||||
|
||||
void SendChat(const std::string& text);
|
||||
|
||||
void Disconnect();
|
||||
// void Disconnect(const std::string& reason);
|
||||
|
||||
WSConnId GetConnId() const { return id_; }
|
||||
ClientState GetState() const { return state_; }
|
||||
@ -41,8 +39,6 @@ public:
|
||||
private:
|
||||
void Send(std::string msg);
|
||||
|
||||
bool ProcessLoginMsg(net::InMessage& msg);
|
||||
|
||||
private:
|
||||
Server& server_;
|
||||
WSConnId id_ = 0;
|
||||
|
||||
@ -61,11 +61,6 @@ void sv::Server::Send(Client& client, std::string msg)
|
||||
ws_.Send(client.GetConnId(), std::move(msg));
|
||||
}
|
||||
|
||||
void sv::Server::Disconnect(Client& client)
|
||||
{
|
||||
ws_.Close(client.GetConnId());
|
||||
}
|
||||
|
||||
void sv::Server::PollWSEvents()
|
||||
{
|
||||
WSEvent event;
|
||||
@ -103,10 +98,9 @@ void sv::Server::HandleWSConnect(WSConnId conn)
|
||||
void sv::Server::HandleWSMessage(WSConnId conn, const std::string& data)
|
||||
{
|
||||
net::InMessage msg(data.data(), data.size());
|
||||
auto& client = clients_.at(conn);
|
||||
if (!client->ProcessMessage(msg))
|
||||
if (!clients_.at(conn)->ProcessMessage(msg))
|
||||
{
|
||||
client->Disconnect();
|
||||
// TODO: disconnect
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,8 +21,6 @@ public:
|
||||
|
||||
void Send(Client& client, std::string msg);
|
||||
|
||||
void Disconnect(Client& client);
|
||||
|
||||
game::Game& GetGame() { return game_; }
|
||||
|
||||
int64_t GetTime() const { return time_; }
|
||||
|
||||
@ -97,20 +97,6 @@ void sv::WSServer::Send(WSConnId conn_id, std::string data)
|
||||
(*it->second).send_binary(std::move(data));
|
||||
}
|
||||
|
||||
void sv::WSServer::Close(WSConnId conn_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
|
||||
auto it = id2conn_.find(conn_id);
|
||||
if (it == id2conn_.end())
|
||||
{
|
||||
std::cerr << "attempted to close unknown conn ID " << conn_id << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
(*it->second).close();
|
||||
}
|
||||
|
||||
void sv::WSServer::Exit()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
|
||||
@ -50,7 +50,7 @@ public:
|
||||
|
||||
bool PollEvent(WSEvent& out_event);
|
||||
void Send(WSConnId conn_id, std::string data);
|
||||
void Close(WSConnId conn_id);
|
||||
// void Close(WSConnId conn_id);
|
||||
|
||||
void Exit();
|
||||
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define FEKAL_VERSION 2026031401
|
||||
Loading…
x
Reference in New Issue
Block a user