Merge branch 'SQC-15_paquets' into SQC-15_animation
This commit is contained in:
@@ -276,9 +276,46 @@ void Engine::DrawMenu()
|
||||
ShowCursor();
|
||||
}
|
||||
|
||||
void Engine::Init() {
|
||||
void Engine::DrawPause()
|
||||
{
|
||||
static const int sTitle = 400;
|
||||
static const int sButton = 225;
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
PauseBGTexture.Bind();
|
||||
glLoadIdentity();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2i(800, 0);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2i(800, 600);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, 600);
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
ShowCursor();
|
||||
}
|
||||
|
||||
void Engine::Init() {
|
||||
|
||||
GLenum glewErr = glewInit();
|
||||
if (glewErr != GLEW_OK) {
|
||||
@@ -307,6 +344,10 @@ void Engine::Init() {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
if (m_istarted)
|
||||
return;
|
||||
else m_istarted = true;
|
||||
|
||||
//
|
||||
// Objet de skybox avec sa propre texture et son propre shader!
|
||||
m_skybox.Init(0.2f);
|
||||
@@ -396,15 +437,12 @@ void Engine::LoadResource() {
|
||||
|
||||
LoadTexture(MenuTitleTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
|
||||
LoadTexture(MenuBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
|
||||
LoadTexture(PauseBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
|
||||
LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png");
|
||||
LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png");
|
||||
LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png");
|
||||
LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
|
||||
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
||||
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
||||
@@ -895,7 +933,13 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
||||
glPushMatrix();
|
||||
|
||||
int timer = GetCountdown(elapsedTime);
|
||||
|
||||
for (int i = 1; i < WORLD_SIZE_X; i++)
|
||||
{
|
||||
if (timer <= COUNTDOWN - m_timerReductionChunk * i) {
|
||||
m_world.RemoveChunk(m_nbReductionChunk * i);
|
||||
m_renderer.RemoveChunk(m_nbReductionChunk * i);
|
||||
}
|
||||
}
|
||||
if (m_keyK) {
|
||||
SystemNotification(m_messageNotification);
|
||||
m_keyK = false;
|
||||
@@ -960,12 +1004,13 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
||||
|
||||
int Engine::GetCountdown(float elapsedTime) {
|
||||
if (m_resetcountdown)
|
||||
{
|
||||
m_nbReductionChunk = 4;
|
||||
m_timerReductionChunk = 30;
|
||||
m_countdown = m_time + COUNTDOWN;
|
||||
m_resetcountdown = false;
|
||||
}
|
||||
@@ -1001,7 +1046,6 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
Transformation all;
|
||||
Transformation skybox;
|
||||
Transformation remotePlayer;
|
||||
Vector3f vstep;
|
||||
|
||||
// Transformations initiales
|
||||
@@ -1032,16 +1076,15 @@ void Engine::Render(float elapsedTime) {
|
||||
pollTime = 0;
|
||||
}
|
||||
|
||||
RenderRemotePlayers(m_remotePlayer, pollTime);
|
||||
|
||||
m_player.ApplyTransformation(all);
|
||||
|
||||
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
|
||||
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//m_remotePlayer.ApplyTransformation(all);
|
||||
|
||||
if (m_mouseWU) bloc++;
|
||||
else if (m_mouseWD) bloc--;
|
||||
@@ -1097,16 +1140,15 @@ void Engine::Render(float elapsedTime) {
|
||||
}
|
||||
}
|
||||
|
||||
m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
if (m_isSkybox) 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_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||
|
||||
m_remotePlayer.Render(m_textureAtlas, m_shader01, elapsedTime);
|
||||
if (m_isSkybox) m_skybox.Render(skybox);
|
||||
|
||||
|
||||
|
||||
DrawHud(elapsedTime, bloc);
|
||||
DisplayPovGun();
|
||||
if (m_isSkybox) DrawHud(elapsedTime, bloc);
|
||||
if (m_isSkybox) DisplayPovGun();
|
||||
ProcessNotificationQueue();
|
||||
if (m_damage)
|
||||
{
|
||||
@@ -1122,14 +1164,26 @@ void Engine::Render(float elapsedTime) {
|
||||
fell = false;
|
||||
}
|
||||
|
||||
if (m_networkgame) {
|
||||
if (m_networkgame) { // Pour se gerer le paquet.
|
||||
using namespace std::chrono;
|
||||
using namespace netprot;
|
||||
Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - m_startTime).count();
|
||||
Input input;
|
||||
Sync sync;
|
||||
uint64_t id = m_conn.getId();
|
||||
static std::vector<char*> lsPck;
|
||||
|
||||
input.sid = m_conn.getId();
|
||||
if (false) { // TODO: Faire un checkup pour chaque ~1000ms.
|
||||
sync.sid = id;
|
||||
sync.timestamp = tstamp;
|
||||
sync.position = m_player.GetPosition();
|
||||
sync.hp = m_player.GetHP();
|
||||
// TODO: Garrocher ca quelque-part.
|
||||
}
|
||||
|
||||
input.sid = id;
|
||||
input.direction = m_player.GetDirection();
|
||||
input.timestamp = duration_cast<milliseconds>(high_resolution_clock::now() - m_startTime).count();
|
||||
input.timestamp = tstamp;
|
||||
input.keys.forward = m_keyW;
|
||||
input.keys.backward = m_keyS;
|
||||
input.keys.left = m_keyA;
|
||||
@@ -1138,13 +1192,38 @@ void Engine::Render(float elapsedTime) {
|
||||
input.keys.block = m_mouseR;
|
||||
input.keys.shoot = m_mouseL;
|
||||
|
||||
sendPackTo<Input>(m_conn.m_sock_udp, &input, &m_buf, &m_conn.m_srvsockaddr);
|
||||
|
||||
// TODO: Faire la gestion de la réception de paquets.
|
||||
sendPackTo<Input>(m_conn.m_sock_udp, &input, &m_bufout, &m_conn.m_srvsockaddr);
|
||||
|
||||
lsPck = recvPacks(m_conn.m_sock_udp, &m_buf);
|
||||
char* prevptr = nullptr;
|
||||
for (auto& pck : lsPck) { // We could make a few threads out of this.
|
||||
Sync sync;
|
||||
Output out;
|
||||
if (!prevptr)
|
||||
prevptr = m_buf.ptr;
|
||||
uint32_t bsize = m_buf.len - (pck - prevptr);
|
||||
prevptr = pck;
|
||||
switch (getType(pck, 1)) {
|
||||
using enum PACKET_TYPE;
|
||||
case SYNC:
|
||||
if (Deserialize(&sync, pck, &bsize)) {
|
||||
if (sync.sid != m_conn.getId())
|
||||
break;
|
||||
// TODO: Vérifier si les positions concordent au sync local.
|
||||
}
|
||||
break;
|
||||
case OUTPUT:
|
||||
if (Deserialize(&out, pck, &bsize)) {
|
||||
RemotePlayer* r = (RemotePlayer*)m_players[out.id];
|
||||
r->Feed(out);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
lsPck.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
|
||||
{
|
||||
@@ -1155,11 +1234,12 @@ void Engine::Render(float elapsedTime) {
|
||||
DrawMenu();
|
||||
}
|
||||
}
|
||||
else if (m_gamestate == GameState::PAUSE)
|
||||
{
|
||||
DrawPause();
|
||||
}
|
||||
else if (m_gamestate == GameState::QUIT)
|
||||
Stop();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Engine::KeyPressEvent(unsigned char key) {
|
||||
@@ -1185,7 +1265,14 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
}
|
||||
break;
|
||||
case 36: // ESC - Quitter
|
||||
m_gamestate = GameState::MAIN_MENU;
|
||||
if (m_gamestate == GameState::PLAY)
|
||||
{
|
||||
m_gamestate = GameState::PAUSE;
|
||||
}
|
||||
else if (m_gamestate == GameState::PAUSE)
|
||||
{
|
||||
m_gamestate = GameState::PLAY;
|
||||
}
|
||||
//Stop();
|
||||
break;
|
||||
case 57: // Space - Sauter
|
||||
@@ -1420,7 +1507,3 @@ bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool use
|
||||
|
||||
return true;
|
||||
}
|
||||
void Engine::RenderRemotePlayers(RemotePlayer& remoteplayer, float elapsedTime)
|
||||
{
|
||||
remoteplayer.Render(m_textureAtlas, m_shader01, elapsedTime);
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ public:
|
||||
Engine();
|
||||
virtual ~Engine();
|
||||
virtual void DrawMenu();
|
||||
virtual void DrawPause();
|
||||
virtual void DrawSplachScreen();
|
||||
virtual void Init();
|
||||
virtual void DeInit();
|
||||
@@ -94,17 +95,18 @@ private:
|
||||
Bullet* m_bullets[MAX_BULLETS];
|
||||
|
||||
std::unordered_map<uint64_t, Player*> m_players;
|
||||
netprot::Buffer m_buf;
|
||||
netprot::Buffer m_buf, m_bufout;
|
||||
std::chrono::high_resolution_clock::time_point m_startTime;
|
||||
|
||||
//Menu
|
||||
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
|
||||
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY, PAUSE };
|
||||
GameState m_gamestate = GameState::MAIN_MENU;
|
||||
Texture MenuTitleTexture;
|
||||
Texture MenuBGTexture;
|
||||
Texture MenuStartTexture;
|
||||
Texture MenuQuitTexture;
|
||||
Texture MenuOptionsTexture;
|
||||
Texture PauseBGTexture;
|
||||
Texture SplachScreenTexture;
|
||||
|
||||
|
||||
@@ -118,6 +120,8 @@ private:
|
||||
|
||||
int m_renderCount = 0;
|
||||
int m_countdown = COUNTDOWN;
|
||||
int m_nbReductionChunk = 4;
|
||||
int m_timerReductionChunk = 30;
|
||||
|
||||
bool m_damage = false;
|
||||
|
||||
@@ -131,7 +135,7 @@ private:
|
||||
bool m_resetcountdown = false;
|
||||
bool m_soloMultiChoiceMade = false;
|
||||
bool m_stopcountdown = false;
|
||||
|
||||
|
||||
bool m_keyK = false;
|
||||
bool m_keyL = false;
|
||||
bool m_keyW = false;
|
||||
|
@@ -9,7 +9,7 @@ Mesh::~Mesh() {
|
||||
void Mesh::FlushMeshToVBO() {
|
||||
m_vertexBuffer.SetMeshData(m_vd, m_vcount);
|
||||
m_vcount = 0;
|
||||
//delete[] m_vd;
|
||||
delete[] m_vd;
|
||||
}
|
||||
|
||||
void Mesh::FlushVBO() {
|
||||
|
@@ -15,7 +15,7 @@ private:
|
||||
Chunk* m_chunk; // NE PAS D<>TRUIRE ICI.
|
||||
|
||||
void AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, float u, float v, float s, World* world);
|
||||
|
||||
void RemoveChunk(int nbReduit);
|
||||
public:
|
||||
Mesh(Chunk* chunk);
|
||||
~Mesh();
|
||||
|
@@ -15,7 +15,7 @@ bool OpenglContext::Start(const std::string& title, int width, int height, bool
|
||||
m_title = title;
|
||||
m_fullscreen = fullscreen;
|
||||
InitWindow(width, height);
|
||||
|
||||
|
||||
Init();
|
||||
LoadResource();
|
||||
|
||||
|
@@ -52,6 +52,8 @@ protected:
|
||||
void HideCursor();
|
||||
void ShowCrossCursor() const;
|
||||
|
||||
bool m_istarted = false;
|
||||
|
||||
private:
|
||||
void InitWindow(int width, int height);
|
||||
MOUSE_BUTTON ConvertMouseButton(sf::Mouse::Button button) const;
|
||||
|
@@ -71,101 +71,20 @@ void RemotePlayer::Feed(const netprot::Output out) {
|
||||
|
||||
void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, float elapsedTime)
|
||||
{
|
||||
m_texture_front.Bind();
|
||||
shader.Use();
|
||||
//m_texture_front.Bind();
|
||||
|
||||
//float x = current.position.x;
|
||||
//float y = current.position.y;
|
||||
//float z = current.position.z;
|
||||
|
||||
float x = 128.0f;
|
||||
float y = 21.0f;
|
||||
float z = 128.0f;
|
||||
|
||||
float quadSize = 300.0f;
|
||||
float u, v, w, h;
|
||||
atlas.Bind();
|
||||
atlas.TextureIndexToCoord(0, u, v, w, h);
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f(0, 0, 1);
|
||||
|
||||
// Face avant
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x - quadSize / 2, y - quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(x + quadSize / 2, y - quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x + quadSize / 2, y + quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(x - quadSize / 2, y + quadSize / 2, z + quadSize / 2);
|
||||
|
||||
// Face arri<72>re
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x + quadSize / 2, y - quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(x - quadSize / 2, y - quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x - quadSize / 2, y + quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(x + quadSize / 2, y + quadSize / 2, z - quadSize / 2);
|
||||
|
||||
// Face droite
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x + quadSize / 2, y - quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(x + quadSize / 2, y - quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x + quadSize / 2, y + quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(x + quadSize / 2, y + quadSize / 2, z + quadSize / 2);
|
||||
|
||||
// Face gauche
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x - quadSize / 2, y - quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(x - quadSize / 2, y - quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x - quadSize / 2, y + quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(x - quadSize / 2, y + quadSize / 2, z - quadSize / 2);
|
||||
|
||||
// Face sup<75>rieure
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x - quadSize / 2, y + quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(x + quadSize / 2, y + quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x + quadSize / 2, y + quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(x - quadSize / 2, y + quadSize / 2, z - quadSize / 2);
|
||||
|
||||
// Face inf<6E>rieure
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x - quadSize / 2, y - quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(x + quadSize / 2, y - quadSize / 2, z - quadSize / 2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x + quadSize / 2, y - quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(x - quadSize / 2, y - quadSize / 2, z + quadSize / 2);
|
||||
|
||||
glTexCoord2f(u, v); glVertex3f(0, 50., 0);
|
||||
glTexCoord2f(u+w, v); glVertex3f(50., 50., 0);
|
||||
glTexCoord2f(u+w, v+h); glVertex3f(50., 0, 0);
|
||||
glTexCoord2f(u, v+h); glVertex3f(0, 0, 0);
|
||||
glEnd();
|
||||
|
||||
shader.Disable();
|
||||
}
|
||||
|
||||
bool RemotePlayer::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError)
|
||||
|
@@ -7,6 +7,32 @@ Renderer::Renderer() {
|
||||
Renderer::~Renderer() {
|
||||
}
|
||||
|
||||
void Renderer::RemoveChunk(int nbReduit)
|
||||
{
|
||||
for (int x = 0; x < WORLD_SIZE_X; ++x)
|
||||
for (int y = 0; y < WORLD_SIZE_Y; ++y)
|
||||
{
|
||||
Mesh* chk = nullptr;
|
||||
if (x < nbReduit)
|
||||
chk = m_meshes.Remove(x, y);
|
||||
if (y < nbReduit)
|
||||
chk = m_meshes.Remove(x, y);
|
||||
if (y > WORLD_SIZE_Y - nbReduit)
|
||||
chk = m_meshes.Remove(x, y);
|
||||
if (x > WORLD_SIZE_X - nbReduit)
|
||||
chk = m_meshes.Remove(x, y);
|
||||
|
||||
// TODO: MakeDirty() les voisins pour qu'ils se redessinent.
|
||||
|
||||
if (!chk)
|
||||
continue;
|
||||
|
||||
delete chk;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
@@ -21,6 +21,8 @@ public:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
void RemoveChunk(int nbReduit);
|
||||
|
||||
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;
|
||||
|
Reference in New Issue
Block a user