コード例 #1
0
ファイル: window.cpp プロジェクト: MatthewBeardmore/tdesktop
void Window::notifyShowNext(NotifyWindow *remove) {
	if (App::quiting()) return;

	int32 count = NotifyWindowsCount;
	if (remove) {
		for (NotifyWindows::iterator i = notifyWindows.begin(), e = notifyWindows.end(); i != e; ++i) {
			if ((*i) == remove) {
				notifyWindows.erase(i);
				break;
			}
		}
	}

	uint64 ms = getms(true), nextAlert = 0;
	bool alert = false;
	for (NotifyWhenAlerts::iterator i = notifyWhenAlerts.begin(); i != notifyWhenAlerts.end();) {
		while (!i.value().isEmpty() && i.value().begin().key() <= ms) {
			i.value().erase(i.value().begin());
			NotifySettingsPtr n = i.key()->peer->notify;
			if (n == EmptyNotifySettings || (n != UnknownNotifySettings && n->mute <= unixtime())) {
				alert = true;
			}
		}
		if (i.value().isEmpty()) {
			i = notifyWhenAlerts.erase(i);
		} else {
			if (!nextAlert || nextAlert > i.value().begin().key()) {
				nextAlert = i.value().begin().key();
			}
			++i;
		}
	}
	if (alert) {
		psFlash();
		App::playSound();
	}

    if (cCustomNotifies()) {
        for (NotifyWindows::const_iterator i = notifyWindows.cbegin(), e = notifyWindows.cend(); i != e; ++i) {
            int32 ind = (*i)->index();
            if (ind < 0) continue;
            --count;
        }
    }
	if (count <= 0 || !cDesktopNotify()) {
		if (nextAlert) {
			notifyWaitTimer.start(nextAlert - ms);
		}
		return;
	}

	QRect r = psDesktopRect();
	int32 x = r.x() + r.width() - st::notifyWidth - st::notifyDeltaX, y = r.y() + r.height() - st::notifyHeight - st::notifyDeltaY;
	while (count > 0) {
		uint64 next = 0;
		HistoryItem *notifyItem = 0;
		NotifyWaiters::iterator notifyWaiter;
		for (NotifyWaiters::iterator i = notifyWaiters.begin(); i != notifyWaiters.end(); ++i) {
			History *history = i.key();
			if (history->currentNotification() && history->currentNotification()->id != i.value().msg) {
				NotifyWhenMaps::iterator j = notifyWhenMaps.find(history);
				if (j == notifyWhenMaps.end()) {
					history->clearNotifications();
					i = notifyWaiters.erase(i);
					continue;
				}
				do {
					NotifyWhenMap::const_iterator k = j.value().constFind(history->currentNotification()->id);
					if (k != j.value().cend()) {
						i.value().msg = k.key();
						i.value().when = k.value();
						break;
					}
					history->skipNotification();
				} while (history->currentNotification());
			}
			if (!history->currentNotification()) {
				notifyWhenMaps.remove(history);
				i = notifyWaiters.erase(i);
				continue;
			}
			uint64 when = i.value().when;
			if (!notifyItem || next > when) {
				next = when;
				notifyItem = history->currentNotification();
				notifyWaiter = i;
			}
		}
		if (notifyItem) {
			if (next > ms) {
				if (nextAlert && nextAlert < next) {
					next = nextAlert;
					nextAlert = 0;
				}
				notifyWaitTimer.start(next - ms);
				break;
			} else {
                if (cCustomNotifies()) {
                    NotifyWindow *notify = new NotifyWindow(notifyItem, x, y);
                    notifyWindows.push_back(notify);
					psNotifyShown(notify);
                    --count;
                } else {
					psPlatformNotify(notifyItem);
                }


				uint64 ms = getms(true);
				History *history = notifyItem->history();
				history->skipNotification();
				NotifyWhenMaps::iterator j = notifyWhenMaps.find(history);
				if (j == notifyWhenMaps.end() || !history->currentNotification()) {
					history->clearNotifications();
					notifyWaiters.erase(notifyWaiter);
					if (j != notifyWhenMaps.end()) notifyWhenMaps.erase(j);
					continue;
				}
				j.value().remove(notifyItem->id);
				do {
					NotifyWhenMap::const_iterator k = j.value().constFind(history->currentNotification()->id);
					if (k != j.value().cend()) {
						notifyWaiter.value().msg = k.key();
						notifyWaiter.value().when = k.value();
						break;
					}
					history->skipNotification();
				} while (history->currentNotification());
				if (!history->currentNotification()) {
					notifyWaiters.erase(notifyWaiter);
					notifyWhenMaps.erase(j);
					continue;
				}
			}
		} else {
			break;
		}
	}
	if (nextAlert) {
		notifyWaitTimer.start(nextAlert - ms);
	}

	count = NotifyWindowsCount - count;
	for (NotifyWindows::const_iterator i = notifyWindows.cbegin(), e = notifyWindows.cend(); i != e; ++i) {
		int32 ind = (*i)->index();
		if (ind < 0) continue;
		--count;
		(*i)->moveTo(x, y - count * (st::notifyHeight + st::notifyDeltaY));
	}
}
コード例 #2
0
ファイル: belief.cpp プロジェクト: AdaCompNUS/despot
vector<State*> Belief::Resample(int num, const Belief& belief, History history,
	int hstart) {
	double reward;
	OBS_TYPE obs;

	vector<State*> sample;
	int count = 0;
	int pos = 0;
	double max_wgt = Globals::NEG_INFTY;
	vector<State*> particles;
	int trial = 0;
	while (count < num || trial < 200 * num) {
		// Pick next particle
		if (pos == particles.size()) {
			particles = belief.Sample(num);
			pos = 0;
		}
		State* particle = particles[pos];

		trial++;

		// Step through history
		double log_wgt = 0;
		for (int i = hstart; i < history.Size(); i++) {
			belief.model_->Step(*particle, Random::RANDOM.NextDouble(),
				history.Action(i), reward, obs);

			double prob = belief.model_->ObsProb(history.Observation(i),
				*particle, history.Action(i));
			if (prob > 0) {
				log_wgt += log(prob);
			} else {
				belief.model_->Free(particle);
				break;
			}
		}

		// Add to sample if survived
		if (particle->IsAllocated()) {
			particle->weight = log_wgt;
			sample.push_back(particle);

			max_wgt = max(log_wgt, max_wgt);
			count++;
		}

		// Remove particles with very small weights
		if (count == num) {
			for (int i = sample.size() - 1; i >= 0; i--) {
				if (sample[i]->weight - max_wgt < log(1.0 / num)) {
					belief.model_->Free(sample[i]);
					sample.erase(sample.begin() + i);
					count--;
				}
			}
		}

		pos++;
	}

	// Free unused particles
	for (int i = pos; i < particles.size(); i++)
		belief.model_->Free(particles[i]);

	double total_weight = 0;
	for (int i = 0; i < sample.size(); i++) {
		sample[i]->weight = exp(sample[i]->weight - max_wgt);
		total_weight += sample[i]->weight;
	}
	for (int i = 0; i < sample.size(); i++) {
		sample[i]->weight = sample[i]->weight / total_weight;
	}

	logd << "[Belief::Resample] Resampled " << sample.size() << " particles"
		<< endl;
	for (int i = 0; i < sample.size(); i++) {
		logv << " " << i << " = " << *sample[i] << endl;
	}

	return sample;
}
コード例 #3
0
ファイル: V8HistoryCustom.cpp プロジェクト: dog-god/iptv
bool V8History::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
{
    History* history = V8History::toNative(host);
    return BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), history->frame(), DoNotReportSecurityError);
}
コード例 #4
0
ファイル: V8HistoryCustom.cpp プロジェクト: dzhshf/WebKit
bool V8History::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
{
    // Only allow same origin access.
    History* history = V8History::toNative(host);
    return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), history->frame(), false);
}
コード例 #5
0
ファイル: HistoryTest.cpp プロジェクト: huner15/saas
TEST(GetLast, Empty) {
    History history;
    EXPECT_EQ(NULL, history.GetLast());
}
コード例 #6
0
ファイル: HistoryTest.cpp プロジェクト: huner15/saas
TEST(GetSecondLast, Empty) {
    History history;
    EXPECT_EQ(NULL, history.GetSecondToLast());
}
コード例 #7
0
void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event,
    const InputMessage* next) {
    if (!mResampleTouch
            || !(event->getSource() & AINPUT_SOURCE_CLASS_POINTER)
            || event->getAction() != AMOTION_EVENT_ACTION_MOVE) {
        return;
    }

    ssize_t index = findTouchState(event->getDeviceId(), event->getSource());
    if (index < 0) {
#if DEBUG_RESAMPLING
        ALOGD("Not resampled, no touch state for device.");
#endif
        return;
    }

    TouchState& touchState = mTouchStates.editItemAt(index);
    if (touchState.historySize < 1) {
#if DEBUG_RESAMPLING
        ALOGD("Not resampled, no history for device.");
#endif
        return;
    }

    // Ensure that the current sample has all of the pointers that need to be reported.
    const History* current = touchState.getHistory(0);
    size_t pointerCount = event->getPointerCount();
    for (size_t i = 0; i < pointerCount; i++) {
        uint32_t id = event->getPointerId(i);
        if (!current->idBits.hasBit(id)) {
#if DEBUG_RESAMPLING
            ALOGD("Not resampled, missing id %d", id);
#endif
            return;
        }
    }

    // Find the data to use for resampling.
    const History* other;
    History future;
    float alpha;
    if (next) {
        // Interpolate between current sample and future sample.
        // So current->eventTime <= sampleTime <= future.eventTime.
        future.initializeFrom(next);
        other = &future;
        nsecs_t delta = future.eventTime - current->eventTime;
        if (delta < RESAMPLE_MIN_DELTA) {
#if DEBUG_RESAMPLING
            ALOGD("Not resampled, delta time is %lld ns.", delta);
#endif
            return;
        }
        alpha = float(sampleTime - current->eventTime) / delta;
    } else if (touchState.historySize >= 2) {
        // Extrapolate future sample using current sample and past sample.
        // So other->eventTime <= current->eventTime <= sampleTime.
        other = touchState.getHistory(1);
        nsecs_t delta = current->eventTime - other->eventTime;
        if (delta < RESAMPLE_MIN_DELTA) {
#if DEBUG_RESAMPLING
            ALOGD("Not resampled, delta time is %lld ns.", delta);
#endif
            return;
        }
        nsecs_t maxPredict = current->eventTime + min(delta / 2, RESAMPLE_MAX_PREDICTION);
        if (sampleTime > maxPredict) {
#if DEBUG_RESAMPLING
            ALOGD("Sample time is too far in the future, adjusting prediction "
                    "from %lld to %lld ns.",
                    sampleTime - current->eventTime, maxPredict - current->eventTime);
#endif
            sampleTime = maxPredict;
        }
        alpha = float(current->eventTime - sampleTime) / delta;
    } else {
#if DEBUG_RESAMPLING
        ALOGD("Not resampled, insufficient data.");
#endif
        return;
    }

    // Resample touch coordinates.
    touchState.lastResample.eventTime = sampleTime;
    touchState.lastResample.idBits.clear();
    for (size_t i = 0; i < pointerCount; i++) {
        uint32_t id = event->getPointerId(i);
        touchState.lastResample.idToIndex[id] = i;
        touchState.lastResample.idBits.markBit(id);
        PointerCoords& resampledCoords = touchState.lastResample.pointers[i];
        const PointerCoords& currentCoords = current->getPointerById(id);
        if (other->idBits.hasBit(id)
                && shouldResampleTool(event->getToolType(i))) {
            const PointerCoords& otherCoords = other->getPointerById(id);
            resampledCoords.copyFrom(currentCoords);
            resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_X,
                    lerp(currentCoords.getX(), otherCoords.getX(), alpha));
            resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y,
                    lerp(currentCoords.getY(), otherCoords.getY(), alpha));
#if DEBUG_RESAMPLING
            ALOGD("[%d] - out (%0.3f, %0.3f), cur (%0.3f, %0.3f), "
                    "other (%0.3f, %0.3f), alpha %0.3f",
                    id, resampledCoords.getX(), resampledCoords.getY(),
                    currentCoords.getX(), currentCoords.getY(),
                    otherCoords.getX(), otherCoords.getY(),
                    alpha);
#endif
        } else {
            resampledCoords.copyFrom(currentCoords);
#if DEBUG_RESAMPLING
            ALOGD("[%d] - out (%0.3f, %0.3f), cur (%0.3f, %0.3f)",
                    id, resampledCoords.getX(), resampledCoords.getY(),
                    currentCoords.getX(), currentCoords.getY());
#endif
        }
    }

    event->addSample(sampleTime, touchState.lastResample.pointers);
}
コード例 #8
0
ファイル: bpredictor.cpp プロジェクト: pwnall/pset_writeups
 Gshare() {
   globalHistory.setAllTaken();
   for (int i = 0; i < (1 << globalSize); i++) {
     table[i].setWeakTaken();
   }
 }
コード例 #9
0
void  TestUseCaseUndo::run_006 ()
{
   Document document (Model::use (), 123456789UL, 'appl', 'gui ');

   Song & song = document.root <Song> ();
   Track & track = *song._tracks.emplace ();
   Clip & clip1 = *track._clips.emplace (1.0, 1.0);
   Clip & clip2 = *track._clips.emplace (5.0, 1.0);
   Clip & clip3 = *track._clips.emplace (2.5, 2.0);
   song._selection.emplace (clip1);
   song._selection.emplace (clip2);

   document.commit ();
   document.push ();

   History <HistoryStoreMemory> history (document);

   //

   clip1._position = 2.0;

   document.commit ();
   auto tx = document.squash ();
   history.add_undo_step (tx);

   //

   clip1._position = 3.5;

   document.commit ();
   tx = document.squash ();
   *history.last_undo () = tx;
   document.push ();

   //

   clip1._position = 4.7;
   clip1._duration = 2.5;
   clip2._position = 4.2;

   document.commit ();
   tx = document.squash ();
   history.add_undo_step (tx);

   //

   clip2._position = 4.2;
   document.commit ();

   clip1._position = 1.2;
   document.commit ();

   clip3._position = 3.4;
   document.commit ();

   tx = document.squash ();
   *history.last_undo () = tx;

   //

   bool ok_flag = history.execute_undo ();
   flip_TEST (ok_flag);

   flip_TEST (clip1._position == 3.5);
   flip_TEST (clip1._duration == 1.0);
   flip_TEST (clip2._position == 5.0);
   flip_TEST (clip2._duration == 1.0);
   flip_TEST (clip3._position == 2.5);
   flip_TEST (clip3._duration == 2.0);

   ok_flag = history.execute_redo ();
   flip_TEST (ok_flag);

   flip_TEST (clip1._position == 1.2);
   flip_TEST (clip1._duration == 2.5);
   flip_TEST (clip2._position == 4.2);
   flip_TEST (clip2._duration == 1.0);
   flip_TEST (clip3._position == 3.4);
   flip_TEST (clip3._duration == 2.0);

   ok_flag = history.execute_undo ();
   flip_TEST (ok_flag);

   ok_flag = history.execute_undo ();
   flip_TEST (ok_flag);

   flip_TEST (clip1._position == 1.0);
   flip_TEST (clip1._duration == 1.0);
   flip_TEST (clip2._position == 5.0);
   flip_TEST (clip2._duration == 1.0);
   flip_TEST (clip3._position == 2.5);
   flip_TEST (clip3._duration == 2.0);

   ok_flag = history.execute_redo ();
   flip_TEST (ok_flag);

   flip_TEST (clip1._position == 3.5);
   flip_TEST (clip1._duration == 1.0);
   flip_TEST (clip2._position == 5.0);
   flip_TEST (clip2._duration == 1.0);
   flip_TEST (clip3._position == 2.5);
   flip_TEST (clip3._duration == 2.0);

   ok_flag = history.execute_undo ();
   flip_TEST (ok_flag);

   flip_TEST (clip1._position == 1.0);
   flip_TEST (clip1._duration == 1.0);
   flip_TEST (clip2._position == 5.0);
   flip_TEST (clip2._duration == 1.0);
   flip_TEST (clip3._position == 2.5);
   flip_TEST (clip3._duration == 2.0);

   ok_flag = history.execute_redo ();
   flip_TEST (ok_flag);

   ok_flag = history.execute_redo ();
   flip_TEST (ok_flag);

   flip_TEST (clip1._position == 1.2);
   flip_TEST (clip1._duration == 2.5);
   flip_TEST (clip2._position == 4.2);
   flip_TEST (clip2._duration == 1.0);
   flip_TEST (clip3._position == 3.4);
   flip_TEST (clip3._duration == 2.0);
}
コード例 #10
0
void V8PopStateEvent::stateAttributeGetterCustom(
    const v8::FunctionCallbackInfo<v8::Value>& info) {
  ScriptState* scriptState = ScriptState::current(info.GetIsolate());
  v8::Local<v8::Value> result = V8HiddenValue::getHiddenValue(
      scriptState, info.Holder(), V8HiddenValue::state(info.GetIsolate()));

  if (!result.IsEmpty()) {
    v8SetReturnValue(info, result);
    return;
  }

  PopStateEvent* event = V8PopStateEvent::toImpl(info.Holder());
  History* history = event->history();
  if (!history || !event->serializedState()) {
    // If the event doesn't have serializedState(), it means that the
    // event was initialized with PopStateEventInit. In such case, we need
    // to get a v8 value for the current world from state().
    if (event->serializedState())
      result = event->serializedState()->deserialize();
    else
      result = event->state().v8ValueFor(scriptState);
    if (result.IsEmpty())
      result = v8::Null(info.GetIsolate());
    v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result));
    return;
  }

  // There's no cached value from a previous invocation, nor a state value was
  // provided by the event, but there is a history object, so first we need to
  // see if the state object has been deserialized through the history object
  // already.
  // The current history state object might've changed in the meantime, so we
  // need to take care of using the correct one, and always share the same
  // deserialization with history.state.

  bool isSameState = history->isSameAsCurrentState(event->serializedState());

  if (isSameState) {
    v8::Local<v8::Value> v8HistoryValue =
        toV8(history, info.Holder(), info.GetIsolate());
    if (v8HistoryValue.IsEmpty())
      return;
    v8::Local<v8::Object> v8History = v8HistoryValue.As<v8::Object>();
    if (!history->stateChanged()) {
      result = V8HiddenValue::getHiddenValue(
          scriptState, v8History, V8HiddenValue::state(info.GetIsolate()));
      if (!result.IsEmpty()) {
        v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result));
        return;
      }
    }
    result = event->serializedState()->deserialize(info.GetIsolate());
    V8HiddenValue::setHiddenValue(scriptState, v8History,
                                  V8HiddenValue::state(info.GetIsolate()),
                                  result);
  } else {
    result = event->serializedState()->deserialize(info.GetIsolate());
  }

  v8SetReturnValue(info, cacheState(scriptState, info.Holder(), result));
}
コード例 #11
0
void guiChangeIP(Frame *frame, int eventId){
    Change c;
    HANDLE tibia = c.getTibiaProcess();
    if(!tibia){
        frame->sb->SetStatusText(wxT("Tibia process not found!"),0);
        if(eventId == MENU_CHANGE_IP)
            sendDialog(wxT("Tibia process not found!"), wxOK | wxICON_ERROR);
        CloseHandle(tibia);
        return;
    }
    std::string sip = std::string(frame->ip->GetValue().mb_str());
    int sport = frame->host->GetValue();
    std::string client = std::string(frame->clients->GetValue().mb_str());
    if(sip == ""){
        frame->sb->SetStatusText(wxT("IP adress not found!"),0);
        if(eventId == MENU_CHANGE_IP)
        	sendDialog(wxT("IP adress not found!"), wxOK | wxICON_ERROR);
        return;
    }
    size_t found = sip.find(":");
    if(found != string::npos){
        sport = atoi(sip.substr(found+1, sip.size()).c_str());
        sip = sip.substr(0, found);
        frame->ip->SetValue(sip);
        frame->host->SetValue(sport);
    }
        
    if(client != "Auto"){
        std::string s ="";
        s += client.at(1);
        if(s == ".")
        	client = client.erase(1,1);
    }
        	
    bool ret = c.changeIP(sip, sport, client);
        
    if(ret){
        frame->sb->SetStatusText(wxT("IP Changed!"),0);
        if(eventId == MENU_CHANGE_IP)
        	sendDialog(wxT("IP Changed!"), wxOK);
    }else{
        frame->sb->SetStatusText(wxT("IP not Changed!"),0);
        if(eventId == MENU_CHANGE_IP)
        	sendDialog(wxT("IP not Changed!"), wxOK | wxICON_ERROR);
        return;
    }
    
    char buf[4];
    itoa(sport, buf, 10);
    std::string save;
    save += sip + ":" + buf;
	h.saveHistory(save);
	frame->ip->Clear();
	vector<string>z;
	z = h.getHistory();
	for(int i = 0; i < int(z.size()); i++){
		wxString wxs(z[i].c_str(), wxConvUTF8);
		frame->ip->Append(wxs);
	}
	std::string tmp = z[0].substr(0, z[0].size()-5);
	wxString last(tmp.c_str(), wxConvUTF8);
	frame->ip->SetValue(last);
}
コード例 #12
0
ファイル: NBShell.cpp プロジェクト: nsbender/nbshell
void NBShell::run() {
	Prompt * prompt = new Prompt();
	Path * path = new Path();
	History * history = new History();

	while (true){
		cout << (prompt -> get()) << "$ " << flush;
		CommandLine * cmd = new CommandLine(cin);

		if (cmd->getArgCount() == 0){ // If the input is empty, do nothing (Allow the user to press enter with no text)
			cmd->~CommandLine();
			continue;
		}

		else if ((string)cmd -> getCommand() == "history"){
			history -> add(cmd -> getRawInput());
			if ((cmd -> getArgCount() > 1)&&(string)(cmd -> getArgVector(1)) == 
"-c"){
				history -> clear();
			}
			else{
				history -> getAll();
			}
		}

		else if ((string)cmd -> getCommand() == "cd"){
			struct stat st;
			if (stat((cmd->getArgVector(1)), &st) == 0 && S_ISDIR(st.st_mode)) //Check to make sure the directory exists
			{
				chdir(cmd->getArgVector(1)); //Tell the system to change the current working directory
				prompt->update();
				history->add(cmd->getRawInput());
				cmd->~CommandLine(); // Destroy the CommandLine after it is done and restart the loop.
				continue;
			}
			else {
				cout << "No such directory!" << endl;
				history->add(cmd->getRawInput());
				cmd->~CommandLine();
				continue;
			}
		}

		else if ((string)cmd -> getCommand() == "exit"){
			exit(0); // Exit the program
		}

		else if ((string)cmd -> getCommand() == "pwd"){
			cout << prompt->get() << endl;
			history->add(cmd->getRawInput()); 
			cmd->~CommandLine();
			continue;
		}

		else{
			history -> add(cmd -> getRawInput());
			int status = path -> find((string)cmd -> getCommand());
			if (status != -1 ){ // After checking that the program exists...
				pid_t pid;
				int forkStatus;
				string completePath = (path->getDirectory(status)) + "/" + ((string)cmd -> getCommand()); // Add the file name to the end of the directory that contains it
				if ((pid = fork()) < 0) { // Attempt to create a child using fork
					perror("fork() error");
					exit(-1);
				}
				else if (pid == 0) { //Check to see if fork isn't a parent; If so execute the command.
					if (execve(completePath.c_str(),cmd->getArgVector(), NULL) < 0) { //Execute the file and pass in its arguments from the CommandLine
						perror("execve() error");
						cmd->~CommandLine();
						continue;
					}
					exit(0);
				}
				//Have the parent wait for child completion if & is included in the command
				if (cmd->Ampersand() == false) {
					waitpid(pid, &forkStatus, 0); // Wait for the child with the PID specified at its creation
					cmd->~CommandLine();
					continue;
				}
			}
			else{
				cout << "Command not found." << endl;
			} 
		}
	}
}
コード例 #13
0
ファイル: _band.cpp プロジェクト: zsimpson/plug_public
void render() {
	int i;

	if( changeMon.hasChanged() ) {
		cheReactionReset();
	}

	glScalef( 1.f/DIMX, 1.f/DIMX, 1.f );
	glTranslatef( -DIMX/2.f, -DIMY/2.f, 0.f );
	zviewpointSetupView();

	zprofBeg( band_update );
	for( i=0; i<Band_updates; i++ ) {
		partUpdate();
		cheReactionUpdate();
	}
	zprofEnd();

	Band_avgZHits = (float)zReactHits / (float)framesSinceLastReset;

	zprofBeg( band_render );
	glPointSize( Band_pointSize );
	glVertexPointer( 2, GL_INT, sizeof(Part), &part[0].pos );
	glEnableClientState( GL_VERTEX_ARRAY );
	glColorPointer( 3, GL_UNSIGNED_BYTE, sizeof(Part), &part[0].color );
	glEnableClientState( GL_COLOR_ARRAY );
 	glDrawArrays( GL_POINTS, 0, partCount );

	glColor3ub( 100, 100, 100 );
	glBegin( GL_LINES );
	float cntf = (float)spatialHistogramCount;
	for( int x=0; x<DIMX; x++ ) {
		glVertex2f( (float)x, 0.f );
		glVertex2f( (float)x, Band_histogramScale * (float)spatialHistogram[x] / cntf );
	}
	glEnd();

	glTranslatef( 0.f, -22, 0.f );
	glBegin( GL_LINES );
	glColor3ub( 255, 255, 255 );
	glVertex2f( 0.f, 0.f );
	glVertex2f( Band_plotScaleX * (float)inputHistory.size, 0.f );

	glColor3ub( 50, 255, 50 );
	glVertex2f( 0.f, Band_plotScaleY0 * Band_signalTop );
	glVertex2f( Band_plotScaleX * (float)inputHistory.size, Band_plotScaleY0 * Band_signalTop );
	glEnd();

	glColor3ub( 100, 255, 100 );
	glBegin( GL_LINE_STRIP );
	for( i=0; i<inputHistory.size-1; i++ ) {
		glVertex2f( Band_plotScaleX * (float)i, Band_plotScaleY0 * inputHistory.getVal(i) );
	}
	glEnd();

	glColor3ub( 100, 100, 255 );
	glBegin( GL_LINE_STRIP );
	for( i=0; i<inputHistory.size-1; i++ ) {
		glVertex2f( Band_plotScaleX * (float)i, Band_plotScaleY1 * outputHistory.getAvg(i) );
	}
	glEnd();

	// DRAW the power spectrum
	glTranslatef( 0.f, -22, 0.f );
	glBegin( GL_LINES );
	glColor3ub( 255, 255, 255 );
	glVertex2f( 0.f, 0.f );
	glVertex2f( Band_plotFFTScaleX * (float)fftBufSize/2.f, 0.f );
	glEnd();
	glColor3ub( 200, 200, 50 );
	glBegin( GL_LINE_STRIP );
	for( i=1; i<fftBufSize/2-1; i++ ) {
		glVertex2f( Band_plotFFTScaleX * (float)i, Band_plotFFTScaleY * cumPowerSpectrumLog[i] );
	}
	glEnd();
	zprofEnd();
}
コード例 #14
0
ファイル: _band.cpp プロジェクト: zsimpson/plug_public
void cheReactionUpdate() {
	framesSinceLastReset++;

	int i;

	if( Band_signalOmega != oldOmega ) {
		cheReactionReset();
	}

	avgBuf[avgBufCount++] = (float)outputHits;
	if( avgBufCount == avgBufSize ) {
		float sum = 0.f;
		for( i=0; i<avgBufCount; i++ ) {
			sum += avgBuf[i];
		}
		fftBuf[fftBufCount] = sum / (float)avgBufCount;
		fftBufCount++;
		avgBufCount = 0;
		if( fftBufCount == fftBufSize ) {
			FFT fft( fftBuf, fftBufSize );
			fft.fft();
			float *p = fft.computePowerSpectrum();
			for( i=0; i<fftBufCount/2-1; i++ ) {
				cumPowerSpectrum[i] += p[i];
				cumPowerSpectrumLog[i] = logf( 1.f + cumPowerSpectrum[i] );
			}
			fftBufCount = 0;
			cumPowerSpectrumCount++;
			FILE *file = fopen( ZTmpStr("/transfer/fft/fft-diff-%d.txt",cumPowerSpectrumCount), "wt" );
			for( i=1; i<100; i++ ) {
				fprintf( file, "%f\n", cumPowerSpectrum[i] / (float)cumPowerSpectrumCount );
			}
			fclose( file );
		}
	}

	if( !(simulationFrameNumber % 100 ) ) {
		spatialHistogramCount++;
		for( int x=0; x<DIMX; x++ ) {
			for( int y=0; y<DIMY; y++ ) {
				Part *p = partAt( IVec2(x,y) );
				if( p && p->type == TYPE_CHEYP ) {
					spatialHistogram[x]++;
				}
			}
		}
	}

	outputHistory.setAvgWindow( Band_plotWindowRadius );
	outputHistory.add( (float)outputHits );

	// COMPUTE input signal
	signal = Band_signal;
	if( Band_useSinSignal ) {
		signal = (float)( Band_signalTop * 0.5*( 1.0+sin( Band_signalOmega * (double)simulationFrameNumber ) ) );
	}
	inputHistory.add( signal );

	// SETUP for next computation
	outputHits = 0;
}
コード例 #15
0
int TraceProcessorX86InterruptLinux::processInstruction(History<string>& strs)
{
  if (strs.size() < 2)
  {
    return (-1);
  }

  if (!isInterested(strs.at(0)))
  {
    return (-1);
  }

  const string& prevS = strs.at(1);

  size_t t = prevS.find("mov");
  if (t == string::npos)
  {
    return(-1);
  }

  //now that we found mov, lets find the $
  size_t t2 = prevS.find('$', t);

  //now that we found the $, we need to find the comma
  size_t t3 = prevS.find(',',t2);

  //now we should just make sure that the next thing is eax
  size_t t4 = prevS.find("%eax", t3);
  //make sure all characters from t3 to t4 are whitespaces
  for (size_t i = t3+1; i < t4; i++)
  {
    if (!isspace(prevS[i]))
    {
      return (-1);
    }
  }

  //if we are here that means everything checked out so lets get
  // the syscall number
  uint32_t syscallNum = 0;
  if(myHexStrToul(syscallNum, prevS.substr(t2+1,t3-t2-1)) != 0)
  {
    return (-1);
  }
  /*
  t4 = str.find("$0x80");

  outs = str.substr(0, t4);
  outs += "SYSCALL:";
  outs += sysCallTable[syscallNum];
  outs += "{";
  outs += str.substr(t4, 5);
  outs += "}";
  outs += str.substr(t4+5);
  */

  if (syscallNum >= SYSCALLTABLE_LINUX_2_6_LEN)
  {
    return (-1);
  }

  curSyscallName = sysCallTable[syscallNum];

  return (0);
}