Sync ees almöss de voork!
This commit is contained in:
parent
10b8d77734
commit
e89b5914fb
@ -14,43 +14,53 @@ void Player::TurnLeftRight(float value) {
|
||||
m_rotY += value;
|
||||
if (m_rotY > 360) m_rotY = 0;
|
||||
else if (m_rotY < -360) m_rotY = 0;
|
||||
|
||||
float yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
|
||||
float xrotrad = (m_rotX / 57.2957795056f);
|
||||
|
||||
m_direction = Vector3f(cos(xrotrad) * sin(yrotrad),
|
||||
-sin(xrotrad),
|
||||
cos(xrotrad) * -cos(yrotrad));
|
||||
|
||||
m_direction.Normalize();
|
||||
}
|
||||
|
||||
void Player::TurnTopBottom(float value) {
|
||||
m_rotX += value;
|
||||
if (m_rotX > 80) m_rotX = 80;
|
||||
else if (m_rotX < -80) m_rotX = -80;
|
||||
}
|
||||
|
||||
Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool shoot, float elapsedTime) {
|
||||
|
||||
Vector3f delta = Vector3f(0, 0, 0);
|
||||
|
||||
float yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
|
||||
float xrotrad = (m_rotX / 57.2957795056f);
|
||||
|
||||
m_direction = Vector3f(cos(xrotrad) * sin(yrotrad),
|
||||
-sin(xrotrad),
|
||||
cos(xrotrad) * -cos(yrotrad));
|
||||
-sin(xrotrad),
|
||||
cos(xrotrad) * -cos(yrotrad));
|
||||
|
||||
m_direction.Normalize();
|
||||
}
|
||||
|
||||
Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool shoot, float elapsedTime) {
|
||||
Vector3f delta = Vector3f(0, 0, 0);
|
||||
|
||||
Vector3f dir = m_direction;
|
||||
|
||||
dir.y = 0;
|
||||
|
||||
if (front) {
|
||||
delta.x += float(sin(yrotrad)) * elapsedTime * 10.f;
|
||||
delta.z += float(-cos(yrotrad)) * elapsedTime * 10.f;
|
||||
delta += dir;
|
||||
}
|
||||
else if (back) {
|
||||
delta.x += float(-sin(yrotrad)) * elapsedTime * 10.f;
|
||||
delta.z += float(cos(yrotrad)) * elapsedTime * 10.f;
|
||||
delta -= dir;
|
||||
}
|
||||
|
||||
if (left) {
|
||||
delta.x += float(-cos(yrotrad)) * elapsedTime * 10.f;
|
||||
delta.z += float(-sin(yrotrad)) * elapsedTime * 10.f;
|
||||
delta.x += dir.z;
|
||||
delta.z += -dir.x;
|
||||
}
|
||||
else if (right) {
|
||||
delta.x += float(cos(yrotrad)) * elapsedTime * 10.f;
|
||||
delta.z += float(sin(yrotrad)) * elapsedTime * 10.f;
|
||||
delta.x -= dir.z;
|
||||
delta.z -= -dir.x;
|
||||
}
|
||||
|
||||
delta.Normalize();
|
||||
|
@ -81,7 +81,7 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
|
||||
if (m_playinfo.id == conn->GetHash(false))
|
||||
continue;
|
||||
//std::cout << m_playinfo.id << ": " << m_playinfo.name << ": " << conn->GetName() << std::endl;
|
||||
std::cout << out.id << ": " << out.position << std::endl;
|
||||
//std::cout << out.id << ": " << out.position << std::endl;
|
||||
|
||||
sendPackTo<Output>(sock, &out, &m_bufout, conn->getAddr());
|
||||
}
|
||||
@ -124,6 +124,7 @@ void Connection::Run(World* world) {
|
||||
el = (double)(in.timestamp - last.timestamp) / 1000.;
|
||||
std::cout << 1. / el << std::endl;
|
||||
player.get()->SetDirection(in.direction);
|
||||
std::cout << in.direction << std::endl;
|
||||
player.get()->ApplyPhysics(player.get()->GetInput(in.keys.forward,
|
||||
in.keys.backward,
|
||||
in.keys.left,
|
||||
|
@ -319,33 +319,8 @@ void Engine::DrawPause()
|
||||
|
||||
void Engine::Init() {
|
||||
|
||||
GLenum glewErr = glewInit();
|
||||
if (glewErr != GLEW_OK) {
|
||||
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
uint64_t seed = SEED;
|
||||
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
glDisable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
if (m_istarted)
|
||||
return;
|
||||
else m_istarted = true;
|
||||
@ -363,6 +338,9 @@ void Engine::Init() {
|
||||
m_whoosh[x] = nullptr;
|
||||
}
|
||||
|
||||
// Init Chunks
|
||||
m_world.GetChunks().Reset(nullptr);
|
||||
|
||||
char* ch = new char[2];
|
||||
|
||||
std::cout << "Jouer en ligne? [o/N] ";
|
||||
@ -415,12 +393,8 @@ void Engine::Init() {
|
||||
|
||||
m_world.SetSeed(seed);
|
||||
|
||||
// Init Chunks
|
||||
m_world.GetChunks().Reset(nullptr);
|
||||
|
||||
m_startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
m_remotePlayer.SetPosition(Vector3f(.5,CHUNK_SIZE_Y + 10., .5));
|
||||
// Gestion de souris.
|
||||
CenterMouse();
|
||||
HideCursor();
|
||||
@ -429,6 +403,31 @@ void Engine::Init() {
|
||||
void Engine::DeInit() {}
|
||||
|
||||
void Engine::LoadResource() {
|
||||
GLenum glewErr = glewInit();
|
||||
if (glewErr != GLEW_OK) {
|
||||
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
glDisable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
||||
//LoadTexture(m_skybox2.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
||||
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
|
||||
@ -1331,15 +1330,18 @@ void Engine::Render(float elapsedTime) {
|
||||
std::cout << "syncsid be no good.";
|
||||
break;
|
||||
}
|
||||
if (m_syncs.contains(sync.timestamp)) {
|
||||
if (m_syncs.count(sync.timestamp)) {
|
||||
Sync comp = m_syncs[sync.timestamp];
|
||||
m_player.InflictDamage(sync.hp - comp.hp);
|
||||
|
||||
std::cout << comp.position << " - " << sync.position << std::endl;
|
||||
|
||||
Vector3f diff = sync.position - comp.position;
|
||||
if (diff.Length() > 2.5)
|
||||
m_player.Move(diff);
|
||||
|
||||
//std::cout << sync.timestamp << " ms: " << comp.position << " - " << sync.position << " Diff: " << diff.Length() << std::endl;
|
||||
|
||||
if (diff.Length() > 1.5) {
|
||||
diff.Normalize();
|
||||
m_player.Move(-diff);
|
||||
}
|
||||
|
||||
// TODO: Syncer sync.timer avec le timer
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ bool OpenglContext::Start(const std::string& title, int width, int height, bool
|
||||
m_fullscreen = fullscreen;
|
||||
InitWindow(width, height);
|
||||
|
||||
Init();
|
||||
LoadResource();
|
||||
Init();
|
||||
|
||||
sf::Clock clock;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user