/** * Calls the 'process' method if the replay is activated and the event is of a type selected to be replayed. * This way, events of the types that are recorded and replayed are ignored during a replay. This is what makes * the player have no control over the character during a replay. * @param entity the entity which the event was sent against. * @param event the event being sent. */ @Override public void send(EntityRef entity, Event event) { if (recordAndReplayCurrentStatus.getStatus() != RecordAndReplayStatus.REPLAYING || !isSelectedToReplayEvent(event)) { originalSend(entity, event); } }
/** * Calls the 'process' method if the replay is activated and the event is of a type selected to be replayed. * This way, events of the types that are recorded and replayed are ignored during a replay. This is what makes * the player have no control over the character during a replay. * @param entity the entity which the event was sent against. * @param event the event being sent. * @param component the component sent along with the event. */ @Override public void send(EntityRef entity, Event event, Component component) { if (recordAndReplayCurrentStatus.getStatus() != RecordAndReplayStatus.REPLAYING || !isSelectedToReplayEvent(event)) { originalSend(entity, event, component); } }
/** * Try to process recorded events for 'maxDuration' miliseconds. Events are only processed if the time is right. * @param maxDuration the amount of time in which this method will try to process recorded events in one go. */ private void processRecordedEventsBatch(long maxDuration) { long beginTime = System.currentTimeMillis(); for (RecordedEvent re = recordedEvents.peek(); re != null; re = recordedEvents.peek()) { long passedTime = System.currentTimeMillis() - this.replayEventsLoadTime; //Waits until the time of reproduction is right or until 'maxDuration' miliseconds have already passed since this method was called while (passedTime < re.getTimestamp()) { passedTime = System.currentTimeMillis() - this.replayEventsLoadTime; if ((System.currentTimeMillis() - beginTime) >= maxDuration) { return; } } recordedEvents.poll(); EntityRef entity = getEntityRef(re); // Sends recorded event to be processed if (re.getComponent() != null) { originalSend(entity, re.getEvent(), re.getComponent()); } else { originalSend(entity, re.getEvent()); } this.lastRecordedEventIndex = re.getIndex(); // Check if time is up. if ((System.currentTimeMillis() - beginTime) >= maxDuration) { return; } } }
/** * Processes recorded and pending events. If recordedEvents is not loaded, load it from RecordedEventStore. */ @Override public void process() { processRecordedEvents(); PendingEvent event = pendingEvents.poll(); while (event != null) { if (event.getComponent() != null) { originalSend(event.getEntity(), event.getEvent(), event.getComponent()); } else { originalSend(event.getEntity(), event.getEvent()); } event = pendingEvents.poll(); } }