Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Predicting only player movement

  • Loading branch information...
commit 20261112f7aa1371977d17fbb2abd520438006e4 1 parent 583a5ff
@Detegr authored
Showing with 38 additions and 24 deletions.
  1. +13 −14 client.cpp
  2. +6 −0 entity.cpp
  3. +1 −0  entity.h
  4. +18 −10 packetparser.cpp
View
27 client.cpp
@@ -108,6 +108,19 @@ int main()
currt=newt;
keyvec=getkeys();
+
+ const std::vector<C_GfxEntity*>& entities = r->M_Entities();
+ for(std::vector<C_GfxEntity*>::const_iterator it=entities.begin(); it!=entities.end(); ++it)
+ {
+ C_Entity* e=pm->GetEntity((*it)->M_Id());
+ if(e)
+ {
+ pm->ApplyPlayerForces(e, keyvec);
+ (*it)->SetPosition(e->GetPosition().x, e->GetPosition().y);
+ (*it)->M_SetRotation(e->GetRotation());
+ }
+ }
+
if(sock.M_Receive(p, 1, NULL, NULL))
{
C_Packet keys;
@@ -119,19 +132,6 @@ int main()
prevkeyvec=keyvec;
while(p.M_Size()) C_PacketParser::M_Parse(p);
}
- //else
- {
- const std::vector<C_GfxEntity*>& entities = r->M_Entities();
- for(std::vector<C_GfxEntity*>::const_iterator it=entities.begin(); it!=entities.end(); ++it)
- {
- C_Entity* e=pm->GetEntity((*it)->M_Id());
- if((*it)->IsPlayer())
- {
- pm->ApplyPlayerForces(e, keyvec);
- }
- (*it)->SetPosition(e->GetPosition().x, e->GetPosition().y);
- (*it)->M_SetRotation(e->GetRotation());
- }
/*
const std::vector<C_GfxEntity*>& entities = r->M_Entities();
for(std::vector<C_GfxEntity*>::const_iterator it=entities.begin(); it!=entities.end(); ++it)
@@ -140,7 +140,6 @@ int main()
(*it)->M_ExtrapolateRotation(idt.M_Get());
}
*/
- }
accu += framet;
while(accu >= dt)
{
View
6 entity.cpp
@@ -73,6 +73,12 @@ void C_GfxEntity::M_SetRotation(float amount)
m_Er.M_Add(amount*(180/3.14));
m_RotationMatrix = glm::rotate(glm::mat4(1.0), (const float)(amount*(180/3.14)), glm::vec3(0.0f, 0.0f, 1.0f));
}
+
+float C_GfxEntity::GetRotation() const
+{
+ return glm::acos(m_RotationMatrix[0][0]);
+}
+
void C_GfxEntity::M_ExtrapolateRotation(double dt)
{
float a=m_Er.M_ExtrapolateValue();
View
1  entity.h
@@ -39,6 +39,7 @@ class C_GfxEntity
void M_SetScale(float amount);
void M_Rotate(float amount);
void M_SetRotation(float amount);
+ float GetRotation() const;
void M_ExtrapolateRotation(double dt);
const std::string& M_ModelName() const;
const glm::mat4& M_ModelMatrix();
View
28 packetparser.cpp
@@ -36,7 +36,11 @@ void C_PacketParser::M_Parse(C_Packet& p)
{
unsigned short id;
p >> id;
- C_Singleton::M_Renderer()->M_GetEntity(id)->SetPlayer(true);
+ C_GfxEntity* e=C_Singleton::M_Renderer()->M_GetEntity(id);
+ e->SetPlayer(true);
+ /*C_Entity* pe=*/C_Singleton::M_PhysicsManager()->M_CreateDynamicEntity(e->M_Id(), C_Singleton::M_ModelManager()->M_Get(e->M_ModelName()), e->M_Scale());
+ //pe->SetPosition(e->GetPosition());
+ //pe->SetRotation(e->GetRotation());
return;
}
}
@@ -70,30 +74,34 @@ void C_PacketParser::M_GfxEntity(C_Packet& p, bool full)
C_Entity* pe=pm->GetEntity(id);
if(e)
{
- e->SetPosition(pe->GetPosition());
- pe->SetPosition(x,y);
+ e->SetPosition(x,y);
e->M_SetRotation(angle);
- pe->SetRotation(angle);
+ if(pe)
+ {
+ pe->SetPosition(x,y);
+ pe->SetRotation(angle);
+ }
}
else if(full)
{
std::cout << "Creating entity with id: " << id << std::endl;
- C_PhysicsManager* p=C_Singleton::M_PhysicsManager();
+ //C_PhysicsManager* p=C_Singleton::M_PhysicsManager();
C_ModelManager* m=C_Singleton::M_ModelManager();
const C_Model& model=m->M_Get(name);
C_GfxEntity* e=C_GfxEntity::M_Create(id, model, scale);
- C_Entity* pe;
+ //C_Entity* pe;
+ //if(e->IsPlayer())
+ //{
+ /*
if(type == C_Entity::Fixed)
{
pe=p->M_CreateStaticEntity(id, model, scale);
}
else
{
- pe=p->M_CreateDynamicEntity(id, model, scale);
- }
+ */
+ //}
e->SetPosition(x,y);
- pe->SetPosition(x,y);
- pe->SetRotation(angle);
e->M_SetRotation(angle);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.