Example #1
0
File: Net.cpp Project: Lang4/server
	Client * getClient(const char *ip,unsigned short port)
	{
		std::stringstream ss;
		ss << ip << ":" << port;
		CLIENTS_ITER iter = clients.find(ss.str());
		if (iter != clients.end())
		{
			return iter->second;
		}
		else
		{
			Client * client = NULL;
			if (GetEvents()->doNewClient)
			{
				client = (*(GetEvents()->doNewClient))(serverClientPool,ip,port);
			}
			else 
				client = new LClient(ip,port);
			LClient *l = (LClient*) client;
			serverClientPool->put(l);
			clients[ss.str()] = client;
			return client;
		}
		return NULL;
	}
Example #2
0
File: Net.cpp Project: Lang4/server
	bool msgParse(const void* cmd, const unsigned int len)
	{
		if (GetEvents()->doParseCmd)
		{
			(*(GetEvents()->doParseCmd))(this,(void*)cmd,len);
		}
		else
			theAllObj.get(remote::CONNECTION)->parse(this,(void*)cmd,len);
		return true;
	}
Example #3
0
File: Net.cpp Project: Lang4/server
	void addToContainer ()
	{
		for (unsigned int index = 0; index < cmds.size();++index)
		{
			sendCmd(cmds[index].c_str(),cmds[index].size());
		}
		cmds.clear();
		if (GetEvents()->doReconnect)
		{
			(*(GetEvents()->doReconnect))(this);
		}
	}
Example #4
0
void Game_Map::GetEventsXY(std::vector<Game_Event*>& events, int x, int y) {
	for (Game_Event& ev : GetEvents()) {
		if (ev.IsInPosition(x, y) && ev.GetActive()) {
			events.push_back(&ev);
		}
	}
}
bool CRecordPlayerDlg::Save(LPCTSTR Path)
{
	CMidiRecord	Record;
	CMidiRecord::CPartInfoArray	PartInfo;
	GetEvents(Record, PartInfo);
	return(Record.Write(Path, m_FileHdr, PartInfo));
}
Example #6
0
Double_t KVINDRADBRun::GetTotalCrossSection(Double_t Q_apres_cible,
                                            Double_t Coul_par_top) const
{
   //Calculate total cross-section (in millibarn) measured for this run from the calculated cross-section per event
   //(see GetEventCrossSection()) and the total number of measured events
   return GetEventCrossSection(Q_apres_cible, Coul_par_top) * GetEvents();
}
bool CRecordPlayerDlg::Export(LPCTSTR Path)
{
	CMidiRecord	Record;
	CMidiRecord::CPartInfoArray	PartInfo;
	GetEvents(Record, PartInfo);
	const COptionsInfo&	opts = theApp.GetMain()->GetOptions();
	return(Record.ExportMidiFile(Path, PartInfo, m_FileHdr.Tempo, 
		opts.m_Record.MidiFilePPQ, m_FileHdr.PerfFreq, opts.m_Record.FixDupNotes != 0));
}
Example #8
0
void IO::OutputScheduler::Run() {
  try {
    _stopRequested = false;
    while (!_stopRequested) {
      int events_number = GetEvents();
      for (auto index = 0; index < events_number; ++index) {
        volatile std::lock_guard<std::mutex> schedule_lock(_scheduling_mutex);
        Log::i("got " + std::to_string(events_number) + " events (writing)");
        if (is_error(_events[index].events)) {
          log_error(_efd);
          remove_socket(_events[index].data.fd);
        } else {
          std::size_t err_pos = static_cast<std::size_t>(-1);
          std::size_t scheduled_item_pos = err_pos;
          for (decltype(scheduled_item_pos) index2 = 0;
               index2 < _schedule.size(); ++index2) {
            if (_schedule[index2].sock->get_fd() == _events[index].data.fd) {
              scheduled_item_pos = index2;
            }
          }

          if (scheduled_item_pos != err_pos) {
            if (_schedule[scheduled_item_pos].data.size() == 0)
              remove_socket(_schedule[scheduled_item_pos].sock->get_fd());

            auto written = static_cast<std::size_t>(
                _schedule[scheduled_item_pos].sock->Write(
                    _schedule[scheduled_item_pos].data));
            if (written < _schedule[scheduled_item_pos].data.size()) {
              auto oldSize = _schedule[scheduled_item_pos].data.size();
              Log::i("on fd = " + std::to_string(_events[index].data.fd) +
                     ", wrote " + std::to_string(written) + " remaining = " +
                     std::to_string(_schedule[scheduled_item_pos].data.size() -
                                    written));
              std::vector<decltype(
                  _schedule[scheduled_item_pos].data)::value_type>(
                  _schedule[scheduled_item_pos].data.begin() + written,
                  _schedule[scheduled_item_pos].data.end())
                  .swap(_schedule[scheduled_item_pos].data);
              auto newSize = _schedule[scheduled_item_pos].data.size();
              assert(oldSize - written == newSize);
            } else {
              _schedule[scheduled_item_pos].data = {};
            }
          }
        }
      }
    }
  } catch (std::exception& ex) {
    throw;
  }
}
Example #9
0
bool Game_Map::MakeWay(int x, int y, int d, const Game_Character& self, bool force_through) {
	int new_x = RoundX(x + (d == Game_Character::Right ? 1 : d == Game_Character::Left ? -1 : 0));
	int new_y = RoundY(y + (d == Game_Character::Down ? 1 : d == Game_Character::Up ? -1 : 0));

	if (!Game_Map::IsValid(new_x, new_y))
		return false;

	if (self.GetThrough() || force_through) return true;

	// A character can move to a position with an impassable tile by
	// standing on top of an event below it. These flags track whether
	// we stepped off an event and therefore don't need to check the
	// passability of the tile layer below.
	bool stepped_off_event = false;
	bool stepped_onto_event = false;

	for (Game_Event& other : GetEvents()) {
		CollisionResult result = TestCollisionDuringMove(x, y, new_x, new_y, d, self, other);
		if (result == Collision) {
			// Try updating the offending event to give it a chance to move out of the
			// way and recheck.
			other.UpdateParallel();
			if (TestCollisionDuringMove(x, y, new_x, new_y, d, self, other) == Collision) {
				return false;
			}
		}
		else if (result == CanStepOffCurrentTile) {
			stepped_off_event = true;
		} else if (result == CanStepOntoNewTile) {
			stepped_onto_event = true;
		}
	}

	if (vehicles[0]->IsInPosition(new_x, new_y) || vehicles[1]->IsInPosition(new_x, new_y)) {
		return false;
	}

	if (Main_Data::game_player->IsInPosition(new_x, new_y)
			&& !Main_Data::game_player->GetThrough()
			&& self.GetLayer() == RPG::EventPage::Layers_same) {
		// Update the Player to see if they'll move and recheck.
		Main_Data::game_player->Update(!first_frame);
		if (Main_Data::game_player->IsInPosition(new_x, new_y)) {
			return false;
		}
	}

	return
		(stepped_off_event || IsPassableTile(DirToMask(d), x + y * GetWidth()))
		&& (stepped_onto_event || IsPassableTile(DirToMask(Game_Character::ReverseDir(d)), new_x + new_y * GetWidth()));
}
Example #10
0
int __fastcall TfrmChoseItem::SelectItem(u32 choose_ID, LPCSTR& dest, int sel_cnt, LPCSTR init_name, TOnChooseFillItems item_fill, void* fill_param, TOnChooseSelectItem item_select, ChooseItemVec* items, u32 mask)
{
	VERIFY(!form);
	form 							= xr_new<TfrmChoseItem>((TComponent*)0);
    form->m_Flags.assign			(mask);
    form->m_Flags.set				(cfMultiSelect,sel_cnt>1);
    form->iMultiSelLimit 			= sel_cnt;

	// init
//.	if (init_name&&init_name[0]) 
    	m_LastSelection 			= init_name;
    form->tvItems->Selected 		= 0;

    // fill items
    if (items){
    	VERIFY2(item_fill.empty(),"ChooseForm: Duplicate source.");
    	form->m_Items				= *items;
        form->E.Set					("Select Item",0,item_select,0,0,0);
    }else if (!item_fill.empty()){
    	// custom
        form->E.Set					("Select Item",item_fill,item_select,0,0,0);
    }else{
    	SChooseEvents* e			= GetEvents(choose_ID); VERIFY2(e,"Can't find choose event.");
    	form->E						= *e;
    }
	// set & fill
    form->Caption					= form->E.caption.c_str();

    if (!form->E.on_fill.empty())	
    	form->E.on_fill(form->m_Items,fill_param);
    
    form->FillItems					(choose_ID);
    
//.	form->paItemsCount->Caption		= AnsiString(" Items in list: ")+AnsiString(form->tvItems->Items->Count);

	// show
    bool bRes 						= (form->ShowModal()==mrOk);
    dest							= 0;
    if (bRes){
		int item_cnt				= _GetItemCount(select_item.c_str(),',');
    	dest 						= (select_item==NONE_CAPTION)?0:select_item.c_str();
	    m_LastSelection				= select_item;
        return 						item_cnt?item_cnt:1;
    }
    return 0;
}
Example #11
0
bool Game_Map::CanDisembarkShip(Game_Player& player, int x, int y) {
	if (!Game_Map::IsValid(x, y)) {
		return false;
	}

	for (auto& ev: GetEvents()) {
		if (ev.IsInPosition(x, y)
			&& ev.GetLayer() == RPG::EventPage::Layers_same
			&& ev.IsActive()) {
			return false;
		}
	}

	int bit = GetPassableMask(x, y, player.GetX(), player.GetY());

	return IsPassableTile(nullptr, bit, x, y);
}
C3DFileAdapter::OutputTables
C3DFileAdapter::extendRead(const std::string& fileName) const {
    auto reader = btk::AcquisitionFileReader::New();
    reader->SetFilename(fileName);
    reader->Update();
    auto acquisition = reader->GetOutput();

    EventTable event_table{};
    auto events = acquisition->GetEvents();
    for (auto it = events->Begin();
        it != events->End();
        ++it) {
        auto et = *it;
        event_table.push_back({ et->GetLabel(),
            et->GetTime(),
            et->GetFrame(),
            et->GetDescription() });
    }

    OutputTables tables{};

    auto marker_pts = btk::PointCollection::New();

    for(auto it = acquisition->BeginPoint();
        it != acquisition->EndPoint();
        ++it) {
        auto pt = *it;
        if(pt->GetType() == btk::Point::Marker)
               marker_pts->InsertItem(pt);
    }

    if(marker_pts->GetItemNumber() != 0) {

        int marker_nrow = marker_pts->GetFrontItem()->GetFrameNumber();
        int marker_ncol = marker_pts->GetItemNumber();

        std::vector<double> marker_times(marker_nrow);
        SimTK::Matrix_<SimTK::Vec3> marker_matrix(marker_nrow, marker_ncol);

        std::vector<std::string> marker_labels{};
        for (auto it = marker_pts->Begin(); it != marker_pts->End(); ++it) {
            marker_labels.push_back(SimTK::Value<std::string>((*it)->GetLabel()));
        }

        double time_step{1.0 / acquisition->GetPointFrequency()};
        for(int f = 0; f < marker_nrow; ++f) {
            SimTK::RowVector_<SimTK::Vec3> row{ marker_pts->GetItemNumber(), 
                                                SimTK::Vec3(SimTK::NaN) };
            int m{0};
            for(auto it = marker_pts->Begin();  it != marker_pts->End(); ++it) {
                auto pt = *it;
                // BTK reads empty values as zero, but sets a "residual" value
                // to -1 and it is how it knows to export these values as 
                // blank, instead of 0,  when exporting to .trc
                // See: BTKCore/Code/IO/btkTRCFileIO.cpp#L359-L360
                // Read in value if it is not zero or residual is not -1
                if (!pt->GetValues().row(f).isZero() ||    //not precisely zero
                    (pt->GetResiduals().coeff(f) != -1) ) {//residual is not -1
                    row[m] = SimTK::Vec3{ pt->GetValues().coeff(f, 0),
                                          pt->GetValues().coeff(f, 1),
                                          pt->GetValues().coeff(f, 2) };
                }
                ++m;
            }

            marker_matrix.updRow(f) = row;
            marker_times[f] = 0 + f * time_step; //TODO: 0 should be start_time
        }

        // Create the data
        auto marker_table = 
            std::make_shared<TimeSeriesTableVec3>(marker_times, 
                                                  marker_matrix, 
                                                  marker_labels);

        marker_table->
            updTableMetaData().
            setValueForKey("DataRate",
                std::to_string(acquisition->GetPointFrequency()));

        marker_table->
            updTableMetaData().
            setValueForKey("Units",
                acquisition->GetPointUnit());

        marker_table->updTableMetaData().setValueForKey("events", event_table);

        tables.emplace(_markers, marker_table);
    }

    // This is probably the right way to get the raw forces data from force 
    // platforms. Extract the collection of force platforms.
    auto force_platforms_extractor = btk::ForcePlatformsExtractor::New();
    force_platforms_extractor->SetInput(acquisition);
    auto force_platform_collection = force_platforms_extractor->GetOutput();
    force_platforms_extractor->Update();

    std::vector<SimTK::Matrix_<double>> fpCalMatrices{};
    std::vector<SimTK::Matrix_<double>> fpCorners{};
    std::vector<SimTK::Matrix_<double>> fpOrigins{};
    std::vector<unsigned>               fpTypes{};
    auto    fp_force_pts = btk::PointCollection::New();
    auto   fp_moment_pts = btk::PointCollection::New();
    auto fp_position_pts = btk::PointCollection::New();
    for(auto platform = force_platform_collection->Begin(); 
        platform != force_platform_collection->End(); 
        ++platform) {
        const auto& calMatrix = (*platform)->GetCalMatrix();
        const auto& corners   = (*platform)->GetCorners();
        const auto& origins   = (*platform)->GetOrigin();
        fpCalMatrices.push_back(convertToSimtkMatrix(calMatrix));
        fpCorners.push_back(convertToSimtkMatrix(corners));
        fpOrigins.push_back(convertToSimtkMatrix(origins));
        fpTypes.push_back(static_cast<unsigned>((*platform)->GetType()));

        // Get ground reaction wrenches for the force platform.
        auto ground_reaction_wrench_filter = 
            btk::GroundReactionWrenchFilter::New();
        ground_reaction_wrench_filter->setLocation(
            btk::GroundReactionWrenchFilter::Location(getLocationForForceExpression()));
        ground_reaction_wrench_filter->SetInput(*platform);
        auto wrench_collection = ground_reaction_wrench_filter->GetOutput();
        ground_reaction_wrench_filter->Update();
        
        for(auto wrench = wrench_collection->Begin();
            wrench != wrench_collection->End(); 
            ++wrench) {
            // Forces time series.
            fp_force_pts->InsertItem((*wrench)->GetForce());
            // Moment time series.
            fp_moment_pts->InsertItem((*wrench)->GetMoment());
            // Position time series.
            fp_position_pts->InsertItem((*wrench)->GetPosition());
        }
    }

    if(fp_force_pts->GetItemNumber() != 0) {

        std::vector<std::string> labels{};
        ValueArray<std::string> units{};
        for(int fp = 1; fp <= fp_force_pts->GetItemNumber(); ++fp) {
            auto fp_str = std::to_string(fp);

            labels.push_back(SimTK::Value<std::string>("f" + fp_str));
            auto force_unit = acquisition->GetPointUnits().
                at(_unit_index.at("force"));
            units.upd().push_back(SimTK::Value<std::string>(force_unit));

            labels.push_back(SimTK::Value<std::string>("p" + fp_str));
            auto position_unit = acquisition->GetPointUnits().
                at(_unit_index.at("marker"));
            units.upd().push_back(SimTK::Value<std::string>(position_unit));

            labels.push_back(SimTK::Value<std::string>("m" + fp_str));
            auto moment_unit = acquisition->GetPointUnits().
                at(_unit_index.at("moment"));
            units.upd().push_back(SimTK::Value<std::string>(moment_unit));
        }

        const int nf = fp_force_pts->GetFrontItem()->GetFrameNumber();
        
        std::vector<double> force_times(nf);
        SimTK::Matrix_<SimTK::Vec3> force_matrix(nf, (int)labels.size());

        double time_step{1.0 / acquisition->GetAnalogFrequency()};

        for(int f = 0; f < nf;  ++f) {
            SimTK::RowVector_<SimTK::Vec3> 
                row{fp_force_pts->GetItemNumber() * 3};
            int col{0};
            for(auto fit = fp_force_pts->Begin(),
                mit =     fp_moment_pts->Begin(),
                pit =   fp_position_pts->Begin();
                fit != fp_force_pts->End();
                ++fit, 
                ++mit,
                ++pit) {
                row[col] = SimTK::Vec3{(*fit)->GetValues().coeff(f, 0),
                                       (*fit)->GetValues().coeff(f, 1),
                                       (*fit)->GetValues().coeff(f, 2)};
                ++col;
                row[col] = SimTK::Vec3{(*pit)->GetValues().coeff(f, 0),
                                       (*pit)->GetValues().coeff(f, 1),
                                       (*pit)->GetValues().coeff(f, 2)};
                ++col;
                row[col] = SimTK::Vec3{(*mit)->GetValues().coeff(f, 0),
                                       (*mit)->GetValues().coeff(f, 1),
                                       (*mit)->GetValues().coeff(f, 2)};
                ++col;
            }
            force_matrix.updRow(f) = row;
            force_times[f] = 0 + f * time_step; //TODO: 0 should be start_time
        }

        auto&  force_table = 
            *(new TimeSeriesTableVec3(force_times, force_matrix, labels));

        TimeSeriesTableVec3::DependentsMetaData force_dep_metadata
            = force_table.getDependentsMetaData();

        // add units to the dependent meta data
        force_dep_metadata.setValueArrayForKey("units", units);
        force_table.setDependentsMetaData(force_dep_metadata);

        force_table.
            updTableMetaData().
            setValueForKey("CalibrationMatrices", std::move(fpCalMatrices));

        force_table.
            updTableMetaData().
            setValueForKey("Corners", std::move(fpCorners));

        force_table.
            updTableMetaData().
            setValueForKey("Origins", std::move(fpOrigins));

        force_table.
            updTableMetaData().
            setValueForKey("Types", std::move(fpTypes));

        force_table.
            updTableMetaData().
            setValueForKey("DataRate",
                std::to_string(acquisition->GetAnalogFrequency()));

        tables.emplace(_forces,
            std::shared_ptr<TimeSeriesTableVec3>(&force_table));

        force_table.updTableMetaData().setValueForKey("events", event_table);
    }

    return tables;
}
Example #13
0
C3DFileAdapter::OutputTables
C3DFileAdapter::extendRead(const std::string& fileName) const {
    auto reader = btk::AcquisitionFileReader::New();
    reader->SetFilename(fileName);
    reader->Update();
    auto acquisition = reader->GetOutput();

    OutputTables tables{};
    auto& marker_table = *(new TimeSeriesTableVec3{});
    auto&  force_table = *(new TimeSeriesTableVec3{});
    tables.emplace(_markers, 
                   std::shared_ptr<TimeSeriesTableVec3>(&marker_table));
    tables.emplace(_forces, 
                   std::shared_ptr<TimeSeriesTableVec3>(&force_table));

    auto marker_pts = btk::PointCollection::New();

    for(auto it = acquisition->BeginPoint();
        it != acquisition->EndPoint();
        ++it) {
        auto pt = *it;
        if(pt->GetType() == btk::Point::Marker)
               marker_pts->InsertItem(pt);
    }

    if(marker_pts->GetItemNumber() != 0) {
        marker_table.
            updTableMetaData().
            setValueForKey("DataRate", 
                           std::to_string(acquisition->GetPointFrequency()));

        marker_table.
            updTableMetaData().
            setValueForKey("Units", 
                           acquisition->GetPointUnit());

        ValueArray<std::string> marker_labels{};
        for(auto it = marker_pts->Begin();
            it != marker_pts->End();
            ++it) {
            marker_labels.
            upd().
            push_back(SimTK::Value<std::string>((*it)->GetLabel()));
        }

        TimeSeriesTableVec3::DependentsMetaData marker_dep_metadata{};
        marker_dep_metadata.setValueArrayForKey("labels", marker_labels);
        marker_table.setDependentsMetaData(marker_dep_metadata);

        double time_step{1.0 / acquisition->GetPointFrequency()};
        for(int f = 0; 
            f < marker_pts->GetFrontItem()->GetFrameNumber();
            ++f) {
            SimTK::RowVector_<SimTK::Vec3> row{marker_pts->GetItemNumber()};
            int m{0};
            for(auto it = marker_pts->Begin();
                it != marker_pts->End();
                ++it) {
                auto pt = *it;
                row[m++] = SimTK::Vec3{pt->GetValues().coeff(f, 0),
                                       pt->GetValues().coeff(f, 1),
                                       pt->GetValues().coeff(f, 2)};
            }
            marker_table.appendRow(0 + f * time_step, row);
        }
    }

    // This is probably the right way to get the raw forces data from force 
    // platforms. Extract the collection of force platforms.
    auto force_platforms_extractor = btk::ForcePlatformsExtractor::New();
    force_platforms_extractor->SetInput(acquisition);
    auto force_platform_collection = force_platforms_extractor->GetOutput();
    force_platforms_extractor->Update();

    std::vector<SimTK::Matrix_<double>> fpCalMatrices{};
    std::vector<SimTK::Matrix_<double>> fpCorners{};
    std::vector<SimTK::Matrix_<double>> fpOrigins{};
    std::vector<unsigned>               fpTypes{};
    auto    fp_force_pts = btk::PointCollection::New();
    auto   fp_moment_pts = btk::PointCollection::New();
    auto fp_position_pts = btk::PointCollection::New();
    for(auto platform = force_platform_collection->Begin(); 
        platform != force_platform_collection->End(); 
        ++platform) {
        const auto& calMatrix = (*platform)->GetCalMatrix();
        const auto& corners   = (*platform)->GetCorners();
        const auto& origins   = (*platform)->GetOrigin();
        fpCalMatrices.push_back(convertToSimtkMatrix(calMatrix));
        fpCorners.push_back(convertToSimtkMatrix(corners));
        fpOrigins.push_back(convertToSimtkMatrix(origins));
        fpTypes.push_back(static_cast<unsigned>((*platform)->GetType()));

        // Get ground reaction wrenches for the force platform.
        auto ground_reaction_wrench_filter = 
            btk::GroundReactionWrenchFilter::New();
        ground_reaction_wrench_filter->SetInput(*platform);
        auto wrench_collection = ground_reaction_wrench_filter->GetOutput();
        ground_reaction_wrench_filter->Update();
        
        for(auto wrench = wrench_collection->Begin();
            wrench != wrench_collection->End(); 
            ++wrench) {
            // Forces time series.
            fp_force_pts->InsertItem((*wrench)->GetForce());
            // Moment time series.
            fp_moment_pts->InsertItem((*wrench)->GetMoment());
            // Position time series.
            fp_position_pts->InsertItem((*wrench)->GetPosition());
        }
    }

    //shrik<btk::ForcePlatform::Origin> foo;

    if(fp_force_pts->GetItemNumber() != 0) {
        force_table.
            updTableMetaData().
            setValueForKey("CalibrationMatrices", std::move(fpCalMatrices));

        force_table.
            updTableMetaData().
            setValueForKey("Corners",             std::move(fpCorners));

        force_table.
            updTableMetaData().
            setValueForKey("Origins",             std::move(fpOrigins));

        force_table.
            updTableMetaData().
            setValueForKey("Types",               std::move(fpTypes));

        force_table.
            updTableMetaData().
            setValueForKey("DataRate", 
                           std::to_string(acquisition->GetAnalogFrequency()));

        ValueArray<std::string> labels{};
        ValueArray<std::string> units{};
        for(int fp = 1; fp <= fp_force_pts->GetItemNumber(); ++fp) {
            auto fp_str = std::to_string(fp);

            labels.upd().push_back(SimTK::Value<std::string>("f" + fp_str));
            auto force_unit = acquisition->GetPointUnits().
                at(_unit_index.at("force"));
            units.upd().push_back(SimTK::Value<std::string>(force_unit));

            labels.upd().push_back(SimTK::Value<std::string>("m" + fp_str));
            auto moment_unit = acquisition->GetPointUnits().
                at(_unit_index.at("moment"));
            units.upd().push_back(SimTK::Value<std::string>(moment_unit));

            labels.upd().push_back(SimTK::Value<std::string>("p" + fp_str));
            auto position_unit = acquisition->GetPointUnits().
                at(_unit_index.at("marker"));
            units.upd().push_back(SimTK::Value<std::string>(position_unit));
        }
        TimeSeriesTableVec3::DependentsMetaData force_dep_metadata{};
        force_dep_metadata.setValueArrayForKey("labels", labels);
        force_dep_metadata.setValueArrayForKey("units", units);
        force_table.setDependentsMetaData(force_dep_metadata);

        double time_step{1.0 / acquisition->GetAnalogFrequency()};
        for(int f = 0;
            f < fp_force_pts->GetFrontItem()->GetFrameNumber();
            ++f) {
            SimTK::RowVector_<SimTK::Vec3>
                row{fp_force_pts->GetItemNumber() * 3};
            int col{0};
            for(auto fit = fp_force_pts->Begin(),
                mit =     fp_moment_pts->Begin(),
                pit =   fp_position_pts->Begin();
                fit != fp_force_pts->End();
                ++fit, 
                ++mit,
                ++pit) {
                row[col] = SimTK::Vec3{(*fit)->GetValues().coeff(f, 0),
                                       (*fit)->GetValues().coeff(f, 1),
                                       (*fit)->GetValues().coeff(f, 2)};
                ++col;
                row[col] = SimTK::Vec3{(*mit)->GetValues().coeff(f, 0),
                                       (*mit)->GetValues().coeff(f, 1),
                                       (*mit)->GetValues().coeff(f, 2)};
                ++col;
                row[col] = SimTK::Vec3{(*pit)->GetValues().coeff(f, 0),
                                       (*pit)->GetValues().coeff(f, 1),
                                       (*pit)->GetValues().coeff(f, 2)};
                ++col;
            }
            force_table.appendRow(0 + f * time_step, row);
        }
    }

    EventTable event_table{};
    auto events = acquisition->GetEvents();
    for(auto it = events->Begin();
        it != events->End();
        ++it) {
        auto et = *it;
        event_table.push_back({et->GetLabel(),
                               et->GetTime(),
                               et->GetFrame(),
                               et->GetDescription()});
    }
       marker_table.updTableMetaData().setValueForKey("events", event_table);
        force_table.updTableMetaData().setValueForKey("events", event_table);

    return tables;
}
int ReplicationTransfer::ReadDataFromDC(vector<string> *buffer) {
    return GetEvents(buffer);
}
Example #15
0
bool Game_Map::MakeWay(const Game_Character& self, int x, int y) {
	// Moving to same tile (used for jumps) always succeeds
	if (x == self.GetX() && y == self.GetY()) {
		return true;
	}
	if (!self.IsJumping() && x != self.GetX() && y != self.GetY()) {
		// Handle diagonal stepping.
		// Must be able to step on at least one of the 2 adjacent tiles and also the target tile.
		// Verified behavior: Always checks vertical first, only checks horizontal if vertical fails.
		bool vertical_ok = MakeWay(self, self.GetX(), y);
		if (!vertical_ok) {
			bool horizontal_ok = MakeWay(self, x, self.GetY());
			if (!horizontal_ok) {
				return false;
			}
		}
	}

	// Infer directions before we do any rounding.
	const auto bit_from = GetPassableMask(self.GetX(), self.GetY(), x, y);
	const auto bit_to = GetPassableMask(x, y, self.GetX(), self.GetY());

	// Now round for looping maps.
	x = Game_Map::RoundX(x);
	y = Game_Map::RoundY(y);

	// Note, even for diagonal, if the tile is invalid we still check vertical/horizontal first!
	if (!Game_Map::IsValid(x, y)) {
		return false;
	}

	if (self.GetThrough()) {
		return true;
	}

	const auto vehicle_type = static_cast<Game_Vehicle::Type>(self.GetVehicleType());

	bool self_conflict = false;
	if (!self.IsJumping()) {
		// Check for self conflict.
		// If this event has a tile graphic and the tile itself has passage blocked in the direction
		// we want to move, flag it as "self conflicting" for use later.
		if (self.GetLayer() == RPG::EventPage::Layers_below && self.GetTileId() != 0) {
			int tile_id = self.GetTileId();
			if ((passages_up[tile_id] & bit_from) == 0) {
				self_conflict = true;
			}
		}

		if (vehicle_type == Game_Vehicle::None) {
			// Check that we are allowed to step off of the current tile.
			// Note: Vehicles can always step off a tile.
			if (!IsPassableTile(&self, bit_from, self.GetX(), self.GetY())) {
				return false;
			}
		}
	}

	if (vehicle_type != Game_Vehicle::Airship) {
		// Check for collision with events on the target tile.
		for (auto& other: GetEvents()) {
			if (MakeWayCollideEvent(x, y, self, other, self_conflict)) {
				return false;
			}
		}
		auto& player = Main_Data::game_player;
		if (player->GetVehicleType() == Game_Vehicle::None) {
			if (MakeWayCollideEvent(x, y, self, *Main_Data::game_player, self_conflict)) {
				return false;
			}
		}
		for (auto vid: { Game_Vehicle::Boat, Game_Vehicle::Ship}) {
			auto& other = vehicles[vid - 1];
			if (other->IsInCurrentMap()) {
				if (MakeWayCollideEvent(x, y, self, *other, self_conflict)) {
					return false;
				}
			}
		}
		auto& airship = vehicles[Game_Vehicle::Airship - 1];
		if (airship->IsInCurrentMap() && self.GetType() != Game_Character::Player) {
			if (MakeWayCollideEvent(x, y, self, *airship, self_conflict)) {
				return false;
			}
		}
	}

	int bit = bit_to;
	if (self.IsJumping()) {
		bit = Passable::Down | Passable::Up | Passable::Left | Passable::Right;
	}

	return IsPassableTile(&self, bit, x, y);
}
Example #16
0
void Layout::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
    SetBackgroundColor(element.GetIntAttribute( "r" ), element.GetIntAttribute( "v" ), element.GetIntAttribute( "b" ));
    SetWindowDefaultTitle( element.GetStringAttribute("title", "(No title)", "titre") );
    oglFOV = element.GetDoubleAttribute("oglFOV");
    oglZNear = element.GetDoubleAttribute("oglZNear");
    oglZFar = element.GetDoubleAttribute("oglZFar");
    standardSortMethod = element.GetBoolAttribute( "standardSortMethod" );
    stopSoundsOnStartup = element.GetBoolAttribute( "stopSoundsOnStartup" );
    disableInputWhenNotFocused = element.GetBoolAttribute( "disableInputWhenNotFocused" );

    #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
    associatedSettings.UnserializeFrom(element.GetChild("uiSettings", 0, "UISettings"));
    #endif

    #if defined(GD_IDE_ONLY)
    gd::ObjectGroup::UnserializeFrom(objectGroups, element.GetChild( "objectsGroups", 0, "GroupesObjets" ));
    gd::EventsListSerialization::UnserializeEventsFrom(project, GetEvents(), element.GetChild("events", 0, "Events"));
    #endif

    UnserializeObjectsFrom(project, element.GetChild("objects", 0, "Objets"));
    initialInstances.UnserializeFrom(element.GetChild("instances", 0, "Positions"));
    variables.UnserializeFrom(element.GetChild("variables", 0, "Variables"));

    initialLayers.clear();
    SerializerElement & layersElement = element.GetChild("layers", 0, "Layers");
    layersElement.ConsiderAsArrayOf("layer", "Layer");
    for (std::size_t i = 0; i < layersElement.GetChildrenCount(); ++i)
    {
        gd::Layer layer;

        layer.UnserializeFrom(layersElement.GetChild(i));
        initialLayers.push_back(layer);
    }

    //Compatibility with GD <= 4
    gd::String deprecatedTag1 = "automatismsSharedData";
    gd::String deprecatedTag2 = "automatismSharedData";
    if (!element.HasChild(deprecatedTag1))
    {
        deprecatedTag1 = "AutomatismsSharedDatas";
        deprecatedTag2 = "AutomatismSharedDatas";
    }
    //end of compatibility code

    SerializerElement & behaviorsDataElement = element.GetChild("behaviorsSharedData", 0, deprecatedTag1);
    behaviorsDataElement.ConsiderAsArrayOf("behaviorSharedData", deprecatedTag2);
    for (unsigned int i = 0; i < behaviorsDataElement.GetChildrenCount(); ++i)
    {
        SerializerElement & behaviorDataElement = behaviorsDataElement.GetChild(i);
        gd::String type = behaviorDataElement.GetStringAttribute("type", "", "Type")
            .FindAndReplace("Automatism", "Behavior"); //Compatibility with GD <= 4

        std::shared_ptr<gd::BehaviorsSharedData> sharedData = project.CreateBehaviorSharedDatas(type);
        if ( sharedData != std::shared_ptr<gd::BehaviorsSharedData>() )
        {
            sharedData->SetName( behaviorDataElement.GetStringAttribute("name", "", "Name") );
            sharedData->UnserializeFrom(behaviorDataElement);

            behaviorsInitialSharedDatas[sharedData->GetName()] = sharedData;
        }

    }
}