Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

spaceship: made velocity not depend on dt. velocity is only calculated on owner

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  Vector move = velocity*time;
326
327  //orient the velocity in the direction of the spaceship.
328  travelSpeed = velocity.len();
329  velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity;
330  velocity = (velocity.getNormalized())*travelSpeed;
331  this->burstEmitter->setEmissionRate(travelSpeed);
332  this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1);
333
334  //orient the spaceship in direction of the mouse
335   rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia);
336   if (this->getAbsDir().distance(rotQuat) > 0.00000000000001)
337    this->setAbsDir( rotQuat);
338   //this->setAbsDirSoft(mouseDir,5);
339
340  // this is the air friction (necessary for a smooth control)
341  if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001;
342  else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001;
343
344  //other physics (gravity)
345  //if(travelSpeed < 120)
346  //move += Vector(0,-1,0)*60*time + Vector(0,1,0)*travelSpeed/2*time;
347
348  //hoover effect
349  //cycle += time;
350  //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
351
352  //readjust
353  //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
354  //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
355
356  //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
357
358  this->shiftCoor(move);
359
360
361}
362
363/**
364 *  calculate the velocity
365 * @param time the timeslice since the last frame
366*/
367void SpaceShip::calculateVelocity (float time)
368{
369  Vector accel(0.0, 0.0, 0.0);
370  /*
371  Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter
372  */
373  //float rotVal = 0.0;
374  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
375  /* calculate the direction in which the craft is heading  */
376
377  //Plane plane(Vector(0,1,0), Vector(0,0,0));
378
379  if( this->bUp )
380   {
381     //this->shiftCoor(this->getAbsDirX());
382      //accel += (this->getAbsDirX())*2;
383      accel += (this->getAbsDirX())*acceleration;
384
385   }
386
387  if( this->bDown )
388   {
389     //this->shiftCoor((this->getAbsDirX())*-1);
390     //accel -= (this->getAbsDirX())*2;
391    //if(velocity.len() > 50)
392     accel -= (this->getAbsDirX())*0.5*acceleration;
393
394
395
396   }
397
398  if( this->bLeft/* > -this->getRelCoor().z*2*/)
399  {
400    this->shiftDir(Quaternion(time, Vector(0,1,0)));
401//    accel -= rightDirection;
402    //velocityDir.normalize();
403    //rot +=Vector(1,0,0);
404    //rotVal -= .4;
405  }
406  if( this->bRight /* > this->getRelCoor().z*2*/)
407  {
408    this->shiftDir(Quaternion(-time, Vector(0,1,0)));
409
410    //    accel += rightDirection;
411    //velocityDir.normalize();
412    //rot += Vector(1,0,0);
413    //rotVal += .4;
414  }
415
416
417  if( this->bRollL /* > -this->getRelCoor().z*2*/)
418  {
419    mouseDir *= Quaternion(-time*2, Vector(1,0,0));
420//    accel -= rightDirection;
421    //velocityDir.normalize();
422    //rot +=Vector(1,0,0);
423    //rotVal -= .4;
424  }
425  if( this->bRollR /* > this->getRelCoor().z*2*/)
426  {
427    mouseDir *= Quaternion(time*2, Vector(1,0,0));
428
429    //    accel += rightDirection;
430    //velocityDir.normalize();
431    //rot += Vector(1,0,0);
432    //rotVal += .4;
433  }
434  if (this->bAscend )
435  {
436    this->shiftDir(Quaternion(time, Vector(0,0,1)));
437
438//    accel += upDirection;
439    //velocityDir.normalize();
440    //rot += Vector(0,0,1);
441    //rotVal += .4;
442  }
443  if (this->bDescend )
444  {
445    this->shiftDir(Quaternion(-time, Vector(0,0,1)));
446
447    //    accel -= upDirection;
448    //velocityDir.normalize();
449    //rot += Vector(0,0,1);
450    //rotVal -= .4;
451  }
452
453  velocity += accel;
454  //rot.normalize();
455  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
456}
457
458/**
459 * @todo switch statement ??
460 */
461void SpaceShip::process(const Event &event)
462{
463  Playable::process(event);
464
465  if( event.type == KeyMapper::PEV_LEFT)
466      this->bRollL = event.bPressed;
467  else if( event.type == KeyMapper::PEV_RIGHT)
468      this->bRollR = event.bPressed;
469  else if( event.type == KeyMapper::PEV_UP)
470    this->bUp = event.bPressed; //this->shiftCoor(0,.1,0);
471  else if( event.type == KeyMapper::PEV_DOWN)
472    this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0);
473  else if( event.type == EV_MOUSE_MOTION)
474  {
475    this->xMouse += event.xRel;
476    this->yMouse += event.yRel;
477  }
478}
479
480#include "weapons/aiming_turret.h"
481// FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG
482void SpaceShip::ADDWEAPON()
483{
484  Weapon* turret = NULL;
485
486  if ((float)rand()/RAND_MAX < .9)
487  {
488    //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET))
489    {
490      turret = new Turret();
491      this->addWeapon(turret, 2);
492      this->getWeaponManager()->changeWeaponConfig(2);
493    }
494  }
495  else
496  {
497    //if (this->getWeaponManager()->hasFreeSlot(3))
498    {
499      turret = dynamic_cast<Weapon*>(Factory::fabricate(CL_TARGETING_TURRET));
500      if (turret != NULL)
501      this->addWeapon(turret, 3);
502
503      this->getWeaponManager()->changeWeaponConfig(3);
504    }
505  }
506
507  if(turret != NULL)
508  {
509    turret->setName("Turret");
510    turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);
511  }
512}
513
514#define MASK_bUp         1
515#define MASK_bDown       2
516#define MASK_bLeft       4
517#define MASK_bRight      8
518#define MASK_bAscend    16
519#define MASK_bDescend   32
520#define MASK_bRollL     64
521#define MASK_bRollR    128
522
523#define DATA_state       1
524#define DATA_flags       2
525#define DATA_mouse       3
526#define DATA_sync        4
527#define DATA_velocity    5
528#define DATA_playables   6
529
530int SpaceShip::writeBytes( const byte * data, int length, int sender )
531{
532  SYNCHELP_READ_BEGIN();
533
534  byte b;
535
536  while ( SYNCHELP_READ_REMAINING()>0 )
537  {
538    SYNCHELP_READ_BYTE( b, NWT_SS_B );
539
540    if ( b == DATA_state )
541    {
542      setRequestedSync( false );
543      setIsOutOfSync( false );
544      SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SS_WE_STATE );
545
546      continue;
547    }
548
549    if ( b == DATA_flags )
550    {
551      if ( this->getOwner() != this->getHostID() )
552      {
553        byte flags = 0;
554        SYNCHELP_READ_BYTE( flags, NWT_SS_FLAGS );
555
556        bUp = (flags & MASK_bUp) != 0;
557        bDown = (flags & MASK_bDown) != 0;
558        bLeft = (flags & MASK_bLeft) != 0;
559        bRight = (flags & MASK_bRight) != 0;
560        bAscend = (flags & MASK_bAscend) != 0;
561        bDescend = (flags & MASK_bDescend) != 0;
562        bRollL = (flags & MASK_bRollL) != 0;
563        bRollR = (flags & MASK_bRollR) != 0;
564       
565      }
566      else
567        assert(false);
568
569      continue;
570    }
571
572    if ( b == DATA_mouse )
573    {
574      if ( this->getOwner() != this->getHostID() )
575      {
576        SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
577        SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
578        SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
579        SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
580      }
581      else
582        assert(false);
583
584      continue;
585    }
586
587    if ( b == DATA_sync )
588    {
589      if ( this->getOwner() != this->getHostID() )
590      {
591        SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC );
592      }
593      else
594        assert(false);
595
596      continue;
597    }
598
599    if ( b == DATA_velocity )
600    {
601      if ( this->getOwner() != this->getHostID() )
602      {
603        SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
604        SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
605        SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
606      }     
607      else
608        assert(false);
609     
610      continue;
611    }
612   
613    if ( b == DATA_playables )
614    {
615      if ( this->getOwner() != this->getHostID() )
616      {
617        SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC );
618      }
619      else
620        assert(false);
621    }
622  }
623
624  return SYNCHELP_READ_N;
625}
626
627
628
629int SpaceShip::readBytes( byte * data, int maxLength, int * reciever )
630{
631  SYNCHELP_WRITE_BEGIN();
632
633  if ( isOutOfSync() && !requestedSync() /*&& this->getHostID()!=this->getOwner()*/ )
634  {
635    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
636    setRequestedSync( true );
637    PRINTF(0)("REQUESTED STATE %d\n", this->getUniqueID());
638  }
639
640  int rec = this->getRequestSync();
641  if ( rec > 0 )
642  {
643    *reciever = rec;
644
645    PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
646
647    SYNCHELP_WRITE_BYTE( (byte)DATA_state, NWT_SS_B );
648
649    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
650
651    return SYNCHELP_WRITE_N;
652  }
653
654  *reciever = 0 - this->getOwner();
655  //TODO: implement with SYNCHELP_WRITE_SENT()
656  bool sentSomething = false;
657
658  if ( PNode::needsReadSync() && ( this->getHostID()==0 || this->getOwner() == this->getHostID() ) )
659  {
660    PRINTF(0)("sending PNode::readSync\n");
661    SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B );
662    SYNCHELP_WRITE_FKT( PNode::readSync, NWT_SS_PN_SYNC );
663    sentSomething = true;
664  }
665
666  if ( this->getHostID()==0 || this->getHostID()==this->getOwner() )
667  {
668    byte mask = 0;
669
670    if ( bUp )
671      mask |= MASK_bUp;
672    if ( bDown )
673      mask |= MASK_bDown;
674    if ( bLeft )
675      mask |= MASK_bLeft;
676    if ( bRight )
677      mask |= MASK_bRight;
678    if ( bAscend )
679      mask |= MASK_bAscend;
680    if ( bRollL )
681      mask |= MASK_bRollL;
682    if ( bRollR )
683      mask |= MASK_bRollR;
684
685
686    if ( mask != oldMask )
687    {
688      oldMask = mask;
689      PRINTF(0)("sending mask\n");
690      sentSomething = true;
691      SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
692      SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS );
693    }
694#define __OFFSET_MDIR_W 0.01
695#define __OFFSET_MDIR_V 0.01
696    if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_MDIR_W ||
697         fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_MDIR_V ||
698         fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_MDIR_V ||
699         fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_MDIR_V )
700    {
701      oldMouseDir = mouseDir;
702
703      SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B );
704      PRINTF(0)("SENDING mousedir\n");
705      sentSomething = true;
706      SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
707      SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
708      SYNCHELP_WRITE_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
709      SYNCHELP_WRITE_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
710    }
711#define __OFFSET_VEL 0.05
712    if ( fabs( oldVelocity.x - velocity.x ) > __OFFSET_VEL*velocity.x ||
713         fabs( oldVelocity.y - velocity.y ) > __OFFSET_VEL*velocity.y ||
714         fabs( oldVelocity.z - velocity.z ) > __OFFSET_VEL*velocity.z )
715    {
716      oldVelocity = velocity;
717      PRINTF(0)("SENDING velocity\n");
718      //SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
719      //SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
720      //SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
721      //SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
722    }
723   
724    if ( Playable::needsReadSync() )
725    {
726      sentSomething = true;
727      PRINTF(0)("SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC )\n");
728      SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B );
729      SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC );
730    }
731
732  }
733 
734  if ( !sentSomething )
735    *reciever = 0;
736
737  return SYNCHELP_WRITE_N;
738}
739
740
Note: See TracBrowser for help on using the repository browser.