Пример #1
0
//--------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(0, 0, 0);
    
    moveBall();
    ofPoint* target = reach(segments[0], ball->x, ball->y);
    for(int i=1; i<numSegments; i++){
        Segment* segment = segments[i];
        target = reach(segment, target->x, target->y);
    }
    
    for(int i=numSegments - 1; i>0; i--){
        Segment* segmentA = segments[i];
        Segment* segmentB = segments[i - 1];
        position(segmentB, segmentA);
    }
    
    checkHit();
    ofNoFill();
    ofSetColor(0, 255, 0);
    for(int i=0; i<numSegments; i++){
        segments[i]->update();
    }
    
    ofFill();
    ball->update();
}
Пример #2
0
bool genexe(compile_t* c, ast_t* program)
{
  // The first package is the main package. It has to have a Main actor.
  const char* main_actor = stringtab("Main");
  const char* env_class = stringtab("Env");

  ast_t* package = ast_child(program);
  ast_t* main_def = ast_get(package, main_actor, NULL);

  if(main_def == NULL)
  {
    errorf(NULL, "no Main actor found in package '%s'", c->filename);
    return false;
  }

  // Generate the Main actor and the Env class.
  ast_t* main_ast = type_builtin(c->opt, main_def, main_actor);
  ast_t* env_ast = type_builtin(c->opt, main_def, env_class);

  genprim_reachable_init(c, program);
  reach(c->reachable, main_ast, stringtab("create"), NULL);
  reach(c->reachable, env_ast, stringtab("_create"), NULL);
  paint(c->reachable);

  gentype_t main_g;
  gentype_t env_g;

  bool ok = gentype(c, main_ast, &main_g) && gentype(c, env_ast, &env_g);

  if(ok)
    gen_main(c, &main_g, &env_g);

  ast_free_unattached(main_ast);
  ast_free_unattached(env_ast);

  if(!ok)
    return false;

  if(!genopt(c))
    return false;

  const char* file_o = genobj(c);

  if(file_o == NULL)
    return false;

  if(c->opt->limit < PASS_ALL)
    return true;

  if(!link_exe(c, program, file_o))
    return false;

#ifdef PLATFORM_IS_WINDOWS
  _unlink(file_o);
#else
  unlink(file_o);
#endif

  return true;
}
Пример #3
0
//--------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(0, 0, 0);
    ofNoFill();
    ofPoint* target = reach(segment0, mouseX, mouseY);
    reach(segment1, target->x, target->y);
    segment0->x = segment1->getPin()->x;
    segment0->y = segment1->getPin()->y;
    
    segment0->update();
    segment1->update();
}
Пример #4
0
void genprim_reachable_init(compile_t* c, ast_t* program)
{
  // Look for primitives in all packages that have _init or _final methods.
  // Mark them as reachable.
  ast_t* package = ast_child(program);

  while(package != NULL)
  {
    ast_t* module = ast_child(package);

    while(module != NULL)
    {
      ast_t* entity = ast_child(module);

      while(entity != NULL)
      {
        if(ast_id(entity) == TK_PRIMITIVE)
        {
          AST_GET_CHILDREN(entity, id, typeparams);

          if(ast_id(typeparams) == TK_NONE)
          {
            ast_t* type = type_builtin(c->opt, entity, ast_name(id));
            ast_t* finit = ast_get(entity, c->str__init, NULL);
            ast_t* ffinal = ast_get(entity, c->str__final, NULL);

            if(finit != NULL)
            {
              reach(c->reach, type, c->str__init, NULL, c->opt);
              ast_free_unattached(finit);
            }

            if(ffinal != NULL)
            {
              reach(c->reach, type, c->str__final, NULL, c->opt);
              ast_free_unattached(ffinal);
            }

            ast_free_unattached(type);
          }
        }

        entity = ast_sibling(entity);
      }

      module = ast_sibling(module);
    }

    package = ast_sibling(package);
  }
}
Пример #5
0
int reach(int X, int Y){
  if(X==0 && Y==0){
    return 1;
  }
  else if(X==0 && Y!=0){
    return (reach(X,Y-1));
  }
  else if(X!=0 && Y==0){
    return (reach(X-1,Y));
  }
  else{
    return (reach(X-1,Y) + reach(X,Y-1));
  }
}
Пример #6
0
bool codegen_gen_test(compile_t* c, ast_t* program, pass_opt_t* opt,
  pass_id last_pass)
{
  if(last_pass < PASS_REACH)
  {
    memset(c, 0, sizeof(compile_t));

    genned_strings_init(&c->strings, 64);
    ffi_decls_init(&c->ffi_decls, 64);

    if(!init_module(c, program, opt))
      return false;

    init_runtime(c);
    genprim_reachable_init(c, program);

    const char* main_actor = c->str_Main;
    const char* env_class = c->str_Env;

    ast_t* package = ast_child(program);
    ast_t* main_def = ast_get(package, main_actor, NULL);

    if(main_def == NULL)
      return false;

    ast_t* main_ast = type_builtin(opt, main_def, main_actor);
    ast_t* env_ast = type_builtin(opt, main_def, env_class);

    if(lookup(opt, main_ast, main_ast, c->str_create) == NULL)
      return false;

    reach(c->reach, main_ast, c->str_create, NULL, opt);
    reach(c->reach, env_ast, c->str__create, NULL, opt);
    reach_done(c->reach, c->opt);
  }

  if(opt->limit == PASS_REACH)
    return true;

  if(last_pass < PASS_PAINT)
    paint(&c->reach->types);

  if(opt->limit == PASS_PAINT)
    return true;

  if(!gentypes(c))
    return false;

  return true;
}
Пример #7
0
static bool reachable_methods(compile_t* c, ast_t* ast)
{
  ast_t* id = ast_child(ast);
  ast_t* type = type_builtin(c->opt, ast, ast_name(id));

  ast_t* def = (ast_t*)ast_data(type);
  ast_t* members = ast_childidx(def, 4);
  ast_t* member = ast_child(members);

  while(member != NULL)
  {
    switch(ast_id(member))
    {
      case TK_NEW:
      case TK_BE:
      case TK_FUN:
      {
        AST_GET_CHILDREN(member, cap, m_id, typeparams);

        // Mark all non-polymorphic methods as reachable.
        if(ast_id(typeparams) == TK_NONE)
          reach(c->reach, type, ast_name(m_id), NULL, c->opt);
        break;
      }

      default: {}
    }

    member = ast_sibling(member);
  }

  ast_free_unattached(type);
  return true;
}
Пример #8
0
void problem2(){
  int X,Y;
  printf("Enter the values of X and Y:");
  scanf("%d%d",&X,&Y);
  int ways = reach(X,Y);
  printf("\nThe number of ways of reaching X,Y from (0,0) is %d\n",ways);
}
Пример #9
0
void Controller::computeTorques(int _currentFrame) {
  mCurrentFrame = _currentFrame;
  mTorques.setZero();
  if (mState == "STAND") {
    stand();
  } else if (mState == "CROUCH") {
    crouch();
  } else if (mState == "JUMP") {
    jump();
  } else if (mState == "REACH") {
    reach();
  } else if (mState == "GRAB") {
    grab();
  } else if (mState == "RELEASE") {
    release();
  } else if (mState == "SWING") {
    swing();
  } else if (mState == "BENDABDOMEN") {
    bendAbdomen();
  } else {
    std::cout << "Illegal state: " << mState << std::endl;
  }

  // Just to make sure no illegal torque is used. Do not remove this.
  for (int i = 0; i < 6; i++) {
    mTorques[i] = 0.0;
  }
}
Пример #10
0
//Given a graph, return a vector of sets representing reachable vertices for each node
//The graph MUST be a directed acyclic graph for this method to work properly
std::vector< std::set<int> > get_reachability_dag(host_graph &g)
{
	if(g.directed == false)
	{
		std::cerr << "Error: The reachability function only supports directed graphs." << std::endl;
		exit(1);
	}

	//First, we need to obtain the reverse graph
	host_graph g_rev = reverse(g);

	//Collect vertices with indegree 0
	std::vector<int> roots;
	for(int i=0; i<g.n; i++)
	{
		if((g_rev.R[i+1]-g_rev.R[i]) == 0)
		{
			roots.push_back(i);
		}
	}

	//Find reachability for each root
	std::vector< std::set<int> > reach(g.n);
	for(auto i=roots.begin(),e=roots.end(); i!=e; ++i)
	{
		find_reach(g,*i,reach);
	}

	return reach;
}
struct ast* eval_instance_native_method(struct ast* m) {
	if (m != NULL){
    char* method_name;

    if (m->node_type == N_METHOD_CALL_1) {
      method_name = strdup(((struct method_call_node*)m)->method_name);
    };

		if (!strcmp(method_name, LENGTH)) {
      struct method_call_node* mc = (struct method_call_node*)m;
      return rlength(eval_ast(mc->left_ast));

    } else if (!strcmp(method_name, EACH_ITERATOR)) {
      struct method_call_node* mc = (struct method_call_node*)m;
      return reach(eval_ast(mc->left_ast), mc->opt_block);

    } else if (!strcmp(method_name, RESPOND_TO)) {
      struct method_call_node* mc = (struct method_call_node*)m;
      struct list_node* arg_node = mc->args;
      if (list_length(arg_node) != 1){
        wrong_arguments_error(list_length(arg_node), 1);
      }
      return rrespond_to(eval_ast(mc->left_ast), strdup(string_value(eval_ast(arg_node->arg))));

    } else if (!strcmp(method_name, NIL_METHOD)) {
      return rnil((struct method_call_node*)m);

    } else if (!strcmp(method_name, OBJECT_ID)) {
      return robject_id((struct method_call_node*)m);
    };
	};
  return new_nil_node();
};
int shortestDistance(vector<vector<int>> grid) {
         if (grid.size()==0 || grid[0].size()== 0) {
           return -1;
         }
         int m = grid.size();
         int n = grid[0].size();
         int houseNum = 0;
         const vector<int> dirs( { 0, 1, 0, -1, 0} );
         vector<vector<int> > dist(m, vector<int>(n)); 
         vector<vector<int> > reach(m, vector<int>(n));
         for (int i=0; i<m; i++) {
             for (int j=0; j<n; j++) {
                 if (grid[i][j] == 1) {
                     houseNum++;
                     int level = 0;
                     vector<vector<bool> > visited(m, vector<bool>(n));
                     queue<int> bfs_q;
                     bfs_q.push(i*n+j);
                     visited[i][j] = true;
                     while (!bfs_q.empty()) {
                         int size = bfs_q.size();
                         for (int t=0; t<size; t++) {
                             int cur = bfs_q.front();
                             bfs_q.pop();
                             int x = cur/n;
                             int y = cur%n;
                             for (int i=0;i<4;++i) {
                                 int xnew = x + dirs[i];
                                 int ynew = y + dirs[i+1];
                                 if (xnew>=0 && xnew<m && ynew>=0 && ynew<n 
                                     && !visited[xnew][ynew] && grid[xnew][ynew]==0) {
                                     bfs_q.push(xnew*n+ynew);
                                     visited[xnew][ynew] = true;
                                     dist[xnew][ynew] += level+1;
                                     reach[xnew][ynew]++;
                                 }
                             }
                         }
                         level++;
                     }
                 }
             }
         }
         
         int minDist = INT_MAX;
         for (int i=0; i<m; i++) {
             for (int j=0; j<n; j++) {
                 if (grid[i][j]==0 && reach[i][j] == houseNum) {
                     minDist = min(minDist, dist[i][j]);
                 }
             }
         }
         return minDist == INT_MAX ? -1 : minDist;
}
Пример #13
0
bool reach(int u, int dest, int times) {
    if (u == dest) {
        return true;
    }
    visit[u] = times;
    foreach(iter, neighbors[u]) {
        int v = *iter;
        if (visit[v] != times && reach(v, dest, times)) {
            return true;
        }
    }
Пример #14
0
Reach setup_reach(const Config & config, const Protein & protein) {
    ModelReduction reduction = load_reduction(config.files.reduction, protein.residue_count());

    ProteinSegmentFactory protein_segment_factory;
    std::vector<std::shared_ptr<ProteinSegment>> protein_segments = protein_segment_factory.generate_protein_segments_for_analysis(protein);

    TrajectoryAnalyzer trajectory_analyzer;

    if (config.files.nma_covariance) {
        LOGI << "setting up Reach with NMA input";

        CSVReader csv_reader;
        Eigen::MatrixXd nma_covariance = csv_reader.read_matrix(
                *config.files.nma_covariance,
                protein.residue_count() * 3);

        trajectory_analyzer.analyze(nma_covariance, protein_segments, config.general.temperature);

    } else {
        LOGI << "setting up Reach with Trajectory";
        LOGI << "loading trajectory files";

        TrajectoryFileFactory tf;
        std::vector<std::shared_ptr<TrajectoryFile>> trajectory_files;

        for (auto const & path : config.files.trajectories) {
            trajectory_files.push_back(tf.create(path, config.general.crystal_information));
        }

        Trajectory trajectory(trajectory_files);

        trajectory_analyzer.analyze(trajectory,
                                    protein_segments,
                                    config.general.temperature,
                                    config.general.ensemble_size);
    }

    Reach reach(protein_segments,
                config.general.temperature,
                config.general.ensemble_size,
                config.fitting.average_bin_length,
                config.fitting.minimum_length,
                config.fitting.maximum_length,
                config.fitting.use_slow_fitting,
                config.fitting.slow_minimum_length,
                config.fitting.slow_maximum_length,
                reduction);

    return reach;
}
Пример #15
0
 void finish() {
   // TUHG_SHOWP(1, "pre-heapify", locp);
   heap.heapify();
   // TUHG_SHOWP(1, "post-heapify", locp);
   TUHG_SHOWP_ALL(1, "pre-finish");
   while (!heap.empty()) {
     VD top = this->top();
     TUHG_SHOWQ(6, "at-top", top);
     SHOWIF2(TUHG, 5, heap.size(), top, TUHG_PRINT(top, g));
     pop();
     reach(top);
     TUHG_SHOWP_ALL(9, "post-reach");
   }
   stat.n_unpopped = heap.size();
   TUHG_SHOWP_ALL(5, "post-finish");
   SHOWIF0(TUHG, 1, stat);
 }
Пример #16
0
/** Calculate the stop alphabet for each depth from 0 to MAX_STOP_DEPTH. Then
 * build an eight-bit mask per character C, with each bit representing the
 * depth before the location of character C (if encountered) that the NFA would
 * be in a predictable start state. */
vector<u8> findLeftOffsetStopAlphabet(const NGHolder &g, som_type som) {
    const depth max_depth(MAX_STOP_DEPTH);
    const InitDepths depths(g);
    const map<NFAVertex, BoundedRepeatSummary> no_vertices;

    vector<CharReach> reach(MAX_STOP_DEPTH);

    for (auto v : vertices_range(g)) {
        if (is_special(v, g)) {
            continue;
        }
        CharReach v_cr;
        if (som == SOM_NONE) {
            v_cr = reduced_cr(v, g, no_vertices);
        } else {
            v_cr = g[v].char_reach;
        }

        u32 d = min(max_depth, depths.maxDist(g, v));
        for (u32 i = 0; i < d; i++) {
            reach[i] |= v_cr;
        }
    }

#ifdef DEBUG
    for (u32 i = 0; i < MAX_STOP_DEPTH; i++) {
        DEBUG_PRINTF("depth %u, stop chars: ", i);
        describeClass(stdout, ~reach[i], 20, CC_OUT_TEXT);
        printf("\n");
    }
#endif

    vector<u8> stop(N_CHARS, 0);

    for (u32 i = 0; i < MAX_STOP_DEPTH; i++) {
        CharReach cr = ~reach[i]; // invert reach for stop chars.
        const u8 mask = 1U << i;
        for (size_t c = cr.find_first(); c != cr.npos; c = cr.find_next(c)) {
            stop[c] |= mask;
        }
    }

    return stop;
}
// do the feedback loop
void doFeedbackLoop(std::vector<StateDefinition> stateMachine)
{
	GameSensors sensors;
	GameActuators actuators;

	while (true)
	{
		printf("Current Health %d/%d (%0.00f%%)\n", currentHealth, maximumHealth, sensors.getHealthPercent());
		for (auto state = stateMachine.begin(); state != stateMachine.end(); state++)
		{
			if (!state->condition(&sensors))
			{
				state->reach(&sensors, &actuators);
				break;
			}
		}
		
		getinput(); // since there's no actual game, this just allows you to change the state of the game to see how the feedback loop behaves
		Sleep(1000);
	}
}
Пример #18
0
int main(){
	int row, column, radius, points;
	int matrix[8][8] = {
	{1,0,1,0,1,0,0,1},
	{0,0,2,0,0,0,0,0},
	{0,0,2,0,2,0,2,0},
	{0,1,0,0,0,0,0,0},
	{0,0,0,0,0,2,0,0},
	{0,2,0,1,0,0,0,2},
	{0,0,0,2,0,0,1,0},
	{2,0,1,0,0,1,0,0}
	};//matrix
	printf("Enter row: ");
	scanf_s("%i", &row);
	printf("\nEnter column: ");
	scanf_s("%i", &column);
	printf("\nEnter radius: ");
	scanf_s("%i", &radius);
	points = reach(matrix, row, column, radius);
	printf("You got %i points!\n", points);
	system("pause");
	return 0;
}
Пример #19
0
int main(int argc,char **argv)
{
    MT::initCmdLine(argc,argv);

    switch(MT::getParameter<int>("mode",2)) {
    case 0:
        simpleArrayOperations();
        break;
    case 1:
        openingSimulator();
        break;
    case 2:
        reach();
        break;
    case 3:
        circle();
        break;
    case 4:
        reachTargetByTrajectory();
        break;
    }

    return 0;
}
Пример #20
0
void expect(int k){
  for(int i=0;i<=k;i++){
    printf("%d colors should reach: %.1lf\n",i,reach(k,i));
  }
}
Пример #21
0
bool genexe(compile_t* c, ast_t* program)
{
  errors_t* errors = c->opt->check.errors;

  // The first package is the main package. It has to have a Main actor.
  const char* main_actor = c->str_Main;
  const char* env_class = c->str_Env;

  ast_t* package = ast_child(program);
  ast_t* main_def = ast_get(package, main_actor, NULL);

  if(main_def == NULL)
  {
    errorf(errors, NULL, "no Main actor found in package '%s'", c->filename);
    return false;
  }

  // Generate the Main actor and the Env class.
  ast_t* main_ast = type_builtin(c->opt, main_def, main_actor);
  ast_t* env_ast = type_builtin(c->opt, main_def, env_class);

  if(lookup(NULL, main_ast, main_ast, c->str_create) == NULL)
    return false;

  if(c->opt->verbosity >= VERBOSITY_INFO)
    fprintf(stderr, " Reachability\n");
  reach(c->reach, main_ast, c->str_create, NULL, c->opt);
  reach(c->reach, env_ast, c->str__create, NULL, c->opt);

  if(c->opt->limit == PASS_REACH)
    return true;

  if(c->opt->verbosity >= VERBOSITY_INFO)
    fprintf(stderr, " Selector painting\n");
  paint(&c->reach->types);

  if(c->opt->limit == PASS_PAINT)
    return true;

  if(!gentypes(c))
    return false;

  if(c->opt->verbosity >= VERBOSITY_ALL)
    reach_dump(c->reach);

  reach_type_t* t_main = reach_type(c->reach, main_ast);
  reach_type_t* t_env = reach_type(c->reach, env_ast);

  if((t_main == NULL) || (t_env == NULL))
    return false;

  gen_main(c, t_main, t_env);

  if(!genopt(c))
    return false;

  const char* file_o = genobj(c);

  if(file_o == NULL)
    return false;

  if(c->opt->limit < PASS_ALL)
    return true;

  if(!link_exe(c, program, file_o))
    return false;

#ifdef PLATFORM_IS_WINDOWS
  _unlink(file_o);
#else
  unlink(file_o);
#endif

  return true;
}
Пример #22
0
static
void findForwardAccelScheme(const vector<hwlmLiteral> &lits,
                            hwlm_group_t expected_groups, AccelAux *aux) {
    DEBUG_PRINTF("building accel expected=%016llx\n", expected_groups);
    u32 min_len = MAX_ACCEL_OFFSET;
    vector<const hwlmLiteral *> filtered_lits;

    filterLits(lits, expected_groups, &filtered_lits, &min_len);
    if (filtered_lits.empty()) {
        return;
    }

    if (findDVerm(filtered_lits, aux)
        || findSVerm(filtered_lits, aux)) {
        return;
    }

    vector<CharReach> reach(MAX_ACCEL_OFFSET, CharReach());
    for (const auto &lit : lits) {
        if (!(lit.groups & expected_groups)) {
            continue;
        }

        for (u32 i = 0; i < MAX_ACCEL_OFFSET && i < lit.s.length(); i++) {
            unsigned char c = lit.s[i];
            if (lit.nocase) {
                DEBUG_PRINTF("adding %02hhx to %u\n", mytoupper(c), i);
                DEBUG_PRINTF("adding %02hhx to %u\n", mytolower(c), i);
                reach[i].set(mytoupper(c));
                reach[i].set(mytolower(c));
            } else {
                DEBUG_PRINTF("adding %02hhx to %u\n", c, i);
                reach[i].set(c);
            }
        }
    }

    u32 min_count = ~0U;
    u32 min_offset = ~0U;
    for (u32 i = 0; i < min_len; i++) {
        size_t count = reach[i].count();
        DEBUG_PRINTF("offset %u is %s (reach %zu)\n", i,
                     describeClass(reach[i]).c_str(), count);
        if (count < min_count) {
            min_count = (u32)count;
            min_offset = i;
        }
    }
    assert(min_offset <= min_len);

    if (min_count > MAX_SHUFTI_WIDTH) {
        DEBUG_PRINTF("min shufti with %u chars is too wide\n", min_count);
        return;
    }

    const CharReach &cr = reach[min_offset];
    if (shuftiBuildMasks(cr, &aux->shufti.lo, &aux->shufti.hi) != -1) {
        DEBUG_PRINTF("built shufti for %s (%zu chars, offset %u)\n",
                     describeClass(cr).c_str(), cr.count(), min_offset);
        aux->shufti.accel_type = ACCEL_SHUFTI;
        aux->shufti.offset = verify_u8(min_offset);
        return;
    }

    DEBUG_PRINTF("fail\n");
}
HDTBReturnItem NetworkModule::processRequest(std::vector<std::string> args)
{
    history.push(args);

    // Make sure commands are given
    if(args.size() == 1)
    {
        // Call to super class
        displayAvailableCommands();
        return errorHandler.generateGenericError("No commands given");
    }

    // Make sure command exists
    if(commands.find(args[1]) == commands.end())
    {
        // Call to super class
        displayAvailableCommands();
        return errorHandler.generateGenericError("Command not found");
    }

    //Handle command
    switch(commands[args[1]])
    {
    case HDTB_NETWORK_CMD_PING:
        if (args.size() != 4)
            return errorHandler.generateGenericError("Usage : ping <address> <count>");

        // Make sure count is int
        if( !(atoi(args[3].c_str())) )
            return errorHandler.generateGenericError("Usage : ping <address> <count> [Count must be an int]");

        // Send data to ping
        return ping(args[2], args[3]);
        break;

    case HDTB_NETWORK_CMD_RESET:
        return reset();
        break;

    case HDTB_NETOWRK_CMD_REACH:
        if (args.size() != 5)
            return errorHandler.generateGenericError("send <destination> <port> <message>");

        if( !(atoi(args[3].c_str())) )
            return  errorHandler.generateGenericError("Invalid port, must be an integer");

        return reach(args[2], args[3], args[4]);
        break;

    case HDTB_NETWORK_CMD_KNOCK_SEQUENCE:
        return knock();
        break;

    case HDTB_NETWORK_CMD_COMMLINK:
        return comm();
        break;

    default:
        break;
    }

    return errorHandler.generateGenericError("Uncaught return");
}
Пример #24
0
double reach(int k, int f){
  if(!f)return !!k;
  return (double)f*2*reach(k-1,f-1)/k + 1;
}
Пример #25
0
void
pcollgprintentry(Entry e, int cmd)
{
	uint8_t *p, *pe;
	int r, rprev = NONE, rx, over = 0, font;
	char buf[16];

	p = (uint8_t *)e.start;
	pe = (uint8_t *)e.end;
	curentry = e;
	if(cmd == 'h')
		outinhibit = 1;
	while(p < pe){
		if(cmd == 'r'){
			outchar(*p++);
			continue;
		}
		switch(r = intab[*p++]){	/* assign = */
		case TAGS:
			if(rprev != NONE){
				outrune(rprev);
				rprev = NONE;
			}
			p = reach(p, 0x06);
			font = tag[0];
			if(cmd == 'h')
				outinhibit = (font != 'h');
			break;

		case TAGE:	/* an extra one */
			break;
	
		case SPCS:
			p = reach(p, 0xba);
			r = looknassoc(numtab, asize(numtab), strtol(tag,0,0));
			if(r < 0){
				if(rprev != NONE){
					outrune(rprev);
					rprev = NONE;
				}
				sprint(buf, "\\N'%s'", tag);
				outchars(buf);
				break;
			}
			/* else fall through */

		default:
			if(over){
				rx = looknassoc(overtab, asize(overtab), r);
				if(rx > 0)
					rx = liglookup(rx, rprev);
				if(rx > 0 && rx != NONE)
					outrune(rx);
				else{
					outrune(rprev);
					if(r == ':')
						outrune(L'¨');
					else{
						outrune(L'^');
						outrune(r);
					}
				}
				over = 0;
				rprev = NONE;
			}else if(r == '^'){
				over = 1;
			}else{
				if(rprev != NONE)
					outrune(rprev);
				rprev = r;
			}
		}
		
	}
	if(rprev != NONE)
		outrune(rprev);
	if(cmd == 'h')
		outinhibit = 0;
	outnl(0);
}
Пример #26
0
void NPlayer::stop(bool)
{
	emit reach(true);
	emit stateChanged(state = Stop);
}
Пример #27
0
bool genexe(compile_t* c, ast_t* program)
{
  errors_t* errors = c->opt->check.errors;

  // The first package is the main package. It has to have a Main actor.
  const char* main_actor = c->str_Main;
  const char* env_class = c->str_Env;

  ast_t* package = ast_child(program);
  ast_t* main_def = ast_get(package, main_actor, NULL);

  if(main_def == NULL)
  {
    errorf(errors, NULL, "no Main actor found in package '%s'", c->filename);
    return false;
  }

  // Generate the Main actor and the Env class.
  ast_t* main_ast = type_builtin(c->opt, main_def, main_actor);
  ast_t* env_ast = type_builtin(c->opt, main_def, env_class);

  if(lookup(c->opt, main_ast, main_ast, c->str_create) == NULL)
    return false;

  if(c->opt->verbosity >= VERBOSITY_INFO)
    fprintf(stderr, " Reachability\n");
  reach(c->reach, main_ast, c->str_create, NULL, c->opt);
  reach(c->reach, env_ast, c->str__create, NULL, c->opt);

  if(c->opt->limit == PASS_REACH)
    return true;

  if(c->opt->verbosity >= VERBOSITY_INFO)
    fprintf(stderr, " Selector painting\n");
  paint(&c->reach->types);

  if(c->opt->limit == PASS_PAINT)
    return true;

  if(!gentypes(c))
    return false;

  if(c->opt->verbosity >= VERBOSITY_ALL)
    reach_dump(c->reach);

  reach_type_t* t_main = reach_type(c->reach, main_ast);
  reach_type_t* t_env = reach_type(c->reach, env_ast);

  if((t_main == NULL) || (t_env == NULL))
    return false;

  gen_main(c, t_main, t_env);

  if(!genopt(c, true))
    return false;

  if(c->opt->runtimebc)
  {
    if(!codegen_merge_runtime_bitcode(c))
      return false;

    // Rerun the optimiser without the Pony-specific optimisation passes.
    // Inlining runtime functions can screw up these passes so we can't
    // run the optimiser only once after merging.
    if(!genopt(c, false))
      return false;
  }

  const char* file_o = genobj(c);

  if(file_o == NULL)
    return false;

  if(c->opt->limit < PASS_ALL)
    return true;

  if(!link_exe(c, program, file_o))
    return false;

#ifdef PLATFORM_IS_WINDOWS
  _unlink(file_o);
#else
  unlink(file_o);
#endif

  return true;
}
Пример #28
0
QPlayer::QPlayer(QObject *parent) :
APlayer(parent)
{
	ins = this;
	setObjectName("QPlayer");
	state = Stop;
	manuallyStopped = false;
	waitingForBegin = false;
	skipTimeChanged = false;

	mp = (new QPlayerThread(this))->getMediaPlayer();
	mp->setVolume(Config::getValue("/Playing/Volume", 50));

	connect<void(QMediaPlayer::*)(QMediaPlayer::Error)>(mp, &QMediaPlayer::error, this, [this](int error){
		if ((State)mp->state() == Play){
			manuallyStopped = true;
		}
		emit errorOccurred(error);
	});

	connect(mp, &QMediaPlayer::volumeChanged, this, &QPlayer::volumeChanged);

	connect(mp, &QMediaPlayer::stateChanged, this, [this](int _state){
		if (_state == Stop){
			if (!manuallyStopped&&Config::getValue("/Playing/Loop", false)){
				stateChanged(state = Loop);
				play();
				emit jumped(0);
			}
			else{
				stateChanged(state = Stop);
				emit reach(manuallyStopped);
			}
			manuallyStopped = false;
		}
		else{
			manuallyStopped = false;
			if (_state == Play&&state == Stop){
				waitingForBegin = true;
			}
			else{
				emit stateChanged(state = _state);
			}
		}
	});

	connect(mp, &QMediaPlayer::positionChanged, this, [this](qint64 time){
		if (waitingForBegin&&time > 0){
			waitingForBegin = false;
			ARender::instance()->setMusic(!mp->isVideoAvailable());
			emit stateChanged(state = Play);
			emit begin();
		}
		if (!skipTimeChanged){
			emit timeChanged(time);
		}
		else{
			skipTimeChanged = false;
		}
	});

	connect(mp, &QMediaPlayer::mediaChanged, this, [this](){
		emit mediaChanged(getMedia());
	});

	connect(mp, &QMediaPlayer::playbackRateChanged, this, &QPlayer::rateChanged);
}
Пример #29
0
Файл: main.c Проект: ah09/spdi2
int main()
{
    /*line test1 = {{1, 1}, {4, 1}};
    line test2 = {{1, 1}, {1, 4}};
    if (isSomeCollinearIntersection(test1, test2)){
        printf("there is collinear intersection\n");
        line ci = collinearIntersection(test1, test2);
        printf("test1 and test2 intersect from (%f, %f) to (%f, %f)\n", ci.pt1.x, ci.pt1.y, ci.pt2.x, ci.pt2.y);
    }
    else{
        printf("test1 and test2 do not intersect\n");
    }
    if (lineSetMinusLine(test1, test2).pt1.x != -1){
        line l_l = lineSetMinusLine(test1, test2);
        printf("test1 - test2 is (%f, %f) to (%f, %f)\n", l_l.pt1.x, l_l.pt1.y, l_l.pt2.x, l_l.pt2.y);
    }
    else {
        printf("nothing left\n");
    }*/
    printf("enter size of SPDI\n");
    int size;
    scanf("%d", &(size));
    region * SPDI = malloc(sizeof(region) * size);
    int i = 0;
    for (i = 0; i < size; ++i) {
        printf("enter R%d.e.e1.pt1.x, R%d.e.e1.pt1.y, R%d.e.e1.pt2.x, R%d.e.e1.pt2.y, R%d.e.e2.pt1.x, R%d.e.e2.pt1.y, R%d.e.e2.pt2.x, R%d.e.e2.pt2.y, R%d.e.e3.pt1.x, R%d.e.e3.pt1.y, R%d.e.e3.pt2.x, R%d.e.e3.pt2.y, R%d.e.e4.pt1.x, R%d.e.e4.pt1.y, R%d.e.e4.pt2.x, R%d.e.e4.pt2.y\n", i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1, i+1);
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &(SPDI[i].e.e1.pt1.x), &(SPDI[i].e.e1.pt1.y), &(SPDI[i].e.e1.pt2.x), &(SPDI[i].e.e1.pt2.y), &(SPDI[i].e.e2.pt1.x), &(SPDI[i].e.e2.pt1.y), &(SPDI[i].e.e2.pt2.x), &(SPDI[i].e.e2.pt2.y), &(SPDI[i].e.e3.pt1.x), &(SPDI[i].e.e3.pt1.y), &(SPDI[i].e.e3.pt2.x), &(SPDI[i].e.e3.pt2.y), &(SPDI[i].e.e4.pt1.x), &(SPDI[i].e.e4.pt1.y), &(SPDI[i].e.e4.pt2.x), &(SPDI[i].e.e4.pt2.y));
        printf("enter R%d.v.a.x, R%d.v.a.y, R%d.v.b.x, R%d.v.b.y\n", i+1, i+1, i+1 ,i+1);
        scanf("%lf %lf %lf %lf", &(SPDI[i].v.a.x), &(SPDI[i].v.a.y), &(SPDI[i].v.b.x), &(SPDI[i].v.b.y));
    }
    //region R1;
    //region R2;
    //region R3;
    //region R4;
    //region R5;
    //region R6;
    //region R7;
    //region R8;
    //region R9;
    /*printf("enter R1.e.e1.pt1.x, R1.e.e1.pt1.y, R1.e.e1.pt2.x, R1.e.e1.pt2.y, R1.e.e2.pt1.x, R1.e.e2.pt1.y, R1.e.e2.pt2.x, R1.e.e2.pt2.y, R1.e.e3.pt1.x, R1.e.e3.pt1.y, R1.e.e3.pt2.x, R1.e.e3.pt2.y, R1.e.e4.pt1.x, R1.e.e4.pt1.y, R1.e.e4.pt2.x, R1.e.e4.pt2.y\n");
    scanf("%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf\n", &(R1.e.e1.pt1.x), &(R1.e.e1.pt1.y), &(R1.e.e1.pt2.x), &(R1.e.e1.pt2.y), &(R1.e.e2.pt1.x), &(R1.e.e2.pt1.y), &(R1.e.e2.pt2.x), &(R1.e.e2.pt2.y), &(R1.e.e3.pt1.x), &(R1.e.e3.pt1.y), &(R1.e.e3.pt2.x), &(R1.e.e3.pt2.y), &(R1.e.e4.pt1.x), &(R1.e.e4.pt1.y), &(R1.e.e4.pt2.x), &(R1.e.e4.pt2.y));*/
    //regionEdges re1 = { {{1, 1}, {2, 1}}, {{1, 1}, {1, 2}}, {{1, 2}, {2, 2}}, {{2, 1}, {2, 2}} };
    /*printf("enter R1.v.a.x, R1.v.a.y, R1.v.b.x, R1.v.b.y\n");
    scanf("%lf, %lf, %lf, %lf\n", &(R1.v.a.x), &(R1.v.a.y), &(R1.v.b.x), &(R1.v.b.y));*/
    //regionVectors rv1 = { {1, -1}, {1, -1} };
    /*printf("enter R2.e.e1.pt1.x, R2.e.e1.pt1.y, R2.e.e1.pt2.x, R2.e.e1.pt2.y, R2.e.e2.pt1.x, R2.e.e2.pt1.y, R2.e.e2.pt2.x, R2.e.e2.pt2.y, R2.e.e3.pt1.x, R2.e.e3.pt1.y, R2.e.e3.pt2.x, R2.e.e3.pt2.y, R2.e.e4.pt1.x, R2.e.e4.pt1.y, R2.e.e4.pt2.x, R2.e.e4.pt2.y\n");
    scanf("%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf", &(R2.e.e1.pt1.x), &(R2.e.e1.pt1.y), &(R2.e.e1.pt2.x), &(R2.e.e1.pt2.y), &(R2.e.e2.pt1.x), &(R2.e.e2.pt1.y), &(R2.e.e2.pt2.x), &(R2.e.e2.pt2.y), &(R2.e.e3.pt1.x), &(R2.e.e3.pt1.y), &(R2.e.e3.pt2.x), &(R2.e.e3.pt2.y), &(R2.e.e4.pt1.x), &(R2.e.e4.pt1.y), &(R2.e.e4.pt2.x), &(R2.e.e4.pt2.y));*/
    //regionEdges re2 = { {{2,1},{3,1}}, {{2,1},{2,2}}, {{2,2},{3,2}}, {{3,1},{3,2}} };
    /*printf("enter R2.v.a.x, R2.v.a.y, R2.v.b.x, R2.v.b.y\n");
    scanf("%lf, %lf, %lf, %lf", &(R2.v.a.x), &(R2.v.a.y), &(R2.v.b.x), &(R2.v.b.y));*/
    //regionVectors rv2 = { {1, 1}, {1, 0} };
    //regionEdges re3 = { {{3,1},{4,1}}, {{3,1},{3,2}}, {{3,2},{4,2}}, {{4,1},{4,2}} };
    //regionVectors rv3 = { {1, 1}, {1, 1} };
    /*printf("enter R3.e.e1.pt1.x, R3.e.e1.pt1.y, R3.e.e1.pt2.x, R3.e.e1.pt2.y, R3.e.e2.pt1.x, R3.e.e2.pt1.y, R3.e.e2.pt2.x, R3.e.e2.pt2.y, R3.e.e3.pt1.x, R3.e.e3.pt1.y, R3.e.e3.pt2.x, R3.e.e3.pt2.y, R3.e.e4.pt1.x, R3.e.e4.pt1.y, R3.e.e4.pt2.x, R3.e.e4.pt2.y\n");
    scanf("%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf", &(R3.e.e1.pt1.x), &(R3.e.e1.pt1.y), &(R3.e.e1.pt2.x), &(R3.e.e1.pt2.y), &(R3.e.e2.pt1.x), &(R3.e.e2.pt1.y), &(R3.e.e2.pt2.x), &(R3.e.e2.pt2.y), &(R3.e.e3.pt1.x), &(R3.e.e3.pt1.y), &(R3.e.e3.pt2.x), &(R3.e.e3.pt2.y), &(R3.e.e4.pt1.x), &(R3.e.e4.pt1.y), &(R3.e.e4.pt2.x), &(R3.e.e4.pt2.y));*/
    //regionEdges re4 = { {{1,2},{2,2}}, {{1,2},{1,3}}, {{1,3},{2,3}}, {{2,2},{2,3}} };
    /*printf("enter R3.v.a.x, R3.v.a.y, R3.v.b.x, R3.v.b.y\n");
    scanf("%lf, %lf, %lf, %lf", &(R3.v.a.x), &(R3.v.a.y), &(R3.v.b.x), &(R3.v.b.y));*/
    //regionVectors rv4 = { {0, -1}, {0, -1} };
    /*printf("enter R4.e.e1.pt1.x, R4.e.e1.pt1.y, R4.e.e1.pt2.x, R4.e.e1.pt2.y, R4.e.e2.pt1.x, R4.e.e2.pt1.y, R4.e.e2.pt2.x, R4.e.e2.pt2.y, R4.e.e3.pt1.x, R4.e.e3.pt1.y, R4.e.e3.pt2.x, R4.e.e3.pt2.y, R4.e.e4.pt1.x, R4.e.e4.pt1.y, R4.e.e4.pt2.x, R4.e.e4.pt2.y\n");
    scanf("%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf", &(R4.e.e1.pt1.x), &(R4.e.e1.pt1.y), &(R4.e.e1.pt2.x), &(R4.e.e1.pt2.y), &(R4.e.e2.pt1.x), &(R4.e.e2.pt1.y), &(R4.e.e2.pt2.x), &(R4.e.e2.pt2.y), &(R4.e.e3.pt1.x), &(R4.e.e3.pt1.y), &(R4.e.e3.pt2.x), &(R4.e.e3.pt2.y), &(R4.e.e4.pt1.x), &(R4.e.e4.pt1.y), &(R4.e.e4.pt2.x), &(R4.e.e4.pt2.y));*/
    //regionEdges re5 = { {{2,2},{3,2}}, {{2,2},{2,3}}, {{2,3},{3,3}}, {{3,2},{3,3}} };
    /*printf("enter R4.v.a.x, R4.v.a.y, R4.v.b.x, R4.v.b.y\n");
    scanf("%lf, %lf, %lf, %lf", &(R4.v.a.x), &(R4.v.a.y), &(R4.v.b.x), &(R4.v.b.y));*/
    //regionVectors rv5 = { {0, 1}, {0, 1} };
    //regionEdges re6 = { {{3,2},{4,2}}, {{3,2},{3,3}}, {{3,3},{4,3}}, {{4,2},{4,3}} };
    //regionVectors rv6 = { {0, 1}, {0, 1} };
    /*printf("enter R5.e.e1.pt1.x, R5.e.e1.pt1.y, R5.e.e1.pt2.x, R5.e.e1.pt2.y, R5.e.e2.pt1.x, R5.e.e2.pt1.y, R5.e.e2.pt2.x, R5.e.e2.pt2.y, R5.e.e3.pt1.x, R5.e.e3.pt1.y, R5.e.e3.pt2.x, R5.e.e3.pt2.y, R5.e.e4.pt1.x, R5.e.e4.pt1.y, R5.e.e4.pt2.x, R5.e.e4.pt2.y\n");
    scanf("%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf", &(R5.e.e1.pt1.x), &(R5.e.e1.pt1.y), &(R5.e.e1.pt2.x), &(R5.e.e1.pt2.y), &(R5.e.e2.pt1.x), &(R5.e.e2.pt1.y), &(R5.e.e2.pt2.x), &(R5.e.e2.pt2.y), &(R5.e.e3.pt1.x), &(R5.e.e3.pt1.y), &(R5.e.e3.pt2.x), &(R5.e.e3.pt2.y), &(R5.e.e4.pt1.x), &(R5.e.e4.pt1.y), &(R5.e.e4.pt2.x), &(R5.e.e4.pt2.y));*/
    //regionEdges re7 = { {{1,3},{2,3}}, {{1,3},{1,4}}, {{1,4},{2,4}}, {{2,3},{2,4}} };
    /*printf("enter R5.v.a.x, R5.v.a.y, R5.v.b.x, R5.v.b.y\n");
    scanf("%lf, %lf, %lf, %lf", &(R5.v.a.x), &(R5.v.a.y), &(R5.v.b.x), &(R5.v.b.y));*/
    //regionVectors rv7 = { {-1, -1}, {-1, -1} };
    /*printf("enter R6.e.e1.pt1.x, R6.e.e1.pt1.y, R6.e.e1.pt2.x, R6.e.e1.pt2.y, R6.e.e2.pt1.x, R6.e.e2.pt1.y, R6.e.e2.pt2.x, R6.e.e2.pt2.y, R6.e.e3.pt1.x, R6.e.e3.pt1.y, R6.e.e3.pt2.x, R6.e.e3.pt2.y, R6.e.e4.pt1.x, R6.e.e4.pt1.y, R6.e.e4.pt2.x, R6.e.e4.pt2.y\n");
    scanf("%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf", &(R6.e.e1.pt1.x), &(R6.e.e1.pt1.y), &(R6.e.e1.pt2.x), &(R6.e.e1.pt2.y), &(R6.e.e2.pt1.x), &(R6.e.e2.pt1.y), &(R6.e.e2.pt2.x), &(R6.e.e2.pt2.y), &(R6.e.e3.pt1.x), &(R6.e.e3.pt1.y), &(R6.e.e3.pt2.x), &(R6.e.e3.pt2.y), &(R6.e.e4.pt1.x), &(R6.e.e4.pt1.y), &(R6.e.e4.pt2.x), &(R6.e.e4.pt2.y));*/
    //regionEdges re8 = { {{2,3},{3,3}}, {{2,3},{2,4}}, {{2,4},{3,4}}, {{3,3},{3,4}} };
    /*printf("enter R6.v.a.x, R6.v.a.y, R6.v.b.x, R6.v.b.y\n");
    scanf("%lf, %lf, %lf, %lf", &(R6.v.a.x), &(R6.v.a.y), &(R6.v.b.x), &(R6.v.b.y));*/
    //regionVectors rv8 = { {-1, 1}, {-1, 0}};
    //regionEdges re9 = { {{3,3},{4,3}}, {{3,3},{3,4}}, {{3,4},{4,4}}, {{4,3},{4,4}} };
    //regionVectors rv9 = { {-1, 1}, {-1, 1} };
    //R1.e = re1;
    //R1.v = rv1;
    //R2.e = re2;
    //R2.v = rv2;
    //R3.e = re3;
    //R3.v = rv3;
    //R4.e = re4;
    //R4.v = rv4;
    //R5.e = re5;
    //R5.v = rv5;
    //R6.e = re6;
    //R6.v = rv6;
    //R7.e = re7;
    //R7.v = rv7;
    //R8.e = re8;
    //R8.v = rv8;
    //R9.e = re9;
    //R9.v = rv9;
    //region SPDI[9] = {R1, R2, R3, R4, R5, R6, R7, R8, R9};
    line initial;
    printf("enter initial.pt1.x, initial.pt1.y, initial.pt2.x, initial.pt2.y\n");
    scanf("%lf %lf %lf %lf", &(initial.pt1.x), &(initial.pt1.y), &(initial.pt2.x), &(initial.pt2.y));
    //line initial = { {2, 1.25}, {2, 1.75} };
    line target;
    printf("enter target.pt1.x, target.pt1.y, target.pt2.x, target.pt2.y\n");
    scanf("%lf %lf %lf %lf", &(target.pt1.x), &(target.pt1.y), &(target.pt2.x), &(target.pt2.y));
    //line target = { {2, 2}, {2, 3} };
    sort(&initial.pt1.x, &initial.pt1.y, &initial.pt2.x, &initial.pt2.y);
    sort(&target.pt1.x, &target.pt1.y, &target.pt2.x, &target.pt2.y);
    //line e1 = { {2, 1}, {2, 2} };
    //line e2 = { {2, 2}, {3, 2} };
    //line e3 = { {2, 2}, {2, 3} };
    //line e4 = { {1, 2}, {2, 2} };
    //line edgeList[4] = {e1, e2, e3, e4};
    //int size = sizeof(SPDI) / sizeof(SPDI[0]);
    //line * k = malloc(sizeof(line) * 5);
    //k = controllabilityKernel(k, edgeList, 4, initial, SPDI, size);
    //int i = 0;
    //for (i = 0; i < 4; ++i) {
        //printf("k[%d] is (%f, %f) to (%f, %f)\n", i, k[i].pt1.x, k[i].pt1.y, k[i].pt2.x, k[i].pt2.y);
    //}
    line * edgeSequence = malloc(sizeof(line) * 1000);
    line * intervalSequence = malloc(sizeof(line) * 1000);
    //line * inescapable = malloc(sizeof(line) * 1000);
    intervalSequence[0] = initial;
    line l = reach(SPDI, size, edgeSequence, intervalSequence, 0, target);
    if (l.pt1.x != -1) {
        printf("yes, the edge (%f, %f) to (%f, %f)\nis reachable at (%f, %f) to (%f, %f)\nwhen starting from (%f, %f) to (%f, %f)\n",
        target.pt1.x, target.pt1.y, target.pt2.x, target.pt2.y, l.pt1.x, l.pt1.y, l.pt2.x, l.pt2.y, initial.pt1.x, initial.pt1.y, initial.pt2.x, initial.pt2.y);
    }
    else {
        printf("no, the edge (%f, %f) to (%f, %f) is not reachable when starting from (%f, %f) to (%f, %f)\n",
        target.pt1.x, target.pt1.y, target.pt2.x, target.pt2.y, initial.pt1.x, initial.pt1.y, initial.pt2.x, initial.pt2.y);
    }
    //free(k);
    //free(SPDI);
    return 0;
}