Exemplo n.º 1
0
	void sequence::advance()
	{
		assert (is_item());

		if(!is_item())
		{
			current_index = used;
		}

		current_index++;
	}
Exemplo n.º 2
0
 void sequence::advance()
 {
    if(is_item())
      current_index++;
    else
      current_index = used;
 }
Exemplo n.º 3
0
size_t inventory_entry::get_available_count() const {
    if( is_item() && get_stack_size() == 1 ) {
        return get_item().count_by_charges() ? get_item().charges : 1;
    } else {
        return get_stack_size();
    }
}
Exemplo n.º 4
0
 sequence::value_type sequence::current() const
 {
    if(is_item())
  	  return data[current_index - 1];
    else
  	  return 0;
 }
   void sequence::remove_current()

   // this function removes the user-entered value from the sequence and
   // sets the next item to be the current item; if the user-entered value
   // was already at the end of the sequence, then there is no longer a 
   // current value;
   {
      // PRE-CONDITION: is_item returns true	  
      if( is_item() )
      {
         // CASE 1: if the current item is the last one in the sequence,
         // effectively remove it by decrementing used and setting the 
         // current_index = used (i.e., there's no longer a current item)
         if( (current_index + 1) == used )          
         {                                   
            used--;
            current_index = used;
         }
         // CASE 2: the current item is not the last one in the sequence
         else
         {
            size_type i;
            for( i = current_index; i < used; i++ )
            {
               data[i] = data[i+1];
            } 
            used--;
         }
      }
   }
Exemplo n.º 6
0
/**
 * @brief Registers a timer into a context (table or a userdata).
 * @param timer A timer.
 * @param context_index Index of the table or userdata in the stack.
 * @param callback_index Index of the function to call when the timer finishes.
 */
void LuaContext::add_timer(Timer* timer, int context_index, int callback_index) {

  const void* context;
  if (lua_type(l, context_index) == LUA_TUSERDATA) {
    ExportableToLua** userdata = static_cast<ExportableToLua**>(
        lua_touserdata(l, context_index));
    context = *userdata;
  }
  else {
    context = lua_topointer(l, context_index);
  }

  lua_pushvalue(l, callback_index);
  int callback_ref = create_ref();

  timers[timer].callback_ref = callback_ref;
  timers[timer].context = context;

  Game* game = main_loop.get_game();
  if (game != NULL) {
    // We are during a game: depending on the timer's context,
    // when the map is suspended, also suspend the timer or not.
    if (is_map(l, context_index)
        || is_entity(l, context_index)
        || is_item(l, context_index)) {
      timer->set_suspended_with_map(true);
    }
  }
  timer->increment_refcount();
}
 void sequence::move_back()
 {
    assert( is_item() );
    if (current_index == 0)
       current_index = used;
    else
       --current_index;
 }
   void sequence::insert(const value_type& entry)

   // this function inserts a user-entered value into the sequence before
   // the current item; if there was no current item, the new entry goes
   // at the front of the sequence; in either case, the entry becomes the
   // new current item
   {
      // resize array if capacity is too small for entry 
      if( (used + 1) > capacity )
      {
         size_type nuCapacity = capacity * 1.25;
                                                
         if( nuCapacity == capacity )
            nuCapacity = capacity + 1;

         resize(nuCapacity);
      }


      // insert the entry value into the array:

      // CASE 1: if there is no current item because the array 
      // is empty, then put the entry in the first index
      // NOTE: in this case, current_index is already 0
      if( used == 0 )                
      {
         data[current_index] = entry;               
         used++;
      }

      // CASE 2: if array is not empty, then insert entry before
      // the current item; if there is no current item, then 
      // insert entry at front of sequence;
      // METHOD: beginning at current item (if there is one) 
      // or at index[0] (if there's no current item), scoot the 
      // elements to the right by one index, then insert the
      // entry value into the hole created by the shift
      // NOTE: the newly inserted item is now the current item
      else                                 
      {
         size_type END;
         if( is_item() )                  // set END = current item
            END = current_index;          // if there is one   
         else
         {
            END = 0;                      // else END = 0 = insertion point 
            current_index = END;				 
		   }
		   
         size_type i;
         for( i = used; i > END; i-- )
         {
            data[i] = data[i-1];
         }
         data[END] = entry;
         used++;
      }
}
   void sequence::remove_current()
   {
      assert( is_item() );

      size_type i;

      for (i = current_index + 1; i < used; ++i)
         data[i - 1] = data[i];
      --used;
   }
Exemplo n.º 10
0
/**
 * @brief Registers a timer into a context (table or a userdata).
 * @param timer A timer.
 * @param context_index Index of the table or userdata in the stack.
 * @param callback_index Index of the function to call when the timer finishes.
 */
void LuaContext::add_timer(Timer* timer, int context_index, int callback_index) {

  const void* context;
  if (lua_type(l, context_index) == LUA_TUSERDATA) {
    ExportableToLua** userdata = static_cast<ExportableToLua**>(
        lua_touserdata(l, context_index));
    context = *userdata;
  }
  else {
    context = lua_topointer(l, context_index);
  }

  lua_pushvalue(l, callback_index);
  int callback_ref = create_ref();

#ifndef NDEBUG
  // Sanity check: check the uniqueness of the ref.
  std::map<Timer*, LuaTimerData>::iterator it;
  for (it = timers.begin(); it != timers.end(); ++it) {
    if (it->second.callback_ref == callback_ref) {
      Debug::die(StringConcat() << "Callback ref " << callback_ref
            << " is already used by a timer (duplicate luaL_unref?)");
    }
  }
#endif

  Debug::check_assertion(timers.find(timer) == timers.end(),
      "Duplicate timer in the system");

  timers[timer].callback_ref = callback_ref;
  timers[timer].context = context;

  Game* game = main_loop.get_game();
  if (game != NULL) {
    // We are during a game: depending on the timer's context,
    // suspend the timer or not.
    if (is_map(l, context_index)
        || is_entity(l, context_index)
        || is_item(l, context_index)) {

      // By default, we want the timer to be automatically suspended when a
      // camera movement, a dialog or the pause menu starts.
      timer->set_suspended_with_map(true);

      // But in the initial state, we override that rule.
      // We initially suspend the timer only during a dialog.
      // In particular, we don't want to suspend timers created during a
      // camera movement.
      // This would be very painful for users.
      bool initially_suspended = game->is_dialog_enabled();
      timer->set_suspended(initially_suspended);
    }
  }
  timer->increment_refcount();
}
Exemplo n.º 11
0
	void sequence::remove_current()
	{
		assert (is_item());

		for (size_type i = current_index; i < used - 1; i++)
		{
			data[i] = data[i+1];
		}

		used--;
	}
Exemplo n.º 12
0
 void sequence::remove_current()
 {
    assert(is_item());
    if (current_index == used-1)
        --used;
    else
    {
       for (size_type i = current_index; i < used-1; ++i)
           data[i] = data[i+1];
       --used;
    }
 }
Exemplo n.º 13
0
 void sequence::attach(const value_type& entry)
 {
    if (used == capacity)
       resize(capacity * 1.25);
    if (is_item())
    {
       advance();
       for (size_type i = used; i > current_index; i--)
          data[i] = data[i-1];
    }
    data[current_index] = entry;
    ++used;
 }
Exemplo n.º 14
0
    /**
     *  Vertex update function.
     */
    void update(graphchi_vertex<VertexDataType, edge_data> &v, graphchi_context &gcontext) {
        if (debug)
            printf("Entered iteration %d with %d\n", gcontext.iteration, is_item(v.id()) ? (v.id() - M + 1): v.id());

        /* Even iteration numbers:
         * 1) load a subset of users into memory (pivots)
         * 2) Find which subset of items is connected to the users
         */
        if (gcontext.iteration % 2 == 0) {
            if (adjcontainer->is_pivot(v.id()) && is_user(v.id())) {
                adjcontainer->load_edges_into_memory(v);
                if (debug)
                    printf("Loading pivot %d intro memory\n", v.id());
            }
        }
        /* odd iteration number:
        * 1) For any item connected to a pivot item
        *       compute itersection
        */
        else {
            assert(is_item(v.id()));

            for (int i=0; i< v.num_edges(); i++) {
                if (!adjcontainer->is_pivot(v.edge(i)->vertex_id()))
                    continue;
                if (debug)
                    printf("comparing user pivot %d to item %d\n", v.edge(i)->vertex_id()+1 , v.id() - M + 1);

                adjcontainer->compute_ratings(v, v.edge(i)->vertex_id(), v.edge(i)->get_data().up_weight);
                item_pairs_compared++;

                if (item_pairs_compared % 1000000 == 0)
                    Rcpp::Rcout<< std::setw(10) << mytimer.current_time() << ")  " << std::setw(10) << item_pairs_compared << " pairs compared " << std::endl;
            }
        }//end of iteration % 2 == 1
    }//end of update function
Exemplo n.º 15
0
   void sequence::advance()
   {
      if(is_item())
      {
    	  if(used == current_index)
    		  current_index = 0;
    	  else
    		  current_index++;
      }
      else
      {
    	  current_index = 0;
    	  cout << "No current item exits." << endl;
      }

   }
Exemplo n.º 16
0
    void sequence::insert(const value_type& entry)
    {
        if(!is_item())
        {
            current_index = 0;
        }

        for (size_type i = used; i > current_index; i--)
        {
            data[i] = data[i - 1];
        }

        data[current_index] = entry;
        used++;

        showIt();
    }
Exemplo n.º 17
0
 void sequence::remove_current()
 {
    if(is_item())
    {
  	  if(used == current_index)
  	  {   
  		   used--;
  	      current_index = 0;
  	  }
  	  else
  	  {
  		  for(size_type i = current_index; i < used; ++i)
  			   data[i - 1] = data[i];
  		  used--;
  	  }
    }
 }
Exemplo n.º 18
0
 void sequence::remove_current()
 {
    if(!is_item())
      return;
    
    if(current_index == used-1)
    {
        --used;
        current_index = used;
        return;
    }
      
    for(size_type count = current_index; count < used; count++)
       data[count] = data[count+1];
    
    --used;
 }
Exemplo n.º 19
0
int main( int argc, char **argv )
{
    FILE *ifp;
    FILE *ofp;
    char *check;
    int prefix_len;
    int enumflag;

    if( argc != 3 ) {
        fail( "mktrans <ytab-hfile> <xlat-hfile>" );
    }
    ifp = fopen( argv[1], "r" );
    if( ifp == NULL ) {
        fail( "cannot open input file '%s'", argv[1] );
    }
    ofp = fopen( argv[2], "w" );
    if( ofp == NULL ) {
        fail( "cannot open input file '%s'", argv[2] );
    }
    fprintf( ofp, "static unsigned char toYACC[256];\n" );
    fprintf( ofp, "static void createTable( void )\n{\n" );
    enumflag = 0;
    for(;;) {
        check = fgets( ibuff, sizeof( ibuff ), ifp );
        if( check == NULL )
            break;
        if( chk_enum( enumflag ) ) {
            if( enumflag )
                break;
            enumflag = 1;
            continue;
        }
        prefix_len = is_item( enumflag );
        if( prefix_len == 0 )
            continue;
        get_mname_mvalue( prefix_len );
        if( mname_suffix( "_NAME" ) || mname_suffix( "_SPECIAL" ) )
            continue;
        fprintf( ofp, "    toYACC[T_%s] = %s;\n", &mname[2], mvalue );
    }
    fprintf( ofp, "}\n" );
    fclose( ifp );
    fclose( ofp );
    return( EXIT_SUCCESS );
}
   void sequence::advance()

   // this function advances the index # of current_index
   {
      if( is_item() )
      {      
         
         if( (current_index+1) == used )  // check if current item is the
         {                                // last one in the sequence; 
            current_index = used;         // if so, there's no longer a 
         }                                // current item
         
         else
            current_index++;              // else the new current item is 
                                          // now the one immediately after 
                                          // the original current item
      }
   }
Exemplo n.º 21
0
    void sequence::attach(const value_type& entry)
    {
        if(!is_item())
        {
            current_index = used - 1;
        }

        current_index++;

        for (size_type i = used; i > current_index + 1; i--)
        {
            data[i] = data[i - 1];
        }

        data[current_index] = entry;
        used++;

        showIt();
    }
Exemplo n.º 22
0
Arquivo: parse.c Projeto: elboza/WiCE
char* get_arg(struct expr_node **expr,char *p,int line_count)
{
	int m_type;
	struct expr_node *new_expr,*new_expr2,*save_expr,*save_tree;
	char s1[MAXSTR];
	p=get_token(p);
	m_type=is_item(line_count);
	new_expr=(struct expr_node*)malloc(sizeof(struct expr_node));
	if(new_expr==NULL)
	{ sprintf(s1,"at line %d, error malloc exr_node",line_count);die(s1);}
	new_expr->type=m_type;
	strncpy(new_expr->str,my_token,MAXSTR);
	new_expr->left=NULL;
	new_expr->right=NULL;
	p=skip_space(p);
	if((*p=='\n')||(*p==',')|| (is_bool_op(p,line_count)))
	{
		*expr=new_expr;
		return p;
	}
	p=get_token(p);
	m_type=is_op(line_count);
	new_expr2=(struct expr_node*)malloc(sizeof(struct expr_node));
	if(new_expr2==NULL)
	{ sprintf(s1,"at line %d, error malloc exr_node",line_count);die(s1);}
	new_expr2->type=m_type;
	strncpy(new_expr2->str,my_token,MAXSTR);
	new_expr2->left=new_expr;
	new_expr2->right=NULL;
	*expr=new_expr2;
	p=skip_space(p);
	p=get_arg(&(new_expr2->right),p,line_count);
	if((new_expr2->type<new_expr2->right->type)&&(new_expr2->type<3)&&(new_expr2->right->type<3))
	{
		save_expr=new_expr2->right;
		save_tree=new_expr2->right->left;
		new_expr2->right->left=new_expr2;
		save_expr->left->right=save_tree;
		*expr=save_expr;
	}
	return p;
}
Exemplo n.º 23
0
	void sequence::insert(const value_type& entry)
	{
		if(used >= capacity)
			resize(size_type(capacity * 1.5) + 1);

		if (is_item() == false)
		{
			current_index = 0;
		}

		for (size_type i = used; i > current_index; i--)
		{
			data[i]= data[i - 1];
		}

		data[current_index]= entry;


		used++;
	}
Exemplo n.º 24
0
 void sequence::insert(const value_type& entry)
 {
    if (used == capacity)
       resize(capacity * 1.25);
    if (is_item())
    {
       for (size_type i = used; i > current_index; i--)
          data[i] = data[i-1];
    }
    else
    {
       if (current_index>0)
       {
          start();
          for (size_type i= used; i> current_index; i--)
              data[i]= data[i-1];
       }
    }
    data[current_index] = entry;
    used++;
 }
Exemplo n.º 25
0
	void sequence::attach(const value_type& entry)
	{
		if(used >= capacity)
			resize(size_type(capacity * 1.5) + 1);
		if(is_item())
		{
			current_index++;
		}
		else
		{
			current_index = used;
		}

		for (size_type i = used; i > current_index; i--)
		{
			data[i] = data[i - 1];
		}

		data[current_index] = entry;

		used++;
	}
   void sequence::add(const value_type& entry)
   {
      assert( size() < CAPACITY );

      size_type i;

      if ( ! is_item() )
      {
         if (used > 0)
            for (i = used; i >= 1; --i)
               data[i] = data[i - 1];
         data[0] = entry;
         current_index = 0;
      }
      else
      {
         ++current_index;
         for (i = used; i > current_index; --i)
            data[i] = data[i - 1];
         data[current_index] = entry;
      }
      ++used;
   }
   sequence::value_type sequence::current() const
   {
      assert( is_item() );

      return data[current_index];
   }
   void sequence::attach(const value_type& entry)

   // this function inserts a user-entered value into the sequence after
   // the current item; if there was no current item, the new entry goes
   // at the end of the sequence; in either case, the entry becomes the
   // new current item
   {
      // resize array if capacity is too small for entry 
      if( (used + 1) > capacity )
      {
         size_type nuCapacity = capacity * 1.25;
                                                
         if( nuCapacity == capacity )
            nuCapacity = capacity + 1;

         resize(nuCapacity);
      }


      // attach the entry value into the array:

      // CASE 1: if there is no current item because the array 
      // is empty, then put the entry in the first index
      // NOTE: in this case, current_index is already 0
      if( used == 0 )                
      {
         data[current_index] = entry;               
         used++;
      }
      
      // CASE 2: if array is not empty and there is no current
      // item, then insert entry at end of sequence and make
      // it the current item
      else if( !is_item() )
      {
         data[used] = entry;        
         used++;
         current_index = (used-1);
      }

      // CASE 3: if array is not empty and current item exists,
      // then attach entry after the current item and set the
      // attached entry value to be the new current item
      // METHOD: beginning at current item + 1, scoot the 
      // elements to the right by one index, then insert the
      // entry value into the hole created by the shift, then
      // increment current_index
      else                                 
      {
         const size_type START = used;       // new final index 
         size_type END = (current_index+1);  // if there is one   
         size_type here = START;
         size_type i;
         for( i = START; i > END; i-- )
         {
            data[here] = data[here-1];
            here--;
         }
         data[END] = entry;
         used++;
         current_index++;
      }
   }
Exemplo n.º 29
0
/**
 * \brief Registers a timer into a context (table or a userdata).
 * \param timer A timer.
 * \param context_index Index of the table or userdata in the stack.
 * \param callback_ref Lua ref to the function to call when the timer finishes.
 */
void LuaContext::add_timer(
    const TimerPtr& timer,
    int context_index,
    const ScopedLuaRef& callback_ref
) {
  const void* context;
  if (lua_type(l, context_index) == LUA_TUSERDATA) {
    ExportableToLuaPtr* userdata = static_cast<ExportableToLuaPtr*>(
        lua_touserdata(l, context_index)
    );
    context = userdata->get();
  }
  else {
    context = lua_topointer(l, context_index);
  }

  callback_ref.push();

#ifndef NDEBUG
  // Sanity check: check the uniqueness of the ref.
  for (const auto& kvp: timers) {
    if (kvp.second.callback_ref.get() == callback_ref.get()) {
      std::ostringstream oss;
      oss << "Callback ref " << callback_ref.get()
          << " is already used by a timer (duplicate luaL_unref?)";
      Debug::die(oss.str());
    }
  }
#endif

  Debug::check_assertion(timers.find(timer) == timers.end(),
      "Duplicate timer in the system");

  timers[timer].callback_ref = callback_ref;
  timers[timer].context = context;

  Game* game = main_loop.get_game();
  if (game != nullptr) {
    // We are during a game: depending on the timer's context,
    // suspend the timer or not.
    if (is_map(l, context_index)
        || is_entity(l, context_index)
        || is_item(l, context_index)) {

      bool initially_suspended = false;

      // By default, we want the timer to be automatically suspended when a
      // camera movement, a dialog or the pause menu starts.
      if (!is_entity(l, context_index)) {
        // The timer normally gets suspended/resumed with the map.
        timer->set_suspended_with_map(true);

        // But in the initial state, we override that rule.
        // We initially suspend the timer only during a dialog.
        // In particular, we don't want to suspend timers created during a
        // camera movement.
        // This would be very painful for users.
        initially_suspended = game->is_dialog_enabled();
      }
      else {
        // Entities are more complex: they also get suspended when disabled
        // and when far from the camera. Therefore, they don't simply follow
        // the map suspended state.
        EntityPtr entity = check_entity(l, context_index);
        initially_suspended = entity->is_suspended() || !entity->is_enabled();
      }

      timer->set_suspended(initially_suspended);
    }
  }
}
Exemplo n.º 30
0
/**
 * \brief Registers a timer into a context (table or a userdata).
 * \param timer A timer.
 * \param context_index Index of the table or userdata in the stack.
 * \param callback_index Index of the function to call when the timer finishes.
 */
void LuaContext::add_timer(Timer* timer, int context_index, int callback_index) {

  const void* context;
  if (lua_type(l, context_index) == LUA_TUSERDATA) {
    ExportableToLua** userdata = static_cast<ExportableToLua**>(
        lua_touserdata(l, context_index));
    context = *userdata;
  }
  else {
    context = lua_topointer(l, context_index);
  }

  lua_pushvalue(l, callback_index);
  int callback_ref = create_ref();

#ifndef NDEBUG
  // Sanity check: check the uniqueness of the ref.
  std::map<Timer*, LuaTimerData>::iterator it;
  for (it = timers.begin(); it != timers.end(); ++it) {
    if (it->second.callback_ref == callback_ref) {
      std::ostringstream oss;
      oss << "Callback ref " << callback_ref
          << " is already used by a timer (duplicate luaL_unref?)";
      Debug::die(oss.str());
    }
  }
#endif

  Debug::check_assertion(timers.find(timer) == timers.end(),
      "Duplicate timer in the system");

  timers[timer].callback_ref = callback_ref;
  timers[timer].context = context;

  Game* game = main_loop.get_game();
  if (game != NULL) {
    // We are during a game: depending on the timer's context,
    // suspend the timer or not.
    if (is_map(l, context_index)
        || is_entity(l, context_index)
        || is_item(l, context_index)) {

      bool initially_suspended = false;

      // By default, we want the timer to be automatically suspended when a
      // camera movement, a dialog or the pause menu starts.
      if (!is_entity(l, context_index)) {
        // The timer normally get suspended/unsuspend with the map.
        timer->set_suspended_with_map(true);

        // But in the initial state, we override that rule.
        // We initially suspend the timer only during a dialog.
        // In particular, we don't want to suspend timers created during a
        // camera movement.
        // This would be very painful for users.
        initially_suspended = game->is_dialog_enabled();
      }
      else {
        // Entities are more complex: they also get suspended when disabled
        // and when far from the camera. Therefore, they don't simply follow
        // the map suspended state.
        const MapEntity& entity = check_entity(l, context_index);
        initially_suspended = entity.is_suspended() || !entity.is_enabled();
      }

      timer->set_suspended(initially_suspended);
    }
  }
  RefCountable::ref(timer);
}