Merge branch 'master' into SQC-18_Mecanique_de_combat
This commit is contained in:
@@ -25,13 +25,14 @@
|
||||
<ClInclude Include="engine.h" />
|
||||
<ClInclude Include="mesh.h" />
|
||||
<ClInclude Include="openglcontext.h" />
|
||||
<ClInclude Include="remoteplayer.h" />
|
||||
<ClInclude Include="shader.h" />
|
||||
<ClInclude Include="skybox.h" />
|
||||
<ClInclude Include="texture.h" />
|
||||
<ClInclude Include="textureatlas.h" />
|
||||
<ClInclude Include="tool.h" />
|
||||
<ClInclude Include="vertexbuffer.h" />
|
||||
<ClInclude Include="worldrenderer.h" />
|
||||
<ClInclude Include="renderer.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="audio.cpp" />
|
||||
@@ -40,13 +41,14 @@
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="mesh.cpp" />
|
||||
<ClCompile Include="openglcontext.cpp" />
|
||||
<ClCompile Include="remoteplayer.cpp" />
|
||||
<ClCompile Include="shader.cpp" />
|
||||
<ClCompile Include="skybox.cpp" />
|
||||
<ClCompile Include="texture.cpp" />
|
||||
<ClCompile Include="textureatlas.cpp" />
|
||||
<ClCompile Include="tool.cpp" />
|
||||
<ClCompile Include="vertexbuffer.cpp" />
|
||||
<ClCompile Include="worldrenderer.cpp" />
|
||||
<ClCompile Include="renderer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SQCSim-common\SQCSim-common.vcxproj">
|
||||
@@ -130,7 +132,7 @@
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -145,7 +147,7 @@
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -162,7 +164,7 @@
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
@@ -184,7 +186,7 @@
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
|
@@ -47,7 +47,10 @@
|
||||
<ClInclude Include="mesh.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="worldrenderer.h">
|
||||
<ClInclude Include="renderer.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="remoteplayer.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
@@ -88,7 +91,10 @@
|
||||
<ClCompile Include="mesh.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="worldrenderer.cpp">
|
||||
<ClCompile Include="renderer.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="remoteplayer.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.18.4)
|
||||
|
||||
project(SQCSim-Client VERSION 0.8)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_STANDARD_REQUIRED True)
|
||||
|
||||
set(CMAKE_BUILD_DIRECTORY "./build")
|
||||
@@ -50,7 +50,8 @@ add_executable(SQCSim-client
|
||||
"../textureatlas.cpp"
|
||||
"../tool.cpp"
|
||||
"../vertexbuffer.cpp"
|
||||
"../worldrenderer.cpp"
|
||||
"../renderer.cpp"
|
||||
"../remoteplayer.cpp"
|
||||
"../main.cpp"
|
||||
)
|
||||
|
||||
|
@@ -42,7 +42,7 @@ int Connector::Init() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Connector::Connect(char* srv_addr, std::string name) {
|
||||
int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
sockaddr_in add;
|
||||
m_srvsockaddr.sin_family = AF_INET;
|
||||
m_srvsockaddr.sin_port = htons(SRV_PORT);
|
||||
@@ -54,44 +54,60 @@ int Connector::Connect(char* srv_addr, std::string name) {
|
||||
|
||||
if (connect(m_sock_tcp, (sockaddr*)&m_srvsockaddr, sizeof(m_srvsockaddr)) < 0) {
|
||||
std::cout << "<EFBFBD>chec de la connexion." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
char* buf = new char[150];
|
||||
uint32_t buflen = 150;
|
||||
flag_t flag = 1;
|
||||
if (ioctl(m_sock_tcp, SOCK_NONBLOCK, &flag) < 0) {
|
||||
std::cout << "Impossible de mettre le socket en mode non-bloquant." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
|
||||
netprot::Buffer bf;
|
||||
netprot::LoginInfo log;
|
||||
memcpy(&log.name, name.c_str(), name.size() + 1);
|
||||
strcpy(log.name, name.c_str());
|
||||
|
||||
netprot::Serialize(&log, &buf, &buflen);
|
||||
netprot::sendPack(m_sock_tcp, &log, &bf);
|
||||
|
||||
int se = send(m_sock_tcp, buf, buflen, 0);
|
||||
bool ready = false;
|
||||
int errors = 0;
|
||||
std::vector<netprot::Packet> lsPck;
|
||||
while (!ready) {
|
||||
lsPck = netprot::recvPacks(m_sock_tcp, &bf);
|
||||
|
||||
delete[] buf;
|
||||
buf = new char[150] {0};
|
||||
buflen = 150;
|
||||
int rpack = 0;
|
||||
|
||||
while (rpack < 2) {
|
||||
recv(m_sock_tcp, buf, buflen, 0);
|
||||
|
||||
switch (netprot::getType(buf, buflen)) {
|
||||
case netprot::PACKET_TYPE::LOGINF:
|
||||
if (!netprot::Deserialize(&m_loginfo, buf, buflen)) {
|
||||
std::cout << "Packet LoginInfo invalide." << std::endl;
|
||||
return 2;
|
||||
for (auto& pck : lsPck) {
|
||||
bool bypass_delete = false;
|
||||
netprot::PlayerInfo* pl = nullptr;
|
||||
switch (pck.type) {
|
||||
using enum netprot::PACKET_TYPE;
|
||||
case LOGINF:
|
||||
m_loginfo = netprot::LoginInfo((netprot::LoginInfo*)pck.ptr);
|
||||
break;
|
||||
case GAMEINFO:
|
||||
m_gameinfo = netprot::GameInfo((netprot::GameInfo*)pck.ptr);
|
||||
break;
|
||||
case PLAYINF:
|
||||
pl = (netprot::PlayerInfo*)pck.ptr;
|
||||
m_players[pl->id] = pl;
|
||||
bypass_delete = true;
|
||||
break;
|
||||
case TEAMINF:
|
||||
// TODO: Faire dequoi avec TeamInfo si on fini par avoir des teams.
|
||||
break;
|
||||
case SYNC:
|
||||
m_origin = netprot::Sync((netprot::Sync*)pck.ptr);
|
||||
ready = true;
|
||||
break;
|
||||
default:
|
||||
errors++;
|
||||
break;
|
||||
}
|
||||
++rpack;
|
||||
break;
|
||||
case netprot::PACKET_TYPE::GAMEINFO:
|
||||
if (!netprot::Deserialize(&m_gameinfo, buf, buflen)) {
|
||||
std::cout << "Packet GameInfo invalide." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
++rpack;
|
||||
break;
|
||||
default:
|
||||
std::cout << "Packet invalide." << std::endl;
|
||||
break;
|
||||
if (!bypass_delete)
|
||||
netprot::emptyPack(pck);
|
||||
}
|
||||
lsPck.clear();
|
||||
if (errors > 100)
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -99,3 +115,5 @@ int Connector::Connect(char* srv_addr, std::string name) {
|
||||
uint64_t Connector::getId() const { return m_loginfo.sid; }
|
||||
|
||||
unsigned int Connector::getSeed() const { return m_gameinfo.seed; }
|
||||
|
||||
netprot::Sync Connector::getOrigin() const { return m_origin; }
|
||||
|
@@ -11,26 +11,32 @@ public:
|
||||
~Connector();
|
||||
|
||||
int Init();
|
||||
int Connect(char* srv_addr, std::string name);
|
||||
int Connect(const char* srv_addr, std::string name);
|
||||
uint64_t getId() const;
|
||||
unsigned int getSeed() const;
|
||||
netprot::Sync getOrigin() const;
|
||||
|
||||
|
||||
//void SendInput();
|
||||
//int Sync();
|
||||
|
||||
SOCKET m_sock_udp = 0,
|
||||
m_sock_tcp = 0;
|
||||
sockaddr_in m_srvsockaddr;
|
||||
|
||||
// void updateRemotePlayers(std::map<RemotePlayers> rplayers);
|
||||
|
||||
std::map<uint64_t, netprot::PlayerInfo> m_players;
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
WSADATA m_wsaData;
|
||||
#endif
|
||||
std::map<Timestamp, netprot::Input> m_inputmanifest;
|
||||
std::map<uint64_t, netprot::PlayerInfo> m_players;
|
||||
std::map<uint64_t, netprot::TeamInfo> m_teams;
|
||||
|
||||
netprot::LoginInfo m_loginfo;
|
||||
netprot::GameInfo m_gameinfo;
|
||||
|
||||
sockaddr_in m_srvsockaddr;
|
||||
SOCKET m_sock_udp = 0,
|
||||
m_sock_tcp = 0;
|
||||
netprot::Sync m_origin;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
@@ -20,7 +20,6 @@
|
||||
#include <climits>
|
||||
#endif
|
||||
|
||||
#define NETWORK_TEST false
|
||||
#define SRV_ADDR "127.0.0.1"
|
||||
#define COUNTDOWN 300
|
||||
|
||||
|
@@ -279,6 +279,9 @@ void Engine::Init() {
|
||||
abort();
|
||||
}
|
||||
|
||||
uint64_t seed = SEED;
|
||||
char ch;
|
||||
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
@@ -308,31 +311,59 @@ void Engine::Init() {
|
||||
// Array pour les balles.
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) {
|
||||
m_bullets[x] = nullptr;
|
||||
m_whoosh[x] = nullptr; // = m_audio.m_engine.m_audio.m_engine->addSoundSourceFromFile(AUDIO_PATH "noise.ogg", irrklang::ESM_AUTO_DETECT, false);
|
||||
m_whoosh[x] = nullptr;
|
||||
}
|
||||
|
||||
uint64_t seed = SEED;
|
||||
std::string playname = "La Chienne <20> Jacques";
|
||||
if (NETWORK_TEST) { // Test connexion r<>seau.
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(SRV_ADDR, playname)) {
|
||||
// setup jeu en r<>seau.
|
||||
std::cout << "ID re<72>u du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
||||
std::cout << "Seed re<72>u du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
|
||||
seed = m_conn.getSeed();
|
||||
std::cout << "Jouer en ligne? [o/N] ";
|
||||
std::cin >> ch;
|
||||
std::cout << std::endl;
|
||||
|
||||
if (ch == 'o' || ch == 'O') {
|
||||
char* input = new char[32];
|
||||
std::string playname, srvname;
|
||||
|
||||
while (playname.size() < 1) {
|
||||
std::cout << "Veuillez entrer un nom de joueur: ";
|
||||
std::cin.ignore();
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
playname = input;
|
||||
if (playname.size() < 1 || playname.size() > 32)
|
||||
std::puts("Nom invalide.");
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
while (srvname.size() < 1) {
|
||||
std::cout << "Veuillez entrer une adresse de serveur: ";
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
srvname = input;
|
||||
if (srvname.size() < 1 || srvname.size() > 32)
|
||||
std::puts("Adresse serveur invalide.");
|
||||
}
|
||||
delete[] input;
|
||||
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(srvname.c_str(), playname)) {
|
||||
// setup jeu en reseau.
|
||||
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
||||
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
|
||||
m_player = Player(m_conn.getOrigin().position);
|
||||
|
||||
for (auto& [key, player] : m_conn.m_players)
|
||||
m_players[key] = new RemotePlayer(player);
|
||||
|
||||
seed = m_conn.getSeed();
|
||||
m_networkgame = true;
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de creation de socket." << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de cr<63>ation de socket." << std::endl;
|
||||
}
|
||||
|
||||
m_world.SetSeed(seed);
|
||||
|
||||
// Init Chunks
|
||||
m_world.GetChunks().Reset(nullptr);
|
||||
|
||||
|
||||
|
||||
// Gestion de souris.
|
||||
CenterMouse();
|
||||
HideCursor();
|
||||
@@ -590,7 +621,9 @@ void Engine::DisplayHud(int timer) {
|
||||
glVertex2f(fPosX, fBarPosY);
|
||||
glEnd();
|
||||
|
||||
// Current HP
|
||||
//TODO: Associer avec mechanique de vie du joueur
|
||||
|
||||
// Barre HP
|
||||
glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(fPosX, fBarPosY - fBarHeight);
|
||||
@@ -868,6 +901,7 @@ std::pair<float, float> Engine::GetScale() const {
|
||||
}
|
||||
|
||||
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
||||
|
||||
int Engine::GetCountdown(float elapsedTime) {
|
||||
if (m_resetcountdown)
|
||||
{
|
||||
@@ -930,8 +964,8 @@ void Engine::Render(float elapsedTime) {
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonn<EFBFBD>es du joueur et
|
||||
// son vecteur de v<EFBFBD>locit<EFBFBD> (pour l'effet Doppler)
|
||||
m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonnees du joueur et
|
||||
// son vecteur de velocite (pour l'effet Doppler)
|
||||
pollTime = 0;
|
||||
}
|
||||
|
||||
@@ -955,10 +989,18 @@ void Engine::Render(float elapsedTime) {
|
||||
m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
break;
|
||||
}
|
||||
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la premi<EFBFBD>re balle de l'array.
|
||||
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la première balle de l'array.
|
||||
m_bullets[0]->~Bullet();
|
||||
m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
}
|
||||
bulletTime = BULLET_TIME;
|
||||
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, .5f);
|
||||
if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash.
|
||||
glClearColor(.8f, .8f, .8f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_mouseR)
|
||||
@@ -966,7 +1008,7 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
|
||||
if (m_bullets[x]) {
|
||||
for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b)
|
||||
for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) {
|
||||
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME)) {
|
||||
m_bullets[x]->~Bullet();
|
||||
if (m_whoosh[x])
|
||||
@@ -978,13 +1020,17 @@ void Engine::Render(float elapsedTime) {
|
||||
else if (!m_whoosh[x]) {
|
||||
m_whoosh[x] = m_audio.Create3DAudioObj(m_whoosh[x], AUDIO_PATH "noise.wav", m_bullets[x]->getPos(), m_bullets[x]->getVel(), true, (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
|
||||
}
|
||||
else m_audio.Render3DAudioObj(m_whoosh[x], m_bullets[x]->getPos(), m_bullets[x]->getVel(), 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
|
||||
else {
|
||||
Vector3f pos = m_bullets[x]->getPos(), vel = m_bullets[x]->getVel();
|
||||
m_audio.Render3DAudioObj(m_whoosh[x], pos, vel, 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
||||
m_wrenderer.UpdateWorld(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||
|
||||
if (m_isSkybox) m_skybox.Render(skybox);
|
||||
|
||||
@@ -1005,6 +1051,28 @@ void Engine::Render(float elapsedTime) {
|
||||
fell = false;
|
||||
}
|
||||
|
||||
if (m_networkgame) {
|
||||
static char* buf = new char[BUFFER_LENGTH];
|
||||
uint32_t buflen = BUFFER_LENGTH;
|
||||
netprot::Input input;
|
||||
//sockaddr_in addr = m_conn.m_srvsockaddr;
|
||||
|
||||
input.direction = m_player.GetDirection();
|
||||
input.sid = m_conn.getId();
|
||||
input.timestamp = 12345;
|
||||
input.keys.forward = m_keyW;
|
||||
input.keys.backward = m_keyS;
|
||||
input.keys.left = m_keyA;
|
||||
input.keys.right = m_keyD;
|
||||
input.keys.jump = m_keySpace;
|
||||
input.keys.block = m_mouseR;
|
||||
input.keys.shoot = m_mouseL;
|
||||
|
||||
//netprot::Serialize(&input, &buf, &buflen);
|
||||
//sendto(m_conn.m_sock_udp, buf, buflen, 0, (sockaddr*)&addr, sizeof(addr));
|
||||
|
||||
netprot::sendPackTo<netprot::Input>(m_conn.m_sock_udp, &input, &buf, &buflen, &m_conn.m_srvsockaddr);
|
||||
}
|
||||
}
|
||||
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
|
||||
{
|
||||
@@ -1055,7 +1123,7 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
break;
|
||||
case 10: // K - Debugging DisplayNotification()
|
||||
m_keyK = true;
|
||||
m_messageNotification = "notifications systeme peuvent <EFBFBD>tre affich<EFBFBD>";
|
||||
m_messageNotification = "notifications systeme peuvent etre affichees";
|
||||
break;
|
||||
case 11: // L - Debugging DisplayNotification()
|
||||
m_keyL = true;
|
||||
|
@@ -18,7 +18,8 @@
|
||||
#include "audio.h"
|
||||
#include "textureatlas.h"
|
||||
#include "connector.h"
|
||||
#include "worldrenderer.h"
|
||||
#include "renderer.h"
|
||||
#include "remoteplayer.h"
|
||||
|
||||
class Engine : public OpenglContext {
|
||||
public:
|
||||
@@ -65,7 +66,7 @@ private:
|
||||
TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
|
||||
|
||||
World m_world = World();
|
||||
WorldRenderer m_wrenderer = WorldRenderer();
|
||||
Renderer m_renderer = Renderer();
|
||||
|
||||
Texture m_textureCrosshair;
|
||||
Texture m_textureFont;
|
||||
@@ -86,8 +87,10 @@ private:
|
||||
|
||||
Bullet* m_bullets[MAX_BULLETS];
|
||||
|
||||
std::map<uint64_t, RemotePlayer*> m_players;
|
||||
|
||||
//Menu
|
||||
enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
|
||||
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
|
||||
GameState m_gamestate = GameState::MAIN_MENU;
|
||||
Texture MenuTitleTexture;
|
||||
Texture MenuBGTexture;
|
||||
@@ -134,6 +137,8 @@ private:
|
||||
float m_mousemx = 0;
|
||||
float m_mousemy = 0;
|
||||
|
||||
bool m_networkgame = false;
|
||||
|
||||
std::string m_messageNotification = "";
|
||||
};
|
||||
|
||||
|
BIN
SQCSim2021/media/audio/whitenoise.ogg
Normal file
BIN
SQCSim2021/media/audio/whitenoise.ogg
Normal file
Binary file not shown.
70
SQCSim2021/remoteplayer.cpp
Normal file
70
SQCSim2021/remoteplayer.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "remoteplayer.h"
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo) : Player(Vector3f(0, 0, 0), 0, 0), m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous() {
|
||||
|
||||
}
|
||||
|
||||
void RemotePlayer::Init() {
|
||||
|
||||
}
|
||||
|
||||
void RemotePlayer::Feed(const netprot::Output out) {
|
||||
|
||||
current.position = out.position;
|
||||
current.direction = out.direction;
|
||||
current.states = out.states;
|
||||
current.id = out.id;
|
||||
|
||||
//a revoir pour le jump et le shoot en meme temps lorsque les test seront possible
|
||||
|
||||
if (current.position != previous.position)
|
||||
{
|
||||
Vector3f positionDelta = current.position - previous.position;
|
||||
m_position = current.position + positionDelta;
|
||||
m_direction = current.direction;
|
||||
|
||||
}
|
||||
|
||||
if(current.direction != previous.direction)
|
||||
{
|
||||
m_direction = current.direction;
|
||||
current.direction = current.direction;
|
||||
}
|
||||
|
||||
if (current.states.shooting) {
|
||||
//true;
|
||||
m_animstate = Anim::SHOOTING;
|
||||
}
|
||||
else if (current.states.jumping) {
|
||||
//true;
|
||||
m_animstate = Anim::JUMPING;
|
||||
}
|
||||
else if (current.states.dead) {
|
||||
//true;
|
||||
m_animstate = Anim::DEAD;
|
||||
}
|
||||
else if(current.states.powerup){
|
||||
//true;
|
||||
m_animstate = Anim::POWERUP;
|
||||
}
|
||||
else if (current.states.still) {
|
||||
//true;
|
||||
m_animstate = Anim::STILL;
|
||||
}
|
||||
else if (current.states.running) {
|
||||
//true;
|
||||
m_animstate = Anim::RUNNING;
|
||||
}
|
||||
|
||||
|
||||
previous.direction = current.direction;
|
||||
previous.position = current.position;
|
||||
previous.states = current.states;
|
||||
previous.id = current.id;
|
||||
|
||||
|
||||
|
||||
}
|
26
SQCSim2021/remoteplayer.h
Normal file
26
SQCSim2021/remoteplayer.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef REMOTEPLAYER_H__
|
||||
#define REMOTEPLAYER_H__
|
||||
#include "../SQCSim-common/player.h"
|
||||
#include "../SQCSim-common/netprotocol.h"
|
||||
#include "define.h"
|
||||
#include "textureatlas.h"
|
||||
#include "shader.h"
|
||||
|
||||
class RemotePlayer : public Player {
|
||||
public:
|
||||
enum Anim { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16, DEAD = 32 };
|
||||
|
||||
RemotePlayer(netprot::PlayerInfo pinfo);
|
||||
|
||||
void Init();
|
||||
void Feed(const netprot::Output out);
|
||||
|
||||
private:
|
||||
netprot::Output current, previous;
|
||||
netprot::PlayerInfo m_pinfo;
|
||||
float m_aminacc;
|
||||
Anim m_animstate;
|
||||
uint64_t m_team_id;
|
||||
|
||||
};
|
||||
#endif
|
@@ -1,13 +1,13 @@
|
||||
#include "worldrenderer.h"
|
||||
#include "renderer.h"
|
||||
|
||||
WorldRenderer::WorldRenderer() {
|
||||
Renderer::Renderer() {
|
||||
m_meshes.Reset(nullptr);
|
||||
}
|
||||
|
||||
WorldRenderer::~WorldRenderer() {
|
||||
Renderer::~Renderer() {
|
||||
}
|
||||
|
||||
void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) {
|
||||
void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const {
|
||||
rendercount = 0;
|
||||
Vector3f angle;
|
||||
Vector3f cursor;
|
||||
@@ -18,7 +18,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f&
|
||||
direct.Normalize();
|
||||
pos.y = 1;
|
||||
|
||||
static Vector3<unsigned int> renderManifest[VIEW_DISTANCE * 8]; // Nombre de Chunks maximal à être rendus.
|
||||
static Vector3<unsigned int> renderManifest[VIEW_DISTANCE * 8]; // Nombre de Chunks maximal <EFBFBD> <20>tre rendus.
|
||||
|
||||
//for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) {
|
||||
for (int dist = 0; dist <= VIEW_DISTANCE; dist += CHUNK_SIZE_X) {
|
||||
@@ -27,18 +27,18 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f&
|
||||
int echantillons;
|
||||
|
||||
if (dist > VIEW_DISTANCE * .1f) {
|
||||
sinus = .00872653549f; // sin(1/2 degré)
|
||||
cosinus = .99996192306; // cos(1/2 degré)
|
||||
sinus = .00872653549f; // sin(1/2 degr<EFBFBD>)
|
||||
cosinus = .99996192306; // cos(1/2 degr<EFBFBD>)
|
||||
echantillons = 180;
|
||||
}
|
||||
//else {//if (dist > VIEW_DISTANCE * .3f) {
|
||||
// sinus = .01151891831f; // sin(2/3 degré)
|
||||
// cosinus = .99993365506; // cos(2/3 degré)
|
||||
// sinus = .01151891831f; // sin(2/3 degr<EFBFBD>)
|
||||
// cosinus = .99993365506; // cos(2/3 degr<EFBFBD>)
|
||||
// echantillons = 120;
|
||||
//}
|
||||
//else if (dist > VIEW_DISTANCE * .2f) {
|
||||
// sinus = .01745240643; // sin(1 degré)
|
||||
// cosinus = .99984769515; // cos(1 degré)
|
||||
// sinus = .01745240643; // sin(1 degr<EFBFBD>)
|
||||
// cosinus = .99984769515; // cos(1 degr<EFBFBD>)
|
||||
// echantillons = 90;
|
||||
//}
|
||||
//else if (dist > VIEW_DISTANCE * .1f) {
|
||||
@@ -72,7 +72,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f&
|
||||
bool valide = true;
|
||||
unsigned int chx, chy;
|
||||
origin->ChunkAt(cursor)->GetPosition(chx, chy);
|
||||
for (int index = 0; index < rendercount; ++index) // Permet de vérifier seulement contre celles ajoutées dans la frame, et ne pas avoir à refaire l'array à chaque frame.
|
||||
for (int index = 0; index < rendercount; ++index) // Permet de v<EFBFBD>rifier seulement contre celles ajout<EFBFBD>es dans la frame, et ne pas avoir <EFBFBD> refaire l'array <EFBFBD> chaque frame.
|
||||
if (renderManifest[index].x == chx && renderManifest[index].z == chy)
|
||||
valide = false;
|
||||
|
||||
@@ -107,7 +107,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f&
|
||||
glStencilFunc(GL_GREATER, 1, 0xFF);
|
||||
};
|
||||
|
||||
void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
int cx = player.x;
|
||||
int cy = player.z;
|
||||
static int frameUpdate = 2;
|
||||
@@ -212,3 +212,10 @@ void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Renderer::RenderPlayer(Player* player, Transformation tran) const {
|
||||
}
|
||||
|
||||
void Renderer::RenderPlayer(RemotePlayer* rplayer, const Vector3f& player_pos, const Vector3f& player_dir) const {
|
||||
}
|
||||
|
30
SQCSim2021/renderer.h
Normal file
30
SQCSim2021/renderer.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef RENDERER_H__
|
||||
#define RENDERER_H__
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include "../SQCSim-common/world.h"
|
||||
#include "../SQCSim-common/transformation.h"
|
||||
#include "define.h"
|
||||
#include "mesh.h"
|
||||
#include "textureatlas.h"
|
||||
#include "shader.h"
|
||||
#include "remoteplayer.h"
|
||||
|
||||
class Renderer {
|
||||
private:
|
||||
Array2d<Mesh*> m_meshes = Array2d<Mesh*>(WORLD_SIZE_X, WORLD_SIZE_Y);
|
||||
|
||||
TextureAtlas* m_playertext = nullptr;
|
||||
Shader* m_playershader = nullptr;
|
||||
|
||||
public:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
|
||||
void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const;
|
||||
void RenderPlayer(Player* player, Transformation tran) const;
|
||||
void RenderPlayer(RemotePlayer* rplayer, const Vector3f& player_pos, const Vector3f& player_dir) const;
|
||||
};
|
||||
#endif
|
@@ -1,23 +0,0 @@
|
||||
#ifndef WORLDRENDERER_H__
|
||||
#define WORLDRENDERER_H__
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include "../SQCSim-common/world.h"
|
||||
#include "../SQCSim-common/transformation.h"
|
||||
#include "define.h"
|
||||
#include "mesh.h"
|
||||
#include "textureatlas.h"
|
||||
#include "shader.h"
|
||||
|
||||
class WorldRenderer {
|
||||
private:
|
||||
Array2d<Mesh*> m_meshes = Array2d<Mesh*>(WORLD_SIZE_X, WORLD_SIZE_Y);
|
||||
|
||||
public:
|
||||
WorldRenderer();
|
||||
~WorldRenderer();
|
||||
|
||||
void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas);
|
||||
void UpdateWorld(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
};
|
||||
#endif
|
Reference in New Issue
Block a user