Пример #1
0
VOID Fini(INT32 code, VOID *v)
{
    std::cout << "Fini()" << std::endl;
    Json::Value cache_data(Json::arrayValue);
    Json::Value no_cache_data(Json::arrayValue);

    for (size_t i = 0; i < all_thread_data.size(); i++) {
      Json::Value threadData_Cache(Json::objectValue);
      threadData_Cache["reads"] = convert_uint64_map_to_json_value(all_thread_data[i]->page_count_read_with_cache);
      threadData_Cache["writes"] = convert_uint64_map_to_json_value(all_thread_data[i]->page_count_write_with_cache);
      cache_data.append(threadData_Cache);

      Json::Value threadData_noCache(Json::objectValue);
      threadData_noCache["reads"] = convert_uint64_map_to_json_value(all_thread_data[i]->page_count_read_without_cache);
      threadData_noCache["writes"] = convert_uint64_map_to_json_value(all_thread_data[i]->page_count_write_without_cache);
      no_cache_data.append(threadData_noCache);
    }

    Json::Value root(Json::objectValue);
    root["cache"] = cache_data;
    root["no_cache"] = no_cache_data;

    std::cout << "Writing to " << std::getenv("PINATRACE_OUTPUT_FILENAME") << std::endl;

    ofstream ofs(std::getenv("PINATRACE_OUTPUT_FILENAME"), ofstream::out);
    ofs << root << endl;
    ofs.close();
}
Пример #2
0
void zone_manager::add( const std::string &name, const zone_type_id &type,
                        const bool invert, const bool enabled, const tripoint &start, const tripoint &end,
                        std::shared_ptr<zone_options> options )
{
    zone_data new_zone = zone_data( name, type, invert, enabled, start,
                                    end, options );
    //the start is a vehicle tile with cargo space
    if( const cata::optional<vpart_reference> vp = g->m.veh_at( g->m.getlocal(
                start ) ).part_with_feature( "CARGO", false ) ) {
        // TODO:Allow for loot zones on vehicles to be larger than 1x1
        if( start == end && query_yn( _( "Bind this zone to the cargo part here?" ) ) ) {
            // TODO: refactor zone options for proper validation code
            if( type == zone_type_id( "FARM_PLOT" ) ) {
                popup( _( "You cannot add that type of zone to a vehicle." ), PF_NONE );
                return;
            }

            create_vehicle_loot_zone( vp->vehicle(), vp->mount(), new_zone );
            return;
        }
    }

    //Create a regular zone
    zones.push_back( new_zone );
    cache_data();
}
Пример #3
0
void zone_manager::add( const std::string &name, const std::string &type,
                        const bool invert, const bool enabled,
                        const tripoint &start, const tripoint &end )
{
    zones.push_back( zone_data( name, type, invert, enabled, start, end ) );
    cache_data();
}
Пример #4
0
void zone_manager::load_zones()
{
    std::string savefile = world_generator->active_world->world_path + "/" + base64_encode(
                               g->u.name ) + ".zones.json";

    read_from_file_optional( savefile, [&]( std::istream & fin ) {
        JsonIn jsin( fin );
        deserialize( jsin );
    } );

    cache_data();
}
Пример #5
0
static void FillDeformationCache(JsonNode& json_obj,
                          const std::string& key,
                          int start_time,
                          int end_time,
                          meshDisplacementCacheManager& cache_manager)
{
    JsonNode * base_obj =  GetJSONNodeFromKey(json_obj, key);

    cache_manager.init(start_time, end_time);
    
    for (JsonIterator it = JsonBegin(base_obj->value);
         it != JsonEnd(base_obj->value);
         ++it)
    {
        JsonNode * cur_node = *it;

        int cur_time = atoi(cur_node->key);
        std::vector<meshDisplacementCache> cache_list;
        
        for (JsonIterator mesh_it = JsonBegin(cur_node->value);
             mesh_it != JsonEnd(cur_node->value);
             ++mesh_it)
        {
            JsonNode * mesh_node = *mesh_it;
            
            std::string cur_name(mesh_node->key);
            
            meshDisplacementCache cache_data(cur_name);
            
            bool use_local_displacement = GetJSONNodeFromKey(*mesh_node, "use_local_displacements")->value.toBool();
            bool use_post_displacement = GetJSONNodeFromKey(*mesh_node, "use_post_displacements")->value.toBool();
            
            if(use_local_displacement) {
                std::vector<glm::vec2> read_pts = ReadJSONPoints2DVector(*mesh_node, "local_displacements");
                cache_data.setLocalDisplacements(read_pts);
            }
            
            if(use_post_displacement) {
                std::vector<glm::vec2> read_pts = ReadJSONPoints2DVector(*mesh_node, "post_displacements");
                cache_data.setPostDisplacements(read_pts);
            }
            
            cache_list.push_back(cache_data);
        }
        
        int set_index = cache_manager.getIndexByTime(cur_time);
        cache_manager.getCacheTable()[set_index] = cache_list;
    }
    
    cache_manager.makeAllReady();
}
Пример #6
0
void zone_manager::load_zones()
{
    std::string savefile = g->get_player_base_save_path() + ".zones.json";

    read_from_file_optional( savefile, [&]( std::istream & fin ) {
        JsonIn jsin( fin );
        deserialize( jsin );
    } );
    revert_vzones();
    added_vzones.clear();
    changed_vzones.clear();
    removed_vzones.clear();

    cache_data();
}
Пример #7
0
static void FillUVSwapCache(JsonNode& json_obj,
                            const std::string& key,
                            int start_time,
                            int end_time,
                            meshUVWarpCacheManager& cache_manager)
{
    JsonNode * base_obj =  GetJSONNodeFromKey(json_obj, key);

    cache_manager.init(start_time, end_time);
    
    for (JsonIterator it = JsonBegin(base_obj->value);
         it != JsonEnd(base_obj->value);
         ++it)
    {
        JsonNode * cur_node = *it;

        int cur_time = atoi(cur_node->key);
        std::vector<meshUVWarpCache> cache_list;
        
        for (JsonIterator uv_it = JsonBegin(cur_node->value);
             uv_it != JsonEnd(cur_node->value);
             ++uv_it)
        {
            JsonNode * uv_node = *uv_it;
            
            std::string cur_name(uv_node->key);

            meshUVWarpCache cache_data(cur_name);
            bool use_uv = GetJSONNodeFromKey(*uv_node, "enabled")->value.toBool();
            cache_data.setEnabled(use_uv);
            if(use_uv) {
                glm::vec2 local_offset = ReadJSONVec2(*uv_node, "local_offset");
                glm::vec2 global_offset = ReadJSONVec2(*uv_node, "global_offset");
                glm::vec2 scale = ReadJSONVec2(*uv_node, "scale");
                cache_data.setUvWarpLocalOffset(local_offset);
                cache_data.setUvWarpGlobalOffset(global_offset);
                cache_data.setUvWarpScale(scale);
            }
            
            cache_list.push_back(cache_data);
        }
        
        int set_index = cache_manager.getIndexByTime(cur_time);
        cache_manager.getCacheTable()[set_index] = cache_list;
    }
    
    cache_manager.makeAllReady();
}
Пример #8
0
static void FillOpacityCache(JsonNode& json_obj,
	const std::string& key,
	int start_time,
	int end_time,
	meshOpacityCacheManager& cache_manager)
{
	JsonNode * base_obj = GetJSONNodeFromKey(json_obj, key);

	cache_manager.init(start_time, end_time);

	if (base_obj == NULL)
	{
		return;
	}

	for (JsonIterator it = JsonBegin(base_obj->value);
		it != JsonEnd(base_obj->value);
		++it)
	{
		JsonNode * cur_node = *it;

		int cur_time = atoi(cur_node->key);
		std::vector<meshOpacityCache> cache_list;

		for (JsonIterator uv_it = JsonBegin(cur_node->value);
			uv_it != JsonEnd(cur_node->value);
			++uv_it)
		{
			JsonNode * opacity_node = *uv_it;

			std::string cur_name(opacity_node->key);

			meshOpacityCache cache_data(cur_name);
			float cur_opacity = (float)GetJSONNodeFromKey(*opacity_node, "opacity")->value.toNumber();
			cache_data.setOpacity(cur_opacity);

			cache_list.push_back(cache_data);
		}

		int set_index = cache_manager.getIndexByTime(cur_time);
		cache_manager.getCacheTable()[set_index] = cache_list;
	}

	cache_manager.makeAllReady();

}
Пример #9
0
static void FillBoneCache(JsonNode& json_obj,
                          const std::string& key,
                          int start_time,
                          int end_time,
                          meshBoneCacheManager& cache_manager)
{
    JsonNode * base_obj =  GetJSONNodeFromKey(json_obj, key);

    cache_manager.init(start_time, end_time);
    
    for (JsonIterator it = JsonBegin(base_obj->value);
         it != JsonEnd(base_obj->value);
         ++it)
    {
        JsonNode * cur_node = *it;

        int cur_time = atoi(cur_node->key);
        std::vector<meshBoneCache> cache_list;
        
        for (JsonIterator bone_it = JsonBegin(cur_node->value);
             bone_it != JsonEnd(cur_node->value);
             ++bone_it)
        {
            JsonNode * bone_node = *bone_it;
            
            std::string cur_name(bone_node->key);
            glm::vec4 cur_start_pt = ReadJSONVec4_2(*bone_node, "start_pt");
            glm::vec4 cur_end_pt = ReadJSONVec4_2(*bone_node, "end_pt");
            
            meshBoneCache cache_data(cur_name);
            cache_data.setWorldStartPt(cur_start_pt);
            cache_data.setWorldEndPt(cur_end_pt);
            
            cache_list.push_back(cache_data);
        }
        
        int set_index = cache_manager.getIndexByTime(cur_time);
        cache_manager.getCacheTable()[set_index] = cache_list;
    }
    
    cache_manager.makeAllReady();
}
Пример #10
0
static struct tarfile *
scan_tarfile(struct package *pkg, struct tarfile *last)
{
	char buf[512];
	struct tarfile *cur;
	off_t ofs;
	size_t sz;

	cur = (last != NULL) ? last->tf_next : pkg->pkg_first;
	if (cur == NULL) {
		ofs = (last != NULL) ? last->tf_ofs + last->tf_size :
		    pkg->pkg_ofs;
		ofs = (ofs + 0x1ff) & ~0x1ff;

		/* Check if we've reached EOF. */
		if (ofs < pkg->pkg_ofs) {
			errno = ENOSPC;
			return (NULL);
		}

		if (ofs != pkg->pkg_ofs) {
			if (last != NULL && pkg->pkg_ofs == last->tf_ofs) {
				if (cache_data(last) == -1)
					return (NULL);
			} else {
				sz = ofs - pkg->pkg_ofs;
				while (sz != 0) {
					if (sz > sizeof(buf))
						sz = sizeof(buf);
					if (get_zipped(pkg, buf, sz) == -1)
						return (NULL);
					sz = ofs - pkg->pkg_ofs;
				}
			}
		}

		cur = malloc(sizeof(*cur));
		if (cur == NULL)
			return (NULL);
		memset(cur, 0, sizeof(*cur));
		cur->tf_pkg = pkg;

		while (1) {
			if (get_zipped(pkg, &cur->tf_hdr,
			    sizeof(cur->tf_hdr)) == -1) {
				free(cur);
				return (NULL);
			}

			/*
			 * There are always 2 empty blocks appended to
			 * a PKG. It marks the end of the archive.
			 */
			if (strncmp(cur->tf_hdr.ut_magic, "ustar", 5) != 0) {
				free(cur);
				errno = ENOSPC;
				return (NULL);
			}

			cur->tf_ofs = pkg->pkg_ofs;
			cur->tf_size = pkg_atol(cur->tf_hdr.ut_size,
			    sizeof(cur->tf_hdr.ut_size));

			if (cur->tf_hdr.ut_name[0] != '+')
				break;

			/*
			 * Skip package meta-files.
			 */
			ofs = cur->tf_ofs + cur->tf_size;
			ofs = (ofs + 0x1ff) & ~0x1ff;
			while (pkg->pkg_ofs < ofs) {
				if (get_zipped(pkg, buf, sizeof(buf)) == -1) {
					free(cur);
					return (NULL);
				}
			}
		}

		if (last != NULL)
			last->tf_next = cur;
		else
			pkg->pkg_first = cur;
		pkg->pkg_last = cur;
	}

	return (cur);
}