38 numFrames = _numFrames;
42 replayTimer =
new Timer();
53 unsigned long bsize = (numNodes * numFrames *
sizeof(
node_simple_t) + numBeams * numFrames *
sizeof(
beam_simple_t) + numFrames *
sizeof(
unsigned long)) / 1024.0f;
54 LOG(
"replay buffer size: " +
TOSTRING(bsize) +
" kB");
62 this->ar_replay_precision = 0.0f;
64 this->ar_replay_precision = 1.0f / ((float)steps);
69 int x = (MyGUI::RenderManager::getInstance().getViewSize().width - width) / 2;
87 void* Replay::getWriteBuffer(
int type)
108 times = (
unsigned long*)calloc(numFrames,
sizeof(
unsigned long));
120 times[writeIndex] = replayTimer->getMicroseconds();
124 ptr = (
void *)(
nodes + (writeIndex * m_actor->ar_num_nodes));
129 ptr = (
void *)(beams + (writeIndex * m_actor->ar_num_beams));
134 void Replay::writeDone()
139 if (writeIndex == numFrames)
147 void* Replay::getReadBuffer(
int offset,
int type,
unsigned long& time)
151 if (offset <= -numFrames)
152 offset = -numFrames + 1;
154 int delta = writeIndex + offset;
156 if (firstRun && type == 0)
157 return (
void *)(
nodes);
158 else if (firstRun && type == 1)
159 return (
void *)(beams);
172 return (
void *)(
nodes + delta * m_actor->ar_num_nodes);
174 return (
void *)(beams + delta * m_actor->ar_num_beams);
178 unsigned long Replay::getLastReadTime()
183 void Replay::onPhysicsStep()
186 if (m_replay_timer >= ar_replay_precision)
192 for (
int i = 0; i < m_actor->ar_num_nodes; i++)
194 nbuff[i].
position = m_actor->ar_nodes[i].AbsPosition;
195 nbuff[i].
velocity = m_actor->ar_nodes[i].Velocity;
203 for (
int i = 0; i < m_actor->ar_num_beams; i++)
205 bbuff[i].
broken = m_actor->ar_beams[i].bm_broken;
206 bbuff[i].
disabled = m_actor->ar_beams[i].bm_disabled;
211 m_replay_timer = 0.0f;
215 void Replay::replayStepActor()
217 if (ar_replay_pos != m_replay_pos_prev)
219 unsigned long time = 0;
224 for (
int i = 0; i < m_actor->ar_num_nodes; i++)
226 m_actor->ar_nodes[i].AbsPosition = nbuff[i].
position;
227 m_actor->ar_nodes[i].RelPosition = nbuff[i].
position - m_actor->ar_origin;
229 m_actor->ar_nodes[i].Velocity = nbuff[i].
velocity;
230 m_actor->ar_nodes[i].Forces = Vector3::ZERO;
233 m_actor->updateSlideNodePositions();
234 m_actor->UpdateBoundingBoxes();
235 m_actor->calculateAveragePosition();
241 for (
int i = 0; i < m_actor->ar_num_beams; i++)
243 m_actor->ar_beams[i].bm_broken = bbuff[i].
broken;
244 m_actor->ar_beams[i].bm_disabled = bbuff[i].
disabled;
247 m_replay_pos_prev = ar_replay_pos;
251 void Replay::UpdateInputEvents()
255 if (m_actor->ar_state == ActorState::LOCAL_REPLAY)
256 m_actor->ar_state = ActorState::LOCAL_SIMULATED;
258 m_actor->ar_state = ActorState::LOCAL_REPLAY;
261 if (m_actor->ar_state == ActorState::LOCAL_REPLAY)
265 this->ar_replay_pos++;
269 this->ar_replay_pos--;
273 this->ar_replay_pos += 10;
277 this->ar_replay_pos -= 10;
282 if (this->ar_replay_pos <= 0 && this->ar_replay_pos >= -this->getNumFrames())
292 if (this->ar_replay_pos > 0)
294 this->ar_replay_pos = 0;
296 if (this->ar_replay_pos < -this->getNumFrames())
298 this->ar_replay_pos = -this->getNumFrames();