Socket côté client!
This commit is contained in:
parent
3ff2634e51
commit
8bc74624c3
@ -12,6 +12,7 @@
|
||||
#define CHUNK_SIZE_Z 4
|
||||
#define MAX_SELECTION_DISTANCE 5
|
||||
#define SEED 12345
|
||||
#define COUNTDOWN 300
|
||||
|
||||
#define WORLD_SIZE_X 64
|
||||
#define WORLD_SIZE_Y 64
|
||||
|
@ -38,7 +38,6 @@
|
||||
<ClInclude Include="textureatlas.h" />
|
||||
<ClInclude Include="tool.h" />
|
||||
<ClInclude Include="transformation.h" />
|
||||
<ClInclude Include="vector3.h" />
|
||||
<ClInclude Include="vertexbuffer.h" />
|
||||
<ClInclude Include="world.h" />
|
||||
</ItemGroup>
|
||||
@ -62,6 +61,11 @@
|
||||
<ClCompile Include="vertexbuffer.cpp" />
|
||||
<ClCompile Include="world.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SQCSim-common\SQCSim-common.vcxproj">
|
||||
<Project>{ee91ab12-4225-4a4d-931d-69d72f6d91fb}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{A21FD938-1FEA-4687-AB86-0EABAC30877B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
|
@ -38,9 +38,6 @@
|
||||
<ClInclude Include="transformation.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="vector3.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="player.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <irrKlang.h>
|
||||
#include <ik_ISoundSource.h>
|
||||
#include "define.h"
|
||||
#include "vector3.h"
|
||||
#include "../SQCSim-common/vector3.h"
|
||||
|
||||
class Audio {
|
||||
private:
|
||||
|
@ -1,18 +1,51 @@
|
||||
#include "connector.h"
|
||||
|
||||
Connector::Connector()
|
||||
{
|
||||
Connector::Connector() {}
|
||||
|
||||
Connector::~Connector() {}
|
||||
|
||||
int Connector::Init() {
|
||||
#ifdef _WIN32
|
||||
if (WSAStartup(MAKEWORD(2, 2), &m_wsaData) != 0) { /* Initialisation de l'environnement reseau (Windows only) */
|
||||
std::cout << "Initialisation WinSock." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_sock_udp = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (m_sock_udp == INVALID_SOCKET) { /* Creation du socket UDP */
|
||||
std::cout << "Creation Socket UDP." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
Connector::~Connector()
|
||||
{
|
||||
m_sock_tcp = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (m_sock_tcp == INVALID_SOCKET) { /* Creation du socket TCP */
|
||||
std::cout << "Creation Socket TCP." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
|
||||
int Connector::Init(sockaddr_in srv_addr) {
|
||||
/* Creation structure donnes descripteur du socket serveur */
|
||||
sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(SRV_PORT);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
if (bind(m_sock_udp, (sockaddr*)&addr, sizeof(addr)) != 0) { /* Associer le socket UDP au port */
|
||||
std::cout << "Association Socket UDP." << std::endl;
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (bind(m_sock_tcp, (sockaddr*)&addr, sizeof(addr)) != 0) { /* Associer le socket TCP au port */
|
||||
std::cout << "Association Socket TCP." << std::endl;
|
||||
return 5;
|
||||
}
|
||||
|
||||
std::cout << "It is the voork!" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Connector::Connect(std::string name) {
|
||||
int Connector::Connect(sockaddr_in srv_addr, std::string name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2,41 +2,26 @@
|
||||
#define CONNECTOR_H__
|
||||
|
||||
#include "define.h"
|
||||
#include "vector3.h"
|
||||
|
||||
struct Input { // vers serveur
|
||||
Timestamp timestamp;
|
||||
UINT8 keys; // 0bFBLRJS__
|
||||
Vector3f direction;
|
||||
};
|
||||
|
||||
struct Output { // autres joueurs du serveur
|
||||
Timestamp timestamp;
|
||||
UINT64 id = 0;
|
||||
Vector3f position, direction;
|
||||
bool is_shooting, is_jumping;
|
||||
};
|
||||
|
||||
struct Sync { // du serveur
|
||||
Timestamp timestamp;
|
||||
UINT64 sid = 0;
|
||||
Vector3f position;
|
||||
};
|
||||
#include "../SQCSim-common/netprotocol.h"
|
||||
|
||||
class Connector {
|
||||
public:
|
||||
Connector();
|
||||
~Connector();
|
||||
|
||||
int Init(sockaddr_in srv_addr);
|
||||
int Connect(std::string name);
|
||||
int Init();
|
||||
int Connect(sockaddr_in srv_addr, std::string name);
|
||||
UINT64 getId() const;
|
||||
unsigned int getSeed() const;
|
||||
|
||||
//void SendInput();
|
||||
//int Sync();
|
||||
private:
|
||||
SOCKET m_sock = 0;
|
||||
#ifdef _WIN32
|
||||
WSADATA m_wsaData;
|
||||
#endif
|
||||
SOCKET m_sock_udp = 0,
|
||||
m_sock_tcp = 0;
|
||||
std::string m_name = "";
|
||||
UINT64 m_sid = 0,
|
||||
m_tid = 0;
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef DEFINE_H__
|
||||
#define DEFINE_H__
|
||||
#ifndef CLI_DEFINE_H__
|
||||
#define CLI_DEFINE_H__
|
||||
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include "../SQCSim-common/define.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@ -14,21 +15,11 @@
|
||||
#include <gl/GLU.h>
|
||||
#endif
|
||||
|
||||
#define NETWORK_TEST false
|
||||
|
||||
|
||||
#define NETWORK_TEST true
|
||||
#define SRV_ADDR "127.0.0.1"
|
||||
#define SRV_PORT 1025
|
||||
#define CLI_PORT 1026
|
||||
|
||||
#define CHUNK_SIZE_X 4
|
||||
#define CHUNK_SIZE_Y 64
|
||||
#define CHUNK_SIZE_Z 4
|
||||
#define MAX_SELECTION_DISTANCE 5
|
||||
#define BASE_WIDTH 640
|
||||
#define BASE_HEIGHT 480
|
||||
#define SEED 12345
|
||||
|
||||
#define WORLD_SIZE_X 64
|
||||
#define WORLD_SIZE_Y 64
|
||||
#define COUNTDOWN 300
|
||||
|
||||
#define FRAMES_RENDER_CHUNKS 1
|
||||
#define FRAMES_UPDATE_CHUNKS 1
|
||||
@ -38,39 +29,8 @@
|
||||
#define THREADS_UPDATE_CHUNKS 3
|
||||
#define THREADS_DELETE_CHUNKS 3
|
||||
|
||||
#define VIEW_DISTANCE 512
|
||||
#define TEXTURE_SIZE 512
|
||||
#define MAX_BULLETS 512
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject
|
||||
|
||||
#include <Windows.h>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
|
||||
#define popen _popen
|
||||
#define pclose _pclose
|
||||
|
||||
#else // Pas _WIN32
|
||||
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define SOCKET int
|
||||
#define INVALID_SOCKET -1
|
||||
#define closesocket close
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
typedef uint8_t BlockType;
|
||||
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };
|
||||
typedef std::chrono::system_clock::time_point Timestamp;
|
||||
#define BASE_WIDTH 640
|
||||
#define BASE_HEIGHT 480
|
||||
|
||||
#define TEXTURE_PATH "./media/textures/"
|
||||
#define SHADER_PATH "./media/shaders/"
|
||||
|
@ -55,11 +55,11 @@ void Engine::Init() {
|
||||
addr.sin_port = htons(SRV_PORT);
|
||||
addr.sin_addr.s_addr = inet_addr(srvaddr);
|
||||
|
||||
if (!m_conn->Init(addr)) {
|
||||
if (m_conn->Connect(playname)) {
|
||||
if (!m_conn.Init()) {
|
||||
if (m_conn.Connect(addr, playname)) {
|
||||
// setup jeu en réseau.
|
||||
seed = m_conn->getSeed();
|
||||
std::cout << "ID reçu du serveur: " << std::to_string(m_conn->getId()) << "!" << std::endl;
|
||||
seed = m_conn.getSeed();
|
||||
std::cout << "ID reçu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ private:
|
||||
void DrawHud(float elapsedTime, BlockType bloc);
|
||||
void PrintText(float x, float y, float scale, const std::string& t);
|
||||
|
||||
Connector* m_conn = nullptr;
|
||||
Connector m_conn;
|
||||
Shader m_shader01;
|
||||
BlockInfo* m_blockinfo[BTYPE_LAST];
|
||||
TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "define.h"
|
||||
#include "vector3.h"
|
||||
#include "../SQCSim-common/vector3.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265f
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef _PLAYER_H__
|
||||
#define _PLAYER_H__
|
||||
#include "vector3.h"
|
||||
#include "../SQCSim-common/vector3.h"
|
||||
#include "transformation.h"
|
||||
#include "audio.h"
|
||||
#include <cmath>
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define TRANSFORMATION_H__
|
||||
|
||||
#include "matrix4.h"
|
||||
#include "vector3.h"
|
||||
#include "../SQCSim-common/vector3.h"
|
||||
#include <stack>
|
||||
|
||||
class Transformation
|
||||
|
@ -1,219 +0,0 @@
|
||||
#ifndef VECTOR3_H__
|
||||
#define VECTOR3_H__
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
template <class T>
|
||||
class Vector3
|
||||
{
|
||||
public:
|
||||
Vector3();
|
||||
Vector3(const T& x, const T& y, const T& z);
|
||||
~Vector3();
|
||||
|
||||
T Length() const;
|
||||
void Normalize();
|
||||
void Zero();
|
||||
|
||||
T Dot(const Vector3<T>& v) const;
|
||||
Vector3<T> Cross(const Vector3<T>& v) const;
|
||||
|
||||
Vector3<T> operator+(const Vector3<T>& v) const;
|
||||
Vector3<T> operator-(const Vector3<T>& v) const;
|
||||
Vector3<T> operator-() const;
|
||||
Vector3<T> operator+(const T& v) const;
|
||||
Vector3<T> operator-(const T& v) const;
|
||||
Vector3<T> operator/(const T& v) const;
|
||||
Vector3<T> operator*(const T& v) const;
|
||||
|
||||
Vector3<T>& operator=(const Vector3<T>& v);
|
||||
|
||||
Vector3<T>& operator+=(const Vector3<T>& v);
|
||||
Vector3<T>& operator-=(const Vector3<T>& v);
|
||||
Vector3<T>& operator+=(const T& v);
|
||||
Vector3<T>& operator-=(const T& v);
|
||||
Vector3<T>& operator/=(const T& v);
|
||||
Vector3<T>& operator*=(const T& v);
|
||||
|
||||
bool operator==(const Vector3<T>& v) const;
|
||||
bool operator!=(const Vector3<T>& v) const;
|
||||
|
||||
void Afficher() const;
|
||||
|
||||
public:
|
||||
T x, y, z;
|
||||
};
|
||||
|
||||
typedef Vector3<int> Vector3i;
|
||||
typedef Vector3<float> Vector3f;
|
||||
|
||||
template <class T>
|
||||
inline std::ostream& operator<<(std::ostream& out, const Vector3<T>& v)
|
||||
{
|
||||
out << "[" << v.x << ", " << v.y << ", " << v.z << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
Vector3<T>::Vector3()
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>::Vector3(const T& x, const T& y, const T& z) : x(x), y(y), z(z)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>::~Vector3()
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T Vector3<T>::Length() const
|
||||
{
|
||||
return sqrt(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Vector3<T>::Normalize()
|
||||
{
|
||||
T len = Length();
|
||||
if (len != 0)
|
||||
{
|
||||
x /= len;
|
||||
y /= len;
|
||||
z /= len;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Vector3<T>::Zero()
|
||||
{
|
||||
x = y = z = 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T Vector3<T>::Dot(const Vector3<T>& v) const
|
||||
{
|
||||
return (x * v.x) + (y * v.y) + (z * v.z);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T> Vector3<T>::Cross(const Vector3<T>& v) const
|
||||
{
|
||||
return Vector3<T>(
|
||||
y * v.z - v.y * z,
|
||||
z * v.x - v.z * x,
|
||||
x * v.y - v.x * y);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T> Vector3<T>::operator+(const Vector3<T>& v) const
|
||||
{
|
||||
return Vector3<T>(x + v.x, y + v.y, z + v.z);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T> Vector3<T>::operator-(const Vector3<T>& v) const
|
||||
{
|
||||
return Vector3<T>(x - v.x, y - v.y, z - v.z);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T> Vector3<T>::operator-() const
|
||||
{
|
||||
return Vector3<T>(-x, -y, -z);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T> Vector3<T>::operator+(const T& v) const
|
||||
{
|
||||
return Vector3<T>(x + v, y + v, z + v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T> Vector3<T>::operator-(const T& v) const
|
||||
{
|
||||
return Vector3<T>(x - v, y - v, z - v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T> Vector3<T>::operator/(const T& v) const
|
||||
{
|
||||
return Vector3<T>(x / v, y / v, z / v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T> Vector3<T>::operator*(const T& v) const
|
||||
{
|
||||
return Vector3<T>(x * v, y * v, z * v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>& Vector3<T>::operator=(const Vector3<T>& v)
|
||||
{
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>& Vector3<T>::operator+=(const Vector3<T>& v)
|
||||
{
|
||||
return (*this = *this + v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>& Vector3<T>::operator-=(const Vector3<T>& v)
|
||||
{
|
||||
return (*this = *this - v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>& Vector3<T>::operator+=(const T& v)
|
||||
{
|
||||
return (*this = *this + v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>& Vector3<T>::operator-=(const T& v)
|
||||
{
|
||||
return (*this = *this - v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>& Vector3<T>::operator/=(const T& v)
|
||||
{
|
||||
return (*this = *this / v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector3<T>& Vector3<T>::operator*=(const T& v)
|
||||
{
|
||||
return (*this = *this * v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool Vector3<T>::operator==(const Vector3<T>& v) const
|
||||
{
|
||||
return (x == v.x && y == v.y && z == v.z);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool Vector3<T>::operator!=(const Vector3<T>& v) const
|
||||
{
|
||||
return !(*this == v);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Vector3<T>::Afficher() const
|
||||
{
|
||||
std::cout << "[" << x << ", " << y << ", " << z << "]" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
#endif // VECTOR3_H__
|
@ -8,7 +8,7 @@
|
||||
#include "define.h"
|
||||
#include "chunk.h"
|
||||
#include "array2d.h"
|
||||
#include "vector3.h"
|
||||
#include "../SQCSim-common/vector3.h"
|
||||
#include "player.h"
|
||||
#include "transformation.h"
|
||||
#include "shader.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user