| [10175] | 1 | /* | 
|---|
 | 2 |  | 
|---|
 | 3 |    Copyright (C) 2006 orx | 
|---|
 | 4 |  | 
|---|
 | 5 |    This program is free software; you can redistribute it and/or modify | 
|---|
 | 6 |    it under the terms of the GNU General Public License as published by | 
|---|
 | 7 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
 | 8 |    any later version. | 
|---|
 | 9 |  | 
|---|
 | 10 | ### File Specific: | 
|---|
| [10431] | 11 |    main-programmer: Lieni | 
|---|
| [10175] | 12 | */ | 
|---|
 | 13 |  | 
|---|
 | 14 | #include "blink.h" | 
|---|
 | 15 |  | 
|---|
 | 16 | #include "util/loading/load_param.h" | 
|---|
 | 17 | #include "util/loading/factory.h" | 
|---|
 | 18 | #include "debug.h" | 
|---|
| [10253] | 19 | #include "state.h" | 
|---|
| [10407] | 20 | #include "effects/billboard.h" | 
|---|
| [10175] | 21 |  | 
|---|
 | 22 |  | 
|---|
 | 23 |  | 
|---|
 | 24 |  | 
|---|
 | 25 | ObjectListDefinition(Blink); | 
|---|
 | 26 | CREATE_FACTORY(Blink); | 
|---|
 | 27 |  | 
|---|
 | 28 | /** | 
|---|
 | 29 |  * standart constructor | 
|---|
 | 30 |  */ | 
|---|
 | 31 | Blink::Blink (const TiXmlElement* root) | 
|---|
 | 32 | { | 
|---|
 | 33 |   this->init(); | 
|---|
 | 34 |  | 
|---|
| [10431] | 35 |   if(root) | 
|---|
| [10175] | 36 |     this->loadParams(root); | 
|---|
| [10445] | 37 |  | 
|---|
 | 38 |   // calculation of the symbolTime | 
|---|
 | 39 |   this->symbolTime = this->period / this->blinkSequence.length(); | 
|---|
| [10491] | 40 |   //PRINTF(0)("\n\n\nperiod: %f\n\n\n", this->period); | 
|---|
| [10175] | 41 | } | 
|---|
 | 42 |  | 
|---|
 | 43 |  | 
|---|
 | 44 | /** | 
|---|
 | 45 |  * destroys a Blink | 
|---|
 | 46 |  */ | 
|---|
 | 47 | Blink::~Blink () | 
|---|
 | 48 | { | 
|---|
| [10431] | 49 |   if(bBoard) | 
|---|
 | 50 |     delete bBoard; | 
|---|
| [10175] | 51 | } | 
|---|
 | 52 |  | 
|---|
 | 53 |  | 
|---|
 | 54 | /** | 
|---|
 | 55 |  * initializes the Blink | 
|---|
 | 56 |  */ | 
|---|
 | 57 | void Blink::init() | 
|---|
 | 58 | { | 
|---|
 | 59 |   this->registerObject(this, Blink::_objectList); | 
|---|
 | 60 |   this->setName("Blink"); | 
|---|
 | 61 |  | 
|---|
 | 62 |   this->toList(OM_COMMON); | 
|---|
 | 63 |  | 
|---|
| [10407] | 64 |   this->bBoard = new Billboard; | 
|---|
| [10511] | 65 |   this->bBoard->setVisibility(true); | 
|---|
| [10445] | 66 |   this->bBoard->setTexture("textures/light/blink.png"); | 
|---|
| [10407] | 67 |  | 
|---|
| [10325] | 68 |   /// Standard values | 
|---|
| [10431] | 69 |   this->bBoard->setAbsCoor(0, 0, 0); | 
|---|
 | 70 |   // default position if not set in xml | 
|---|
| [10426] | 71 |   this->color = Color(1, 0, 0); | 
|---|
| [10429] | 72 |   // 10x10 pxl if not defined in xml | 
|---|
| [10253] | 73 |   this->size = 10; | 
|---|
| [10445] | 74 |   // default period | 
|---|
 | 75 |   this->period = 1; | 
|---|
 | 76 |   // default blink sequence | 
|---|
 | 77 |   this->blinkSequence = "00011234567889998876543211"; | 
|---|
| [10431] | 78 |  | 
|---|
| [10445] | 79 |   // start values of non-loadable variables | 
|---|
 | 80 |   this->blinkStr = 0; | 
|---|
 | 81 |   this->timer = 0; | 
|---|
 | 82 |   this->seqCounter = 0; | 
|---|
| [10491] | 83 |  | 
|---|
 | 84 |   // ugly hack continued | 
|---|
 | 85 |   this->setCoor = true; | 
|---|
| [10175] | 86 | } | 
|---|
 | 87 |  | 
|---|
 | 88 |  | 
|---|
 | 89 | /** | 
|---|
 | 90 |  *  load params | 
|---|
 | 91 |  * @param root TiXmlElement object | 
|---|
 | 92 |  */ | 
|---|
 | 93 | void Blink::loadParams(const TiXmlElement* root) | 
|---|
 | 94 | { | 
|---|
| [10253] | 95 |   WorldEntity::loadParams(root); | 
|---|
 | 96 |  | 
|---|
| [10491] | 97 |   LoadParam(root, "position", this, Blink, PNode::setAbsCoor); | 
|---|
| [10253] | 98 |   LoadParam(root, "size", this, Blink, setSize); | 
|---|
| [10325] | 99 |   LoadParam(root, "color", this, Blink, setColor); | 
|---|
| [10445] | 100 |   LoadParam(root, "period", this, Blink, setPeriod); | 
|---|
 | 101 |   LoadParam(root, "sequence", this, Blink, loadBlinkSequence); | 
|---|
| [10175] | 102 | } | 
|---|
 | 103 |  | 
|---|
 | 104 |  | 
|---|
 | 105 | /** | 
|---|
 | 106 |  * ticks the Blink | 
|---|
 | 107 |  * @param dt the time to ticks | 
|---|
 | 108 |  */ | 
|---|
 | 109 | void Blink::tick(float dt) | 
|---|
 | 110 | { | 
|---|
| [10491] | 111 |   // ugly hack continued, set absCoor only once | 
|---|
 | 112 |   if(this->setCoor) { | 
|---|
 | 113 |     this->bBoard->setAbsCoor(this->getAbsCoor()); | 
|---|
| [10530] | 114 |     this->bBoard->setAbsDir(this->getAbsDir()); | 
|---|
 | 115 |     this->bBoard->setRelCoor(this->getRelCoor()); | 
|---|
 | 116 |     this->bBoard->setRelDir(this->getRelDir()); | 
|---|
 | 117 |     this->bBoard->setParent(this); | 
|---|
| [10491] | 118 |     this->setCoor = false; | 
|---|
 | 119 |     this->symbolTime = this->period / this->blinkSequence.length(); | 
|---|
 | 120 |   } | 
|---|
 | 121 |  | 
|---|
| [10445] | 122 |   timer += dt; | 
|---|
| [10325] | 123 |  | 
|---|
| [10445] | 124 |   while(this->timer >= this->symbolTime) | 
|---|
 | 125 |   { | 
|---|
 | 126 |     this->blinkStr = (float)((int)(blinkSequence[seqCounter]) - 48) / 9; | 
|---|
| [10325] | 127 |  | 
|---|
| [10445] | 128 |     this->timer -= symbolTime; | 
|---|
| [10427] | 129 |  | 
|---|
| [10445] | 130 |     seqCounter++; | 
|---|
 | 131 |     seqCounter %= this->blinkSequence.length(); | 
|---|
 | 132 |   } | 
|---|
 | 133 |  | 
|---|
| [10431] | 134 |   this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr)); | 
|---|
| [10175] | 135 | } | 
|---|
 | 136 |  | 
|---|
 | 137 |  | 
|---|
 | 138 | /** | 
|---|
 | 139 |  * draws the blink | 
|---|
 | 140 |  */ | 
|---|
 | 141 | void Blink::draw() const | 
|---|
 | 142 | { | 
|---|
 | 143 |  | 
|---|
 | 144 | } | 
|---|