Object::Direction Actor::get_reference() const { Direction dir; if (m_xref > get_front()) { dir = Right; } else if (m_xref < get_front()) { dir = Left; } return dir; }
void keyPress(int index, int key) { Queue * q = stimuli[index]; Circle * c2 = &targetCircles[index]; Node * head = get_front(q); Circle * c1; int i; if (head != NULL) { c1 = &(head->circle); if (c1->movable == TRUE) { // the circle is moving if (abs(c1->y - c2->y) < RADIUS * 2.0) { // the stimuli and target are touching // begin to fade or modify alpha c1->invisibleStartTime = glfwGetTime(); // fade away c1->fadeAway = TRUE; c1->alpha = 1.0; for (i = 0; i < COLOR_NUM; i++) { c1->colour[i] = WHITE; } // stopping c1->movable = FALSE; // write to file writeData(TRUE, key); } else { // the stimuli is not touching the target writeData(FALSE, key); } } } else { writeData(FALSE, key); } }
Any_Type get_front_and_dequeue(struct Queue *q) { Any_Type a = get_front(q); dequeue(q); return a; }
//5.得到队首元素 Boolean get_front_queue(Queue *queue, void **value) { if(queue == NULL || is_queue_empty(queue)) { return FALSE; } if(value != NULL){ return get_front(queue->dlist, value); } }
void Hovering::move(Map *map) { switch(m_action) { case Still: set_action(Move); break; case Move: face_reference(get_attribute("turn_width")); animate_move(); if (m_dir == Right) { if (m_x < m_x1) { set_vx(get_attribute("move_speed")); } else { set_vx(0); } } else { if (m_x > m_x0) { set_vx(-get_attribute("move_speed")); } else { set_vx(0); } } if (m_attack_timer.expired(get_attribute("attack_timer"))) { int dist = get_attribute("attack_distance"); int x = m_xref - get_front(); int y = m_yref - get_y(); if (x * x + y * y < dist * dist) { fire(); } } Body::move(map); break; case Hit: case HitPerish: set_vy(0); process_hit(); Monster::move(map); break; default: break; } // Move bullets unsigned n = m_bullets.size(); for (unsigned i = 0; i < n; i++) { m_bullets[i]->move(map); } }
Boolean get_top(Stack *stack, void **value) { if(stack == NULL || value == NULL || is_empty(stack)){ return FALSE; } get_front(stack->dlist, value); printf("%x \n", value); return TRUE; }
/* void print_int(void *value); void print_int(void *value) { printf("%d ",*(int *)value); } */ int main(int argc, char **argv) { int i = 0; int a[]={1,2,3,4,5}; void *value; Dlist *dlist = NULL; dlist = init_dlist(); printf("3.push_front(dlist, &a[i]);\n"); for(i=0; i< sizeof(a)/sizeof(a[0]);++i) { push_front(dlist, &a[i]); } show_dlist(dlist, print_int); printf("5.pop_front(dlist);\n"); pop_front(dlist); show_dlist(dlist, print_int); printf("4.push_back(dlist, &a[i]);\n"); for(i=0; i< sizeof(a)/sizeof(a[0]);++i) { push_back(dlist, &a[i]); } show_dlist(dlist, print_int); printf("6.pop_back(dlist);\n"); pop_back(dlist); show_dlist(dlist, print_int); printf("7.insert_prev(dlist, dlist->head->next->next, &a[4]);\n"); insert_prev(dlist, dlist->head->next->next, &a[4]); show_dlist(dlist, print_int); printf("8.insert_next(dlist, dlist->head->next->next, &a[4]);\n"); insert_next(dlist, dlist->head->next->next, &a[4]); show_dlist(dlist, print_int); printf("9.remove_dlist_node(dlist, dlist->head->next->next->next);\n"); remove_dlist_node(dlist, dlist->head->next->next->next); show_dlist(dlist, print_int); get_front(dlist, &value); printf("\n11.get_front:\n"); print_int(value); get_tail(dlist, &value); printf("\n12.get_tail:\n"); print_int(value); printf("\n13.get_dlist_count:\n"); printf("%d \n",get_dlist_count(dlist)); destroy_dlist(&dlist); return 0; }
void Actor::face_reference(int width) { const Sprite *spr = get_sprite(); int check_width; if (!width) { check_width = spr->get_width(); } else { check_width = width; } if (abs(m_xref - get_front()) < check_width) { set_dir(); } else if (m_xref > get_front()) { set_dir(Right); } else if (m_xref < get_front()) { set_dir(Left); } }
int main() { int data=0, op=0; queue_t *q = malloc(sizeof(queue_t)); printf("Size of Queue :"); scanf("%d", &q->size); init_queue(q, 2); while(1) { printf("Enqueue - 1 \nDequeue - 2 \nExit - 3\n"); scanf("%d", &op); switch(op) { case 1: { node_t *node = malloc(sizeof(node_t)); printf("Data :"); scanf("%d", &data); node->data = data; node->left = NULL; node->right = NULL; enqueue(q, node); print_queue(q); break; } case 2: { node_t *node = get_front(q); if(node == NULL) printf("Empty Queue\n"); dequeue(q); printf("Dequeing node : %d\n", node?node->data:0); break; } case 3: { print_queue(q); exit(0); } } } return 0; }
void get_front( Vec<Expr> &front, Expr inst ) { if ( inst->op_id == inst->cur_op_id ) return; inst->op_id = inst->cur_op_id; int nb_id = 0; for( Expr ch : inst->inp ) if ( ch ) nb_id += not ch->when->always( false ); for( Expr ch : inst->dep ) if ( ch ) nb_id += not ch->when->always( false ); if ( nb_id ) { for( Expr ch : inst->inp ) if ( ch and not ch->when->always( false ) ) get_front( front, ch ); for( Expr ch : inst->dep ) if ( ch and not ch->when->always( false ) ) get_front( front, ch ); } else front << inst; }
void Erupter::move(Map *map) { Monster::move(map); switch(m_action) { case Still: if (m_attack_timer.check(get_attribute("attack_timer"))) { m_attack_timer.reset(); int dist = get_attribute("attack_distance"); int x = m_xref - get_front(); int y = m_yref - get_y(); if (x * x + y * y < dist * dist) { m_attack_timer.reset(); fire(); } } break; case MediumAttack: if (m_anim_timer.expired(get_attribute("treshold"))) { m_attack_timer.reset(); reset_attack(); } break; default: break; } // Move bullets std::vector<GravityBullet*> remove; for (std::list<GravityBullet*>::iterator it = m_bullets.begin(); it != m_bullets.end(); ++it) { GravityBullet *bullet = (*it); bullet->move(map); if (!bullet->get_moving()) { remove.push_back(bullet); } } for (int i = 0; i < remove.size(); i++) { GravityBullet *bullet = remove[i]; m_bullets.remove(bullet); delete bullet; } }
void Dancer::move(Map *map) { Monster::move(map); switch(m_action) { case Still: set_action(Move); break; case Move: face_reference(get_attribute("turn_width")); animate_move(); if (m_attack_timer.check(get_attribute("attack_timer"))) { int dist = get_attribute("attack_distance"); int x = m_xref - get_front(); int y = m_yref - get_y(); if (x * x + y * y < dist * dist) { m_attack_timer.reset(); set_jump(map); if (get_reference() == Right) { set_speed(get_attribute("jump_forward"), -get_attribute("jump_speed")); } else { set_speed(-get_attribute("jump_forward"), -get_attribute("jump_speed")); } } } else { if (m_dir == Right) { set_vx(get_attribute("move_speed")); } else { set_vx(-get_attribute("move_speed")); } } break; default: break; } }
void Player::process_messages(int _size) { long long size = (long long)_size << 32; long long offset = 0; Message next_msg; Message msg; while (!rt_messages.empty()) { msg = rt_messages.pop(); msg.timestamp = 0; handle_message(msg); } MessageQueue &queue = get_front(); if (!playing) { read_position = queue.position; return; } while (size) { long long delta = size; if (!queue.empty()) { next_msg = queue.peek(); delta = std::min(next_msg.timestamp - queue.read_samples, size); if (delta < 0) { // drop queue.pop(); delta = 0; } if (delta < size) { msg = queue.pop(); read_position = msg.frame; msg.timestamp = offset; handle_message(msg); } } queue.read_samples += delta; size -= delta; offset += delta; } }
void bfs(int size, int matrix[size][size], int visited[size], int vertex) { QUEUEPTR queue = create_queue(); queue = enqueue(queue, vertex); visited[vertex] = 1; int front, i; while(!is_queue_empty(queue)) { front = get_front(queue); printf("Vertex %d touched.", front); queue = dequeue(queue); for(i = 0; i < size; i++) { if(matrix[front][i] && !visited[i]) { visited[i] = 1; queue = enqueue(queue, i); } } } }
int main(){ int n; scanf("%d", &n); while(n--){ char input[100]; scanf("%s", input); if(strcmp(input, "push") == 0){ int tmp; scanf("%d", &tmp); enqueue(tmp); } else if(strcmp(input, "pop") == 0){ if(!empty()) printf("%d\n", dequeue()); else printf("%d\n", -1); } else if(strcmp(input, "size") == 0){ printf("%d\n", get_size()); } else if(strcmp(input, "empty") == 0){ printf("%d\n", empty()); } else if(strcmp(input, "front") == 0){ if(!empty()) printf("%d\n", get_front()); else printf("%d\n", -1); } else if(strcmp(input, "back") == 0){ if(!empty()) printf("%d\n", get_back()); else printf("%d\n", -1); } } return 0; }
void print_ttob(TreeNode *pRoot) { if(pRoot == NULL) { return ; } push(pRoot); TreeNode *pTemp = NULL; while(!empty()) { pTemp = get_front(); pop(); printf("%d ",pTemp->iVal); if(pTemp->pLeft) { push(pTemp->pLeft); } if(pTemp->pRight) { push(pTemp->pRight); } } printf("\n"); }
Inst *Codegen_C::scheduling( Vec<Expr> out ) { // update inst->when for( Expr inst : out ) inst->update_when( BoolOpSeq( True() ) ); // get the front ++Inst::cur_op_id; Vec<Expr> front; for( Expr inst : out ) get_front( front, inst ); ++Inst::cur_op_id; for( Expr inst : front ) inst->op_id = Inst::cur_op_id; // go to the roots Inst *beg = 0, *end; ++Inst::cur_op_id; while ( front.size() ) { // try to find an instruction with the same condition set or an inst that is not going to write anything Inst *inst = 0; for( int i = 0; i < front.size(); ++i ) { if ( front[ i ]->when->always( false ) ) { front.remove_unordered( i-- ); continue; } if ( front[ i ]->when->always( true ) ) { inst = front[ i ].inst; front.remove_unordered( i ); break; } } // if not possible to do more without a condition if ( not inst ) { if ( not front.size() ) break; // try to find the best condition to move forward std::map<BoolOpSeq,int> possible_conditions; for( int i = 0; i < front.size(); ++i ) { Vec<BoolOpSeq> pc = front[ i ]->when->common_terms(); PRINT( *front[ i ]->when ); PRINT( pc.size() ); for( int c = 0; c < pc.size(); ++c ) std::cout << " " << pc[ c ]; std::cout << "\n"; for( BoolOpSeq &item : pc ) ++possible_conditions[ item ]; } int best_score = -1; BoolOpSeq best_item; for( const std::pair<BoolOpSeq,int> &p : possible_conditions ) { if ( best_score < p.second ) { best_score = p.second; best_item = p.first; } } // start the input list with the conditions std::map<Inst *,OutCondFront> outputs; // inst to replace -> replacement values + IfOut pos std::map<Expr,int> inputs; std::set<Expr> deps; inputs[ best_item.expr() ] = 0; // get a front of instructions that must be done under the condition `cond` Vec<Expr> ok_we_inp = extract_inst_that_must_be_done_if( outputs, inputs, deps, front, best_item , 1 ); Vec<Expr> ko_we_inp = extract_inst_that_must_be_done_if( outputs, inputs, deps, front, not best_item, 0 ); // for( std::pair<Expr,int> i : inputs ) // std::cout << " inp=" << *i.first << " num=" << i.second << std::endl; // for( std::pair<Inst *,OutCondFront> o : outputs ) // std::cout << " to_be_repl=" << *o.first << "\n ok=" << o.second.inp[ 1 ] << "\n ko=" << o.second.inp[ 0 ] << "\n num=" << o.second.num_in_outputs << std::endl; Expr if_inp_ok = make_if_inp( inputs, deps, ok_we_inp ); Expr if_inp_ko = make_if_inp( inputs, deps, ko_we_inp ); Expr if_out_ok = make_if_out( outputs, 1 ); Expr if_out_ko = make_if_out( outputs, 0 ); // complete the If instruction Vec<Expr> inp( Size(), inputs.size() ); for( std::pair<Expr,int> i : inputs ) inp[ i.second ] = i.first; Expr if_expr = if_inst( inp, if_inp_ok, if_inp_ko, if_out_ok, if_out_ko ); *if_expr->when = BoolOpSeq( True() ); // use the outputs of the if instruction Vec<Expr> if_out_sel( Size(), outputs.size() ); for( int i = 0; i < if_out_sel.size(); ++i ) { if_out_sel[ i ] = get_nout( if_expr, i ); *if_out_sel[ i ]->when = BoolOpSeq( True() ); } for( std::pair<Inst *,OutCondFront> o : outputs ) for( Inst::Parent &p : o.first->par ) if ( p.ninp >= 0 ) p.inst->mod_inp( if_out_sel[ o.second.num_in_outputs ], p.ninp ); else p.inst->mod_dep( if_out_sel[ o.second.num_in_outputs ], o.first ); // add dep to the if instruction for( Expr d : deps ) if_expr->add_dep( d ); // push if_expr in the front // if_expr->op_id = Inst::cur_op_id - 1; // front << if_expr; inst = if_expr.inst; } // register inst->op_id = Inst::cur_op_id; // say that it's done if ( not beg ) { beg = inst; end = inst; } else { end->next_sched = inst; inst->prev_sched = end; end = inst; } // update the front for( Inst::Parent &p : inst->par ) { if ( ready_to_be_scheduled( p.inst ) ) { p.inst->op_id = Inst::cur_op_id - 1; // -> in the front front << p.inst; } } } // delayed operation (ext blocks) for( Inst *inst = beg; inst; inst = inst->next_sched ) { // schedule sub block (ext instructions) for( int ind = 0; ind < inst->ext_disp_size(); ++ind ) { Inst *ext_beg = scheduling( inst->ext[ ind ] ); ext_beg->par_ext_sched = inst; inst->ext_sched << ext_beg; } // add internal break or continue if necessary // CC_SeqItemBlock *b[ s ]; // for( int i = 0; i < s; ++i ) // b[ i ] = ne->ext[ i ].ptr(); // ne->expr->add_break_and_continue_internal( b ); } return beg; }
void LockFlyer::move(Map *map) { Monster::move(map); if (m_hit == HitOne) { if (m_hit_timer.expired(get_attribute("hit_time"))) { m_dx = 0; reset_hit(); } else { // Move backwards m_dx = get_attribute("move_speed"); // Check for collision with map check_behind(map); // Right of player if (get_reference() == Right) { m_x -= m_dx; } else { m_x += m_dx; } } } switch(m_action) { case Still: if (m_hit == HitNone) { if (m_attack_timer.check(get_attribute("attack_timer"))) { const Sprite *spr = get_sprite(); int dist = get_attribute("attack_distance"); int x = m_xref - get_front(); int y = m_yref - (get_y() + spr->get_height() / 2); if (x * x + y * y < dist * dist) { m_attack_timer.reset(); set_move_dir(); m_lock_y = m_yref + spr->get_height() / 2; } } } break; case Move: if (m_hit == HitNone) { const Sprite *spr = get_sprite(); if (abs(m_lock_y - m_y) > get_attribute("move_speed")) { if (m_y < m_lock_y) { m_vertical_dir = VerticalDown; } else if (m_y > m_lock_y) { m_vertical_dir = VerticalUp; } } else { m_vertical_dir = VerticalNone; } // Move if (m_vertical_dir == VerticalDown) { m_dy = get_attribute("move_speed"); check_below(map); if (!m_dy) { set_action(Still); } else { m_y += m_dy; } } else if (m_vertical_dir == VerticalUp) { m_dy = get_attribute("move_speed"); check_above(map); if (!m_dy) { set_action(Still); } else { m_y -= m_dy; } } else { m_dx = get_attribute("move_speed"); face_reference(get_attribute("turn_width")); check_ahead(map); if (!m_dx) { set_action(Still); } else { if (m_dir == Right) { m_x += m_dx; } else if (m_dir == Left) { m_x -= m_dx; } } } animate_move(); } break; default: break; } }
void Player::mix() { if (!playing) return; mix_events(get_front(), PreMixSize); }
bool push(const T &node) { if (!node.valid()) return false; bool proceeded = false; Lock(); { typename NodeListT::iterator it; it = std::find(InternalList.begin(), InternalList.end(), node); if (it != InternalList.end()) { //既存なら最後尾へ T mnode(*it); InternalList.erase(it); mnode.marge(node); mnode.lastlink = time(NULL); InternalList.push_back(mnode); proceeded = true; } else if (InternalList.size() < Capacity) { //リストに余裕があるなら最後尾に追加 T newnode(node); newnode.lastlink = time(NULL); InternalList.push_back(newnode); proceeded = true; } #if !USEPING else { pop_front(); T newnode(node); newnode.lastlink = time(NULL); InternalList.push_back(newnode); proceeded = true; } #endif } Unlock(); #if USEPING if (proceeded) return true; //リストの一番上のノード=最古ノードの生存確認 T head; get_front(head); bool alive = ping(head); if (alive) { //最古ノードが生きている:最古ノードを最後尾へ //※対象ノードは追加しない pop_front(); head.lastlink = time(NULL); Lock(); InternalList.push_back(head); Unlock(); } else { //最古ノードが死んでいる:対象ノードを最後尾に追加 pop_front(); T newnode(node); newnode.lastlink = time(NULL); Lock(); InternalList.push_back(newnode); Unlock(); } #endif return true; };