Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/space_ships/space_ship.cc @ 6902

Last change on this file since 6902 was 6902, checked in by rennerc, 18 years ago

send velocity again

File size: 19.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Benjamin Knecht
13   co-programmer: Silvan Nellen
14
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19#include "executor/executor.h"
20#include "space_ship.h"
21
22#include "objModel.h"
23#include "resource_manager.h"
24
25#include "weapons/weapon_manager.h"
26#include "weapons/test_gun.h"
27#include "weapons/turret.h"
28#include "weapons/cannon.h"
29
30#include "dot_emitter.h"
31#include "sprite_particles.h"
32
33#include "factory.h"
34#include "key_mapper.h"
35#include "event_handler.h"
36
37#include "network_game_manager.h"
38
39#include "power_ups/weapon_power_up.h"
40#include "power_ups/param_power_up.h"
41
42#include "graphics_engine.h"
43
44#include "plane.h"
45
46#include "state.h"
47#include "player.h"
48
49
50// #include "lib/gui/gl_gui/glgui_bar.h"
51// #include "lib/gui/gl_gui/glgui_pushbutton.h"
52
53
54using namespace std;
55
56CREATE_FACTORY(SpaceShip, CL_SPACE_SHIP);
57
58
59/**
60 *  destructs the spaceship, deletes alocated memory
61 */
62SpaceShip::~SpaceShip ()
63{
64}
65
66/**
67 * loads a Spaceships information from a specified file.
68 * @param fileName the name of the File to load the spaceship from (absolute path)
69 */
70SpaceShip::SpaceShip(const char* fileName)
71{
72  this->init();
73  TiXmlDocument doc(fileName);
74
75  if(!doc.LoadFile())
76  {
77    PRINTF(2)("Loading file %s failed for spaceship.\n", fileName);
78    return;
79  }
80
81  this->loadParams(doc.RootElement());
82}
83
84/**
85 *  creates a new Spaceship from Xml Data
86 * @param root the xml element containing spaceship data
87
88   @todo add more parameters to load
89*/
90SpaceShip::SpaceShip(const TiXmlElement* root)
91{
92  this->init();
93  if (root != NULL)
94    this->loadParams(root);
95  else
96  {
97    //this->loadModel("models/ships/reap_#.obj");
98    this->loadModel( "models/ships/fighter.obj" );
99  }
100
101}
102
103
104/**
105 * initializes a Spaceship
106 */
107void SpaceShip::init()
108{
109//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
110  this->setClassID(CL_SPACE_SHIP, "SpaceShip");
111
112  PRINTF(4)("SPACESHIP INIT\n");
113
114  //weapons:
115  Weapon* wpRight = new TestGun(0);
116  wpRight->setName("testGun Right");
117  Weapon* wpLeft = new TestGun(1);
118  wpLeft->setName("testGun Left");
119  Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON));
120
121  cannon->setName("BFG");
122
123  this->addWeapon(wpLeft, 1, 0);
124  this->addWeapon(wpRight,1 ,1);
125  this->addWeapon(cannon, 0, 6);
126
127  this->getWeaponManager()->changeWeaponConfig(1);
128
129  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
130
131  xMouse = yMouse = 0;
132  yInvert = 1;
133  mouseSensitivity = 0.001;
134  airViscosity = 0.05;
135  controlVelocityX = 25;
136  controlVelocityY = 150;
137  shipInertia = 1.5;
138//  cycle = 0.0;
139
140  this->setHealthMax(100);
141  this->setHealth(80);
142
143  travelSpeed = 40.0;
144  acceleration = 3;
145  this->velocity = this->getAbsDirX()*travelSpeed;
146  this->mouseDir = this->getAbsDir();
147  this->pitchDir = this->getAbsDir();
148
149//   GLGuiButton* button = new GLGuiPushButton();
150//    button->show();
151//    button->setLabel("orxonox");
152//    button->setBindNode(this);
153//     GLGuiBar* bar = new GLGuiBar();
154//     bar->show();
155//     bar->setValue(7.0);
156//     bar->setMaximum(10);
157//     bar->setSize2D( 20, 100);
158//     bar->setAbsCoor2D( 10, 200);
159
160  //add events to the eventlist
161  registerEvent(KeyMapper::PEV_UP);
162  registerEvent(KeyMapper::PEV_DOWN);
163  registerEvent(KeyMapper::PEV_LEFT);
164  registerEvent(KeyMapper::PEV_RIGHT);
165  //registerEvent(SDLK_q);
166  //registerEvent(SDLK_e);
167  registerEvent(KeyMapper::PEV_FIRE1);
168  registerEvent(KeyMapper::PEV_NEXT_WEAPON);
169  registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
170  //registerEvent(SDLK_PAGEUP);
171  //registerEvent(SDLK_PAGEDOWN);
172  registerEvent(EV_MOUSE_MOTION);
173
174  this->getWeaponManager()->setSlotCount(7);
175
176  this->getWeaponManager()->setSlotPosition(0, Vector(-2.6, .1, -3.0));
177  this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
178
179  this->getWeaponManager()->setSlotPosition(1, Vector(-2.6, .1, 3.0));
180  this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
181
182  this->getWeaponManager()->setSlotPosition(2, Vector(-1.5, .5, -.5));
183  this->getWeaponManager()->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
184
185  this->getWeaponManager()->setSlotPosition(3, Vector(-1.5, .5, .5));
186  this->getWeaponManager()->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
187
188  this->getWeaponManager()->setSlotPosition(4, Vector(-1.5, -.5, .5));
189  this->getWeaponManager()->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
190
191  this->getWeaponManager()->setSlotPosition(5, Vector(-1.5, -.5, -.5));
192  this->getWeaponManager()->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
193//
194   this->getWeaponManager()->setSlotPosition(6, Vector(-1, 0.0, 0));
195   this->getWeaponManager()->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
196   //
197//   this->getWeaponManager()->setSlotPosition(8, Vector(-2.5, -0.3, -2.0));
198//   this->getWeaponManager()->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0)));
199//
200//   this->getWeaponManager()->setSlotPosition(9, Vector(-2.5, -0.3, 2.0));
201//   this->getWeaponManager()->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));:
202
203  this->getWeaponManager()->getFixedTarget()->setParent(this);
204  this->getWeaponManager()->getFixedTarget()->setRelCoor(100000,0,0);
205
206  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
207
208  this->burstEmitter = new DotEmitter(200, 0.0, .01);
209  this->burstEmitter->setParent(this);
210  this->burstEmitter->setRelCoor(-1, .5, 0);
211  this->burstEmitter->setName("SpaceShip_Burst_emitter");
212
213  this->burstSystem = new SpriteParticles(1000);
214  this->burstSystem->addEmitter(this->burstEmitter);
215  this->burstSystem->setName("SpaceShip_Burst_System");
216  ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png");
217  this->burstSystem->setLifeSpan(1.0, .3);
218  this->burstSystem->setRadius(0.0, 1.0);
219  this->burstSystem->setRadius(0.05, 1.0);
220  this->burstSystem->setRadius(.5, .8);
221  this->burstSystem->setRadius(1.0, 0);
222  this->burstSystem->setColor(0.0, .7,.7,1,.7);
223  this->burstSystem->setColor(0.2, 0,0,0.8,.5);
224  this->burstSystem->setColor(0.5, .5,.5,.8,.8);
225  this->burstSystem->setColor(1.0, .8,.8,.8,.0);
226
227}
228
229
230/**
231 * loads the Settings of a SpaceShip from an XML-element.
232 * @param root the XML-element to load the Spaceship's properties from
233 */
234void SpaceShip::loadParams(const TiXmlElement* root)
235{
236  Playable::loadParams(root);
237}
238
239
240void SpaceShip::enter()
241{
242  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true);
243  this->attachCamera();
244}
245
246void SpaceShip::leave()
247{
248  dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false);
249  this->detachCamera();
250}
251
252
253/**
254 *  effect that occurs after the SpaceShip is spawned
255*/
256void SpaceShip::postSpawn ()
257{
258  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
259}
260
261/**
262 *  the action occuring if the spaceship left the game
263*/
264void SpaceShip::leftWorld ()
265{}
266
267WorldEntity* ref = NULL;
268/**
269 *  this function is called, when two entities collide
270 * @param entity: the world entity with whom it collides
271 *
272 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
273 */
274void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location)
275{
276  Playable::collidesWith(entity, location);
277  if (entity->isA(CL_TURRET_POWER_UP) && entity != ref)
278  {
279    this->ADDWEAPON();
280    ref = entity;
281    }
282//  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
283}
284
285/**
286 *  draws the spaceship after transforming it.
287*/
288void SpaceShip::draw () const
289{
290  WorldEntity::draw();
291  this->getWeaponManager()->draw();
292
293  //this->debug(0);
294}
295
296/**
297 *  the function called for each passing timeSnap
298 * @param time The timespan passed since last update
299*/
300void SpaceShip::tick (float time)
301{
302  Playable::tick(time);
303
304  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )
305   {
306    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
307    else if (xMouse < -controlVelocityX) xMouse = -controlVelocityX;
308    if (yMouse > controlVelocityY) yMouse = controlVelocityY;
309    else if (yMouse < -controlVelocityY) yMouse = -controlVelocityY;
310
311    pitchDir = (Quaternion(xMouse*mouseSensitivity*0.5, Vector(1,0,0)));
312
313    mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity*yInvert, Vector(0,0,1))*pitchDir);
314    xMouse = yMouse = 0;
315   }
316
317
318//   if( this != State::getPlayer()->getControllable())
319//     return;
320
321  // spaceship controlled movement
322  if (this->getOwner() == this->getHostID())
323    this->calculateVelocity(time);
324
325 
326  Vector move = velocity*time;
327
328  //orient the velocity in the direction of the spaceship.
329  travelSpeed = velocity.len();
330  velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity;
331  velocity = (velocity.getNormalized())*travelSpeed;
332  this->burstEmitter->setEmissionRate(travelSpeed);
333  this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1);
334
335  //orient the spaceship in direction of the mouse
336   rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
337   if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
338    this->setAbsDir( rotQuat);
339   //this->setAbsDirSoft(mouseDir,5);
340
341  // this is the air friction (necessary for a smooth control)
342  if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001;
343  else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001;
344
345  //other physics (gravity)
346  //if(travelSpeed < 120)
347  //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time;
348
349  //hoover effect
350  //cycle += time;
351  //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
352
353  //readjust
354  //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
355  //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
356
357  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
358
359  this->shiftCoor(move);
360
361
362}
363
364/**
365 *  calculate the velocity
366 * @param time the timeslice since the last frame
367*/
368void SpaceShip::calculateVelocity (float time)
369{
370  Vector accel(0.0, 0.0, 0.0);
371  /*
372  Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter
373  */
374  //float rotVal = 0.0;
375  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
376  /* calculate the direction in which the craft is heading  */
377
378  //Plane plane(Vector(0,1,0), Vector(0,0,0));
379
380  if( this->bUp )
381   {
382     //this->shiftCoor(this->getAbsDirX());
383      //accel += (this->getAbsDirX())*2;
384      accel += (this->getAbsDirX())*acceleration;
385
386   }
387
388  if( this->bDown )
389   {
390     //this->shiftCoor((this->getAbsDirX())*-1);
391     //accel -= (this->getAbsDirX())*2;
392    //if(velocity.len() > 50)
393     accel -= (this->getAbsDirX())*0.5*acceleration;
394
395
396
397   }
398
399  if( this->bLeft/* > -this->getRelCoor().z*2*/)
400  {
401    this->shiftDir(Quaternion(time, Vector(0,1,0)));
402//    accel -= rightDirection;
403    //velocityDir.normalize();
404    //rot +=Vector(1,0,0);
405    //rotVal -= .4;
406  }
407  if( this->bRight /* > this->getRelCoor().z*2*/)
408  {
409    this->shiftDir(Quaternion(-time, Vector(0,1,0)));
410
411    //    accel += rightDirection;
412    //velocityDir.normalize();
413    //rot += Vector(1,0,0);
414    //rotVal += .4;
415  }
416
417
418  if( this->bRollL /* > -this->getRelCoor().z*2*/)
419  {
420    mouseDir *= Quaternion(-time*2, Vector(1,0,0));
421//    accel -= rightDirection;
422    //velocityDir.normalize();
423    //rot +=Vector(1,0,0);
424    //rotVal -= .4;
425  }
426  if( this->bRollR /* > this->getRelCoor().z*2*/)
427  {
428    mouseDir *= Quaternion(time*2, Vector(1,0,0));
429
430    //    accel += rightDirection;
431    //velocityDir.normalize();
432    //rot += Vector(1,0,0);
433    //rotVal += .4;
434  }
435  if (this->bAscend )
436  {
437    this->shiftDir(Quaternion(time, Vector(0,0,1)));
438
439//    accel += upDirection;
440    //velocityDir.normalize();
441    //rot += Vector(0,0,1);
442    //rotVal += .4;
443  }
444  if (this->bDescend )
445  {
446    this->shiftDir(Quaternion(-time, Vector(0,0,1)));
447
448    //    accel -= upDirection;
449    //velocityDir.normalize();
450    //rot += Vector(0,0,1);
451    //rotVal -= .4;
452  }
453
454  velocity += accel*time*100;
455  //rot.normalize();
456  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
457}
458
459/**
460 * @todo switch statement ??
461 */
462void SpaceShip::process(const Event &event)
463{
464  Playable::process(event);
465
466  if( event.type == KeyMapper::PEV_LEFT)
467      this->bRollL = event.bPressed;
468  else if( event.type == KeyMapper::PEV_RIGHT)
469      this->bRollR = event.bPressed;
470  else if( event.type == KeyMapper::PEV_UP)
471    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
472  else if( event.type == KeyMapper::PEV_DOWN)
473    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
474  else if( event.type == EV_MOUSE_MOTION)
475  {
476    this->xMouse += event.xRel;
477    this->yMouse += event.yRel;
478  }
479}
480
481#include "weapons/aiming_turret.h"
482// FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG
483void SpaceShip::ADDWEAPON()
484{
485  Weapon* turret = NULL;
486
487  if ((float)rand()/RAND_MAX < .9)
488  {
489    //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET))
490    {
491      turret = new Turret();
492      this->addWeapon(turret, 2);
493      this->getWeaponManager()->changeWeaponConfig(2);
494    }
495  }
496  else
497  {
498    //if (this->getWeaponManager()->hasFreeSlot(3))
499    {
500      turret = dynamic_cast<Weapon*>(Factory::fabricate(CL_TARGETING_TURRET));
501      if (turret != NULL)
502      this->addWeapon(turret, 3);
503
504      this->getWeaponManager()->changeWeaponConfig(3);
505    }
506  }
507
508  if(turret != NULL)
509  {
510    turret->setName("Turret");
511    turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);
512  }
513}
514
515#define MASK_bUp         1
516#define MASK_bDown       2
517#define MASK_bLeft       4
518#define MASK_bRight      8
519#define MASK_bAscend    16
520#define MASK_bDescend   32
521#define MASK_bRollL     64
522#define MASK_bRollR    128
523
524#define DATA_state       1
525#define DATA_flags       2
526#define DATA_mouse       3
527#define DATA_sync        4
528#define DATA_velocity    5
529#define DATA_playables   6
530
531int SpaceShip::writeBytes( const byte * data, int length, int sender )
532{
533  SYNCHELP_READ_BEGIN();
534
535  byte b;
536
537  while ( SYNCHELP_READ_REMAINING()>0 )
538  {
539    SYNCHELP_READ_BYTE( b, NWT_SS_B );
540
541    if ( b == DATA_state )
542    {
543      setRequestedSync( false );
544      setIsOutOfSync( false );
545      SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SS_WE_STATE );
546
547      continue;
548    }
549
550    if ( b == DATA_flags )
551    {
552      if ( this->getOwner() != this->getHostID() )
553      {
554        byte flags = 0;
555        SYNCHELP_READ_BYTE( flags, NWT_SS_FLAGS );
556
557        bUp = (flags & MASK_bUp) != 0;
558        bDown = (flags & MASK_bDown) != 0;
559        bLeft = (flags & MASK_bLeft) != 0;
560        bRight = (flags & MASK_bRight) != 0;
561        bAscend = (flags & MASK_bAscend) != 0;
562        bDescend = (flags & MASK_bDescend) != 0;
563        bRollL = (flags & MASK_bRollL) != 0;
564        bRollR = (flags & MASK_bRollR) != 0;
565       
566      }
567      else
568        assert(false);
569
570      continue;
571    }
572
573    if ( b == DATA_mouse )
574    {
575      if ( this->getOwner() != this->getHostID() )
576      {
577        SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
578        SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
579        SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
580        SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
581      }
582      else
583        assert(false);
584
585      continue;
586    }
587
588    if ( b == DATA_sync )
589    {
590      if ( this->getOwner() != this->getHostID() )
591      {
592        SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC );
593      }
594      else
595        assert(false);
596
597      continue;
598    }
599
600    if ( b == DATA_velocity )
601    {
602      if ( this->getOwner() != this->getHostID() )
603      {
604        SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
605        SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
606        SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
607      }     
608      else
609        assert(false);
610     
611      continue;
612    }
613   
614    if ( b == DATA_playables )
615    {
616      if ( this->getOwner() != this->getHostID() )
617      {
618        SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC );
619      }
620      else
621        assert(false);
622    }
623  }
624
625  return SYNCHELP_READ_N;
626}
627
628
629
630int SpaceShip::readBytes( byte * data, int maxLength, int * reciever )
631{
632  SYNCHELP_WRITE_BEGIN();
633
634  if ( isOutOfSync() && !requestedSync() /*&& this->getHostID()!=this->getOwner()*/ )
635  {
636    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
637    setRequestedSync( true );
638    PRINTF(0)("REQUESTED STATE %d\n", this->getUniqueID());
639  }
640
641  int rec = this->getRequestSync();
642  if ( rec > 0 )
643  {
644    *reciever = rec;
645
646    PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
647
648    SYNCHELP_WRITE_BYTE( (byte)DATA_state, NWT_SS_B );
649
650    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
651
652    return SYNCHELP_WRITE_N;
653  }
654
655  *reciever = 0 - this->getOwner();
656  //TODO: implement with SYNCHELP_WRITE_SENT()
657  bool sentSomething = false;
658
659  if ( PNode::needsReadSync() && ( this->getHostID()==0 || this->getOwner() == this->getHostID() ) )
660  {
661    PRINTF(0)("sending PNode::readSync\n");
662    SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B );
663    SYNCHELP_WRITE_FKT( PNode::readSync, NWT_SS_PN_SYNC );
664    sentSomething = true;
665  }
666
667  if ( this->getHostID()==0 || this->getHostID()==this->getOwner() )
668  {
669    byte mask = 0;
670
671    if ( bUp )
672      mask |= MASK_bUp;
673    if ( bDown )
674      mask |= MASK_bDown;
675    if ( bLeft )
676      mask |= MASK_bLeft;
677    if ( bRight )
678      mask |= MASK_bRight;
679    if ( bAscend )
680      mask |= MASK_bAscend;
681    if ( bRollL )
682      mask |= MASK_bRollL;
683    if ( bRollR )
684      mask |= MASK_bRollR;
685
686
687    if ( mask != oldMask )
688    {
689      oldMask = mask;
690      PRINTF(0)("sending mask\n");
691      sentSomething = true;
692      SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
693      SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS );
694    }
695#define __OFFSET_MDIR_W 0.01
696#define __OFFSET_MDIR_V 0.01
697    if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_MDIR_W ||
698         fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_MDIR_V ||
699         fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_MDIR_V ||
700         fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_MDIR_V )
701    {
702      oldMouseDir = mouseDir;
703
704      SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B );
705      PRINTF(0)("SENDING mousedir\n");
706      sentSomething = true;
707      SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
708      SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
709      SYNCHELP_WRITE_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
710      SYNCHELP_WRITE_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
711    }
712#define __OFFSET_VEL 0.05
713    if ( fabs( oldVelocity.x - velocity.x ) > __OFFSET_VEL*velocity.x ||
714         fabs( oldVelocity.y - velocity.y ) > __OFFSET_VEL*velocity.y ||
715         fabs( oldVelocity.z - velocity.z ) > __OFFSET_VEL*velocity.z )
716    {
717      oldVelocity = velocity;
718      PRINTF(0)("SENDING velocity\n");
719      SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
720      SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
721      SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
722      SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
723    }
724   
725    if ( Playable::needsReadSync() )
726    {
727      sentSomething = true;
728      PRINTF(0)("SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC )\n");
729      SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B );
730      SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC );
731    }
732
733  }
734 
735  if ( !sentSomething )
736    *reciever = 0;
737
738  return SYNCHELP_WRITE_N;
739}
740
741
Note: See TracBrowser for help on using the repository browser.