Mercurial > sumwars
changeset 6:7e04df9d6938 branch_net
=netzwerk simulation eingebaut
author | wuha |
---|---|
date | Mon, 22 Sep 2008 13:35:41 +0000 |
parents | 038918a365d3 |
children | f1aed00851e7 8452ab965d92 |
files | src/core/action.h src/core/charconv.h src/core/creature.cpp src/core/network.cpp src/core/world.cpp src/gl_gui/window_main_gl.cpp |
diffstat | 6 files changed, 96 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/action.h Mon Sep 22 09:47:53 2008 +0000 +++ b/src/core/action.h Mon Sep 22 13:35:41 2008 +0000 @@ -95,7 +95,7 @@ ANGER = 54, //v FURY = 55, //w - + // Schuetze Faehigkeiten TRIPLE_SHOT = 64, //a GUIDED_TRIPLE_SHOT = 65,//b MULTISHOT = 66, //c
--- a/src/core/charconv.h Mon Sep 22 09:47:53 2008 +0000 +++ b/src/core/charconv.h Mon Sep 22 13:35:41 2008 +0000 @@ -2,6 +2,8 @@ #define CHARCONV_H #include "raknet/RakNetTypes.h" #include "raknet/BitStream.h" +#include "raknet/GetTime.h" +#include "raknet/MessageIdentifiers.h" /** * \class CharConv @@ -18,7 +20,9 @@ CharConv() : m_bitstream() { - + m_timestamp = RakNet::GetTime(); + m_bitstream.Write((char) ID_TIMESTAMP); + m_bitstream.Write(m_timestamp); } /** @@ -30,7 +34,7 @@ CharConv(unsigned char* data, unsigned int size) : m_bitstream(data, size, false) { - + m_timestamp = RakNet::GetTime(); } /** @@ -41,6 +45,16 @@ CharConv(Packet* packet) : m_bitstream(packet->data, packet->length, false) { + if (packet->data[0] == ID_TIMESTAMP) + { + char tmp; + fromBuffer(tmp); + fromBuffer(m_timestamp); + } + else + { + m_timestamp = RakNet::GetTime(); + } } @@ -124,7 +138,12 @@ { return m_bitstream.GetNumberOfBitsUsed(); } - + + unsigned long getDelay() + { + return RakNet::GetTime()-m_timestamp; + } + private: /** @@ -132,6 +151,12 @@ * \brief enthaelt die Daten als Zeichenkette */ RakNet::BitStream m_bitstream; + + /** + * \var unsigned long m_timestamp + * \brief Zeit zur das Paket erstellt bzw erhalten wurde + */ + unsigned long m_timestamp; };
--- a/src/core/creature.cpp Mon Sep 22 09:47:53 2008 +0000 +++ b/src/core/creature.cpp Mon Sep 22 13:35:41 2008 +0000 @@ -4087,7 +4087,12 @@ if (m_action.m_type!=0) - DEBUG5("sending action: %i at %f %f, dir %f %f",m_action.m_type, getGeometry()->m_shape.m_coordinate_x, getGeometry()->m_shape.m_coordinate_y, getMoveInfo()->m_speed_x,getMoveInfo()->m_speed_y); + { + float acttime = m_action.m_time - m_action.m_elapsed_time; + float goalx = getGeometry()->m_shape.m_coordinate_x + getMoveInfo()->m_speed_x*(acttime); + float goaly = getGeometry()->m_shape.m_coordinate_y + getMoveInfo()->m_speed_y*(acttime); + DEBUG5("sending action: %i at %f %f, dir %f %f goal %f %f",m_action.m_type, getGeometry()->m_shape.m_coordinate_x, getGeometry()->m_shape.m_coordinate_y, getMoveInfo()->m_speed_x,getMoveInfo()->m_speed_y,goalx,goaly); + } } if (event->m_data & Event::DATA_HP) @@ -4142,7 +4147,6 @@ if (event->m_data & Event::DATA_WALK_SPEED) { - DEBUG("walk changed for %i",getId()); cv->toBuffer(getBaseAttrMod()->m_walk_speed); } @@ -4196,13 +4200,16 @@ DEBUG5("got Command %i",m_command.m_type); } - char tmp = m_action.m_type; + char oldact = m_action.m_type; float posx = getGeometry()->m_shape.m_coordinate_x; float posy = getGeometry()->m_shape.m_coordinate_y; float movex = getMoveInfo()->m_speed_x; float movey = getMoveInfo()->m_speed_y; + float newx = getGeometry()->m_shape.m_coordinate_x,newy= getGeometry()->m_shape.m_coordinate_y; + float newmovex,newmovey; - + bool newact= false; + bool newmove = false; if (event->m_data & Event::DATA_ACTION) { @@ -4210,11 +4217,9 @@ m_action.fromString(cv); float x,y; - cv->fromBuffer(x); - cv->fromBuffer(y); - moveTo(x,y); - if (m_action.m_type!=0) - DEBUG5("new Action %i at %f %f",m_action.m_type,x,y); + cv->fromBuffer(newx); + cv->fromBuffer(newy); + newact = true; } @@ -4277,7 +4282,6 @@ if (event->m_data & Event::DATA_WALK_SPEED) { - DEBUG("walk speed changed for %i",getId()); cv->fromBuffer(getBaseAttrMod()->m_walk_speed); } @@ -4311,16 +4315,57 @@ if (event->m_data & Event::DATA_MOVE_INFO) { - cv->fromBuffer(getMoveInfo()->m_speed_x); - cv->fromBuffer(getMoveInfo()->m_speed_y); - DEBUG5("old action: %i at %f %f, dir %f %f",tmp,posx,posy,movex,movey); - DEBUG5("received action: %i at %f %f, dir %f %f",m_action.m_type, getGeometry()->m_shape.m_coordinate_x, getGeometry()->m_shape.m_coordinate_y, getMoveInfo()->m_speed_x,getMoveInfo()->m_speed_y); + cv->fromBuffer(newmovex); + cv->fromBuffer(newmovey); + newmove = true; + } if (event->m_data & Event::DATA_LEVEL) { cv->fromBuffer(getBaseAttr()->m_level); } + + if (newmove) + { + // Zielort der Aktion berechnen + float acttime = m_action.m_time - m_action.m_elapsed_time; + float goalx = newx + newmovex*(acttime); + float goaly = newy + newmovey*(acttime); + + DEBUG5("goal %f %f current pos %f %f",goalx,goaly,getGeometry()->m_shape.m_coordinate_x,getGeometry()->m_shape.m_coordinate_y); + + // Zeit die zum erreichen des Zieles uebrig ist + float goaltime = acttime; + if (event->m_data & Event::DATA_ACTION) + { + goaltime -= cv->getDelay(); + } + DEBUG5("time to reach goal %f",goaltime); + + if (goaltime <0) + { + // wenn man schon lange da sein muesste, Objekt an den Zielort versetzen + moveTo(goalx,goaly); + } + else + { + // Bewegungsgeschwindigkeit so setzen, dass + getMoveInfo()->m_speed_x = (goalx-getGeometry()->m_shape.m_coordinate_x) / goaltime; + getMoveInfo()->m_speed_y = (goaly-getGeometry()->m_shape.m_coordinate_y) / goaltime; + DEBUG5("new speed %f %f",getMoveInfo()->m_speed_x,getMoveInfo()->m_speed_y); + } + + } + + if (newact) + { + m_action.m_elapsed_time += cv->getDelay(); + if (!newmove) + { + moveTo(newx,newy); + } + } }
--- a/src/core/network.cpp Mon Sep 22 09:47:53 2008 +0000 +++ b/src/core/network.cpp Mon Sep 22 13:35:41 2008 +0000 @@ -8,6 +8,8 @@ m_peer->Startup(1,10,&sock, 1); + m_peer->ApplyNetworkSimulator( 0, 200, 0); + }
--- a/src/core/world.cpp Mon Sep 22 09:47:53 2008 +0000 +++ b/src/core/world.cpp Mon Sep 22 13:35:41 2008 +0000 @@ -1025,8 +1025,8 @@ // Debugging: Region, Koordinaten setzen pl->getGridLocation()->m_region =0; - pl->getGeometry()->m_shape.m_coordinate_x = 6; - pl->getGeometry()->m_shape.m_coordinate_y = 11; + pl->getGeometry()->m_shape.m_coordinate_x = 8; + pl->getGeometry()->m_shape.m_coordinate_y = 8; insertPlayerIntoRegion(pl,pl->getGridLocation()->m_region);
--- a/src/gl_gui/window_main_gl.cpp Mon Sep 22 09:47:53 2008 +0000 +++ b/src/gl_gui/window_main_gl.cpp Mon Sep 22 13:35:41 2008 +0000 @@ -709,7 +709,7 @@ glPopMatrix(); } -/* + r=0.5; glPushMatrix(); glTranslatef(-8,-4,0); @@ -718,7 +718,7 @@ glBegin(GL_TRIANGLE_FAN); glVertex3f(0, 0,0.8); - for (float a=0;a<=(1-global_doc->getLocalPlayer()->m_timer1_perc)*6.3;a+=0.1) + for (float a=0;a<=(1-global_doc->getLocalPlayer()->getTimerPercent(1))*6.3;a+=0.1) { glVertex3f(cos(a)*r, sin(a)*r,0.8); } @@ -733,14 +733,14 @@ glBegin(GL_TRIANGLE_FAN); glVertex3f(0, 0,0.8); - for (float a=0;a<=(1-global_doc->getLocalPlayer()->m_timer2_perc)*6.3;a+=0.1) + for (float a=0;a<=(1-global_doc->getLocalPlayer()->getTimerPercent(2))*6.3;a+=0.1) { glVertex3f(cos(a)*r, sin(a)*r,0.8); } glEnd(); glPopMatrix(); -*/ + // Daten entsperren global_doc->unlock();