示例#1
0
/*************************************************************************
	Handler for mouse move events
*************************************************************************/
void FrameWindow::onMouseMove(MouseEventArgs& e)
{
	// default processing (this is now essential as it controls event firing).
	Window::onMouseMove(e);

	// if we are not the window containing the mouse, do NOT change the cursor
	if (getGUIContext().getWindowContainingMouse() != this)
	{
		return;
	}

	if (isSizingEnabled())
	{
		Vector2f localMousePos(CoordConverter::screenToWindow(*this, e.position));

		if (d_beingSized)
		{
			SizingLocation dragEdge = getSizingBorderAtPoint(d_dragPoint);

			// calculate sizing deltas...
			float	deltaX = localMousePos.d_x - d_dragPoint.d_x;
			float	deltaY = localMousePos.d_y - d_dragPoint.d_y;

            URect new_area(d_area);
            bool top_left_sizing = false;
			// size left or right edges
			if (isLeftSizingLocation(dragEdge))
			{
				top_left_sizing |= moveLeftEdge(deltaX, new_area);
			}
			else if (isRightSizingLocation(dragEdge))
			{
				top_left_sizing |= moveRightEdge(deltaX, new_area);
			}

			// size top or bottom edges
			if (isTopSizingLocation(dragEdge))
			{
				top_left_sizing |= moveTopEdge(deltaY, new_area);
			}
			else if (isBottomSizingLocation(dragEdge))
			{
				top_left_sizing |= moveBottomEdge(deltaY, new_area);
			}

            setArea_impl(new_area.d_min, new_area.getSize(), top_left_sizing);
		}
		else
		{
			setCursorForPoint(localMousePos);
		}

	}

	// mark event as handled
	++e.handled;
}
示例#2
0
文件: dobj_menu.c 项目: nasa/QuIP
static COMMAND_FUNC( do_create_area )
{
	const char *area_name;
	long n;
	long siz;

	area_name = NAMEOF("name for this area");
	siz = (long) how_many("size of data area in bytes");
	n = (long) how_many("maximum number of data objects for this area");

	INSIST_POSITIVE_NUM(siz,"number of bytes","create_area");
	INSIST_POSITIVE_NUM(n,"maximum number of objects","create_area");

	curr_ap=new_area(area_name, (dimension_t) siz,(unsigned int)n);	// do_create_area
}
示例#3
0
void RegionsHierarchy::reload()
{
    Logger * log = &Logger::get("RegionsHierarchy");

    time_t new_modification_time = Poco::File(path).getLastModified().epochTime();
    if (new_modification_time <= file_modification_time)
        return;
    file_modification_time = new_modification_time;

    LOG_DEBUG(log, "Reloading regions hierarchy");

    const size_t initial_size = 10000;
    const size_t max_size = 15000000;

    RegionParents new_parents(initial_size);
    RegionParents new_city(initial_size);
    RegionParents new_country(initial_size);
    RegionParents new_area(initial_size);
    RegionParents new_district(initial_size);
    RegionParents new_continent(initial_size);
    RegionParents new_top_continent(initial_size);
    RegionPopulations new_populations(initial_size);
    RegionDepths  new_depths(initial_size);
    RegionTypes types(initial_size);

    DB::ReadBufferFromFile in(path);

    RegionID max_region_id = 0;
    while (!in.eof())
    {
        /** Our internal geobase has negative numbers,
            *  that means "this is garbage, ignore this row".
            */
        Int32 read_region_id = 0;
        Int32 read_parent_id = 0;
        Int8 read_type = 0;

        DB::readIntText(read_region_id, in);
        DB::assertChar('\t', in);
        DB::readIntText(read_parent_id, in);
        DB::assertChar('\t', in);
        DB::readIntText(read_type, in);

        /** Then there can be a newline (old version)
            *  or tab, the region's population, line feed (new version).
            */
        RegionPopulation population = 0;
        if (!in.eof() && *in.position() == '\t')
        {
            ++in.position();
            UInt64 population_big = 0;
            DB::readIntText(population_big, in);
            population = population_big > std::numeric_limits<RegionPopulation>::max()
                ? std::numeric_limits<RegionPopulation>::max()
                : population_big;
        }
        DB::assertChar('\n', in);

        if (read_region_id <= 0 || read_type < 0)
            continue;

        RegionID region_id = read_region_id;
        RegionID parent_id = 0;

        if (read_parent_id >= 0)
            parent_id = read_parent_id;

        RegionType type = read_type;

        if (region_id > max_region_id)
        {
            if (region_id > max_size)
                throw DB::Exception("Region id is too large: " + DB::toString(region_id) + ", should be not more than " + DB::toString(max_size));

            max_region_id = region_id;

            while (region_id >= new_parents.size())
            {
                new_parents.resize(new_parents.size() * 2);
                new_populations.resize(new_parents.size());
                types.resize(new_parents.size());
            }
        }

        new_parents[region_id] = parent_id;
        new_populations[region_id] = population;
        types[region_id] = type;
    }

    new_parents        .resize(max_region_id + 1);
    new_city        .resize(max_region_id + 1);
    new_country        .resize(max_region_id + 1);
    new_area        .resize(max_region_id + 1);
    new_district    .resize(max_region_id + 1);
    new_continent    .resize(max_region_id + 1);
    new_top_continent.resize(max_region_id + 1);
    new_populations .resize(max_region_id + 1);
    new_depths        .resize(max_region_id + 1);
    types            .resize(max_region_id + 1);

    /// prescribe the cities and countries for the regions
    for (RegionID i = 0; i <= max_region_id; ++i)
    {
        if (types[i] == REGION_TYPE_CITY)
            new_city[i] = i;

        if (types[i] == REGION_TYPE_AREA)
            new_area[i] = i;

        if (types[i] == REGION_TYPE_DISTRICT)
            new_district[i] = i;

        if (types[i] == REGION_TYPE_COUNTRY)
            new_country[i] = i;

        if (types[i] == REGION_TYPE_CONTINENT)
        {
            new_continent[i] = i;
            new_top_continent[i] = i;
        }

        RegionDepth depth = 0;
        RegionID current = i;
        while (true)
        {
            ++depth;

            if (depth == std::numeric_limits<RegionDepth>::max())
                throw Poco::Exception("Logical error in regions hierarchy: region " + DB::toString(current) + " possible is inside infinite loop");

            current = new_parents[current];
            if (current == 0)
                break;

            if (current > max_region_id)
                throw Poco::Exception("Logical error in regions hierarchy: region " + DB::toString(current) + " (specified as parent) doesn't exist");

            if (types[current] == REGION_TYPE_CITY)
                new_city[i] = current;

            if (types[current] == REGION_TYPE_AREA)
                new_area[i] = current;

            if (types[current] == REGION_TYPE_DISTRICT)
                new_district[i] = current;

            if (types[current] == REGION_TYPE_COUNTRY)
                new_country[i] = current;

            if (types[current] == REGION_TYPE_CONTINENT)
            {
                if (!new_continent[i])
                    new_continent[i] = current;
                new_top_continent[i] = current;
            }
        }

        new_depths[i] = depth;
    }

    parents.swap(new_parents);
    country.swap(new_country);
    city.swap(new_city);
    area.swap(new_area);
    district.swap(new_district);
    continent.swap(new_continent);
    top_continent.swap(new_top_continent);
    populations.swap(new_populations);
    depths.swap(new_depths);
}
示例#4
0
void RegionsHierarchy::reload()
{
    Logger * log = &Logger::get("RegionsHierarchy");

    if (!data_source->isModified())
        return;

    LOG_DEBUG(log, "Reloading regions hierarchy");

    const size_t initial_size = 10000;
    const size_t max_size = 15000000;

    RegionParents new_parents(initial_size);
    RegionParents new_city(initial_size);
    RegionParents new_country(initial_size);
    RegionParents new_area(initial_size);
    RegionParents new_district(initial_size);
    RegionParents new_continent(initial_size);
    RegionParents new_top_continent(initial_size);
    RegionPopulations new_populations(initial_size);
    RegionDepths  new_depths(initial_size);
    RegionTypes types(initial_size);

    RegionID max_region_id = 0;


    auto regions_reader = data_source->createReader(); 

    RegionEntry region_entry;
    while (regions_reader->readNext(region_entry))
    {
        if (region_entry.id > max_region_id)
        {
            if (region_entry.id > max_size)
                throw DB::Exception("Region id is too large: " + DB::toString(region_entry.id) + ", should be not more than " + DB::toString(max_size));

            max_region_id = region_entry.id;

            while (region_entry.id >= new_parents.size())
            {
                new_parents.resize(new_parents.size() * 2);
                new_populations.resize(new_parents.size());
                types.resize(new_parents.size());
            }
        }

        new_parents[region_entry.id] = region_entry.parent_id;
        new_populations[region_entry.id] = region_entry.population;
        types[region_entry.id] = region_entry.type;
    }

    new_parents      .resize(max_region_id + 1);
    new_city         .resize(max_region_id + 1);
    new_country      .resize(max_region_id + 1);
    new_area         .resize(max_region_id + 1);
    new_district     .resize(max_region_id + 1);
    new_continent    .resize(max_region_id + 1);
    new_top_continent.resize(max_region_id + 1);
    new_populations  .resize(max_region_id + 1);
    new_depths       .resize(max_region_id + 1);
    types            .resize(max_region_id + 1);

    /// prescribe the cities and countries for the regions
    for (RegionID i = 0; i <= max_region_id; ++i)
    {
        if (types[i] == RegionType::City)
            new_city[i] = i;

        if (types[i] == RegionType::Area)
            new_area[i] = i;

        if (types[i] == RegionType::District)
            new_district[i] = i;

        if (types[i] == RegionType::Country)
            new_country[i] = i;

        if (types[i] == RegionType::Continent)
        {
            new_continent[i] = i;
            new_top_continent[i] = i;
        }

        RegionDepth depth = 0;
        RegionID current = i;
        while (true)
        {
            ++depth;

            if (depth == std::numeric_limits<RegionDepth>::max())
                throw Poco::Exception("Logical error in regions hierarchy: region " + DB::toString(current) + " possible is inside infinite loop");

            current = new_parents[current];
            if (current == 0)
                break;

            if (current > max_region_id)
                throw Poco::Exception("Logical error in regions hierarchy: region " + DB::toString(current) + " (specified as parent) doesn't exist");

            if (types[current] == RegionType::City)
                new_city[i] = current;

            if (types[current] == RegionType::Area)
                new_area[i] = current;

            if (types[current] == RegionType::District)
                new_district[i] = current;

            if (types[current] == RegionType::Country)
                new_country[i] = current;

            if (types[current] == RegionType::Continent)
            {
                if (!new_continent[i])
                    new_continent[i] = current;
                new_top_continent[i] = current;
            }
        }

        new_depths[i] = depth;
    }

    parents.swap(new_parents);
    country.swap(new_country);
    city.swap(new_city);
    area.swap(new_area);
    district.swap(new_district);
    continent.swap(new_continent);
    top_continent.swap(new_top_continent);
    populations.swap(new_populations);
    depths.swap(new_depths);
}
示例#5
0
static void load_area( const char * name )
{
   lua_State *L = area_loader; //shortcut name
   int status;
   char filename[MAX_BUFFER];
   D_AREA *area;
   EVENT_DATA *event;
   
   log_string( "--Loading %s", name );
   snprintf( filename, MAX_BUFFER, "../areas/%s", name );

   if( ( status = luaL_loadfile( L, filename ) ) )
   {
      bug( "ERROR: Can not find area file %s(%s)", filename, lua_tostring( L, -1 ) );
      return;
   }
   
   if( lua_pcall( L, 0, 1, 0 ) )
   {
      bug( "ERROR: Unable to parse area file (%s)", lua_tostring( L, -1 ) );
      return;
   }
   
   if( ( area = new_area() ) == NULL )
   {
      bug( "ERROR: Unable to allocate memory for area." );
      return;
   }
   //load the area stats
   if( load_area_stats( L, area ) == FALSE ) //syntax errors in the area file
   {
      log_string( "----stats (failed)" );
      return;
   }
   else
   {
      log_string( "----stats" );
   }
   
   //load the actual rooms, stored in the table 'rooms'
   if( load_area_rooms( L, area ) == FALSE )
   {
      log_string( "----rooms(failed)" ); //failing room load == fail area load
      return;
   }
   else
   {
      log_string( "----rooms" );
   }
   
   //load the objects, stored in table 'objects'
   if( load_area_objects( L, area ) == FALSE )
   {
      log_string( "----objects(failed)" );
   }
   else
   {
      log_string( "----objects" );
   }
   
   //load the NPCs, stored in table 'mobiles'
   if( load_area_mobiles( L, area ) == FALSE )
   {
      log_string( "----mobiles(failed)" );
   }
   else
   {
      log_string( "----mobiles" );
   }
   
   //enqueue its first reset
   if( ( event = alloc_event() ) == NULL )
   {
      bug( "Error: (System) Unable to allocate memory for new event!" );
      exit( 1 );
   }
   event->fun = event_reset_area;
   event->type = EVENT_RESET_AREA;
   event->owner.dArea = area;
   add_event_game( event, area->reset_time * 60 * PULSES_PER_SECOND );
   
   return;
}
示例#6
0
int execve(char *name, char **argv, char **env)
{
  if(current->proc->flags & PROC_FLAG_DEBUG)
  {
    debug("[info]EXECVE(%s, %x, %x)\n", name, argv, env);
  }
  // Find the executable
  INODE executable = vfs_namei(name);
  if(!executable)
  {
    debug("[error] Executable %s not found.\n", name);
    errno = ENOENT;
    return -1;
  }
  if(is_elf(executable) != 2)
  {
    errno = ENOEXEC;
    debug("[error] Tried to load unexecutable file.\n");
    return -1;
  }

  // Save environment in kernel space
  unsigned int envc = 0;
  char **temp_env;
  if(env)
  {
    while(env[envc++]);

    temp_env = calloc(envc, sizeof(char *));

    unsigned int i = 0;
    while(env[i])
    {
      temp_env[i] = strdup(env[i]);
      i++;
    }
    temp_env[envc-1] = 0;
  }

  // Save arguments in kernel space
  unsigned int argc = 0;
  char **temp_argv;
  if(argv)
  {
    while(argv[argc++]);

    temp_argv = calloc(argc, sizeof(char *));

    unsigned int i = 0;
    while(argv[i])
    {
      temp_argv[i] = strdup(argv[i]);
      i++;
    }
    temp_argv[argc-1] = 0;
  }

  if(current->proc->cmdline)
    free(current->proc->cmdline);
  current->proc->cmdline = strdup(name);

  // Clear all process memory areas
  procmm_removeall(current->proc);

  // Reset signal handlers
  memset(current->proc->signal_handler, 0, sizeof(sig_t)*NUM_SIGNALS);
  memset(current->proc->signal_blocked, 0, NUM_SIGNALS);
  init_list(current->proc->signal_queue);

  // Load executable
  load_elf(executable);

  // Reset thread registers and state
  current->r.eax = current->r.ebx = current->r.ecx = current->r.edx = 0;

  // Add an area for the process stack
  new_area(current->proc, USER_STACK_TOP, USER_STACK_TOP, MM_FLAG_WRITE | MM_FLAG_GROWSDOWN | MM_FLAG_ADDONUSE, MM_TYPE_STACK);
  current->kernel_thread = (registers_t *)current;
  uint32_t *pos = (uint32_t *)USER_STACK_TOP; // uint32_t since the stack should be word alligned

  // Restore environment
  if (env)
  {
    pos = pos - envc*sizeof(char *)/sizeof(uint32_t) - 1;
    env = (char **)pos;
    int i = 0;
    while(temp_env[i])
    {
      pos = pos - strlen(temp_env[i])/sizeof(uint32_t) - 2;
      memcpy(pos, temp_env[i], strlen(temp_env[i])+1);
      env[i] = (char *)pos;
      i++;
    }
    env[envc-1] = 0;
  }

  // Restore arguments
  if(argv)
  {
    pos = pos - argc*sizeof(char *)/sizeof(uint32_t) - 1;
    argv = (char **)pos;
    int i = 0;
    while(temp_argv[i])
    {
      pos = pos - strlen(temp_argv[i])/sizeof(uint32_t) - 2;
      memcpy(pos, temp_argv[i], strlen(temp_argv[i])+1);
      argv[i] = (char *)pos;
      i++;
    }
    argv[argc-1] = 0;
  }

  pos = pos - 3;
  pos[0] = (uint32_t)argc-1;
  pos[1] = (uint32_t)argv;
  pos[2] = (uint32_t)env;

  current->r.useresp = current->r.ebp = (uint32_t)pos;
  current->r.ecx = (uint32_t)pos;

  errno = 0;
  return 0;
}