| 97 | } |
| 98 | |
| 99 | void location::updatepos() |
| 100 | { |
| 101 | ASSERT(ref); // was: ASSERT(!stale && ref); |
| 102 | if(stale) return; |
| 103 | |
| 104 | const vec &pos = ref->currentposition(); |
| 105 | |
| 106 | // forced fadeout radius |
| 107 | bool volumeadjust = (cfg->model==soundconfig::DM_LINEAR); |
| 108 | float forcedvol = 1.0f; |
| 109 | if(volumeadjust) |
| 110 | { |
| 111 | float dist = camera1->o.dist(pos); |
| 112 | if(dist>cfg->audibleradius) forcedvol = 0.0f; |
| 113 | else if(dist<0) forcedvol = 1.0f; |
| 114 | else forcedvol = 1.0f-(dist/cfg->audibleradius); |
| 115 | } |
| 116 | |
| 117 | // reference determines the used model |
| 118 | switch(ref->type) |
| 119 | { |
| 120 | case worldobjreference::WR_CAMERA: break; |
| 121 | case worldobjreference::WR_PHYSENT: |
| 122 | { |
| 123 | if(!ref->nodistance()) src->position(pos); |
| 124 | if(volumeadjust) setvolume(forcedvol); |
| 125 | break; |
| 126 | } |
| 127 | case worldobjreference::WR_ENTITY: |
| 128 | { |
| 129 | entityreference &eref = *(entityreference *)ref; |
| 130 | const float vol = eref.ent->attr4<=0.0f ? 1.0f : eref.ent->attr4/255.0f; |
| 131 | float dist = camera1->o.dist(pos); |
| 132 | |
| 133 | if(ref->nodistance()) |
| 134 | { |
| 135 | // own distance model for entities/mapsounds: linear & clamping |
| 136 | |
| 137 | const float innerradius = float(eref.ent->attr3); // full gain area / size property |
| 138 | const float outerradius = float(eref.ent->attr2); // fading gain area / radius property |
| 139 | |
| 140 | if(dist <= innerradius) src->gain(1.0f*vol); // inside full gain area |
| 141 | else if(dist <= outerradius) // inside fading gain area |
| 142 | { |
| 143 | const float fadeoutdistance = outerradius-innerradius; |
| 144 | const float fadeout = dist-innerradius; |
| 145 | src->gain((1.0f - fadeout/fadeoutdistance)*vol); |
| 146 | } |
| 147 | else src->gain(0.0f); // outside entity |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | // use openal distance model to make the sound appear from a certain direction (non-ambient) |
| 152 | src->position(pos); |
| 153 | src->gain(vol); |
| 154 | } |
| 155 | break; |
| 156 | } |
nothing calls this directly
no test coverage detected