示例#1
0
void Rest::getRefData(EntitySet es, Time now, ostream& out) const
{
  int i{0};
  out << '{';
  // FIXME: validate entities.
  if (es.asset()) {
    out << "\"assets\":";
    getAsset(now, out);
    ++i;
  }
  if (es.contr()) {
    if (i > 0) {
      out << ',';
    }
    out << "\"contrs\":";
    getContr(now, out);
    ++i;
  }
  if (es.market()) {
    if (i > 0) {
      out << ',';
    }
    out << "\"markets\":";
    getMarket(now, out);
    ++i;
  }
  out << '}';
}
 InputSourceRef InputSource::getSubSource(const fs::path &subPath)
 {
     if (type == TYPE_RESOURCE_MSW)
     {
         /*
          * TODO: PARSE "resourceName", "mswID" AND "mswType"
          */
     }
     else
     {
         switch (type)
         {
             case TYPE_FILE:
                 return getFile(filePath.parent_path() / subPath);
                 
             case TYPE_ASSET:
                 return getAsset(relativePath.parent_path() / subPath);
                 
             case TYPE_RESOURCE:
                 return getResource(relativePath.parent_path() / subPath);
         }
     }
     
     return InputSourceRef();
 }
示例#3
0
void* findAssetEverywhere(zoneInfo_t* info, int type, const char* name)
{
	void* ret = getAsset(info, type, name);
	if(ret) return ret;

	return DB_FindXAssetHeader(type, name);
}
示例#4
0
void AssetRequest::start() {
    if (QThread::currentThread() != thread()) {
        QMetaObject::invokeMethod(this, "start", Qt::AutoConnection);
        return;
    }

    if (_state != NOT_STARTED) {
        qCWarning(networking) << "AssetRequest already started.";
        return;
    }
    
    _state = WAITING_FOR_INFO;
    
    auto assetClient = DependencyManager::get<AssetClient>();
    assetClient->getAssetInfo(_hash, _extension, [this](AssetServerError error, AssetInfo info) {
        _info = info;
        _error = error;
        
        if (_error != NoError) {
            qCDebug(networking) << "Got error retrieving asset info for" << _hash;
            _state = FINISHED;
            emit finished(this);
            return;
        }
        
        _state = WAITING_FOR_DATA;
        _data.resize(info.size);
        
        qCDebug(networking) << "Got size of " << _hash << " : " << info.size << " bytes";
        
        int start = 0, end = _info.size;
        
        auto assetClient = DependencyManager::get<AssetClient>();
        assetClient->getAsset(_hash, _extension, start, end, [this, start, end](AssetServerError error,
                                                                                const QByteArray& data) {
            Q_ASSERT(data.size() == (end - start));
            
            _error = error;
            if (_error == NoError) {
                memcpy(_data.data() + start, data.constData(), data.size());
                _totalReceived += data.size();
                emit progress(_totalReceived, _info.size);
            } else {
                qCDebug(networking) << "Got error retrieving asset" << _hash;
            }
            
            _state = FINISHED;
            emit finished(this);
        });
    });
}
示例#5
0
void NetworkSprite::updateSprite(bool force) {
	auto lib = AssetLibrary::getInstance();
	if (!_url.empty()) {
		_filePath = getPathForUrl(_url);
		uint64_t assetId = lib->getAssetId(_url, _filePath);
		if (!_asset || _asset->getId() != assetId) {
			retain();
			lib->getAsset([this, force] (Asset *a) {
				onAsset(a, force);
				release();
			}, _url, _filePath, TimeInterval::seconds(10 * 24 * 60 * 60));
		}
	} else {
		onAsset(nullptr, force);
	}
}
void LLLandmarkList::makeCallbacks(const LLUUID& landmark_id)
{
	LLLandmark* landmark = getAsset(landmark_id);

	if (!landmark)
	{
		LL_WARNS() << "Landmark to make callbacks for not found." << LL_ENDL;
	}

	// make all the callbacks here.
	loaded_callback_map_t::iterator it;
	while((it = mLoadedCallbackMap.find(landmark_id)) != mLoadedCallbackMap.end())
	{
		if (landmark)
			(*it).second(landmark);

		mLoadedCallbackMap.erase(it);
	}
}
示例#7
0
/** Returns the full path of a music file by searching all music search paths.
 *  It throws an exception if the file is not found.
 *  \param file_name File name to search for.
 */
std::string FileManager::searchMusic(const std::string& file_name) const
{
    std::string path;
    bool success = findFile(path, file_name, m_music_search_path);
    if(!success)
    {
        // If a music file is not found in any of the music search paths
        // check all root dirs. This is used by stk_config to load the
        // title music before any music search path is defined)
        path = getAsset(MUSIC, file_name);
        success = fileExists(path);
    }
    if (!success)
    {
        throw std::runtime_error(
            "[FileManager::getMusicFile] Cannot find music file '"
            +file_name+"'.");
    }
    return path;
}   // searchMusic
void LLLandmarkList::onRegionHandle(const LLUUID& landmark_id)
{
	LLLandmark* landmark = getAsset(landmark_id);

	if (!landmark)
	{
		LL_WARNS() << "Got region handle but the landmark not found." << LL_ENDL;
		return;
	}

	// Calculate landmark global position.
	// This should succeed since the region handle is available.
	LLVector3d pos;
	if (!landmark->getGlobalPos(pos))
	{
		LL_WARNS() << "Got region handle but the landmark global position is still unknown." << LL_ENDL;
		return;
	}

	makeCallbacks(landmark_id);
}
示例#9
0
void* addXModel(zoneInfo_t* info, const char* name, char* data, size_t dataLen)
{
	if (data == NULL) return NULL;

	if(dataLen == 0)
	{
		XModel * model = (XModel*)data;
		short* boneNames = new short[model->numBones];

		for(int i=0; i<model->numBones; i++)
		{
			boneNames[i] = addScriptString(info, SL_ConvertToString(model->boneNames[i]));
		}

		model->boneNames = boneNames;

		for(int i=0; i<model->numSurfaces; i++)
		{
			// allow material overriding
			void* file;
			void* asset;

			if(int len = FS_ReadFile(va("zonebuilder/materials/%s.txt", model->materials[i]->name), &file) > 0)
			{
				asset = addMaterial(info, model->materials[i]->name, (char*)file, len);
				FS_FreeFile(file);
			}
			else
			{
				asset = addMaterial(info, model->materials[i]->name, (char*)model->materials[i], 0);
			}

			addAsset(info, ASSET_TYPE_MATERIAL, model->materials[i]->name, asset);
		}

		return data;
	}

	// copy stuff over
	XModel * base = (XModel*)DB_FindXAssetHeader(ASSET_TYPE_XMODEL, "viewmodel_mp5k");
	XModel * asset = new XModel;

	memcpy(asset, base, sizeof(XModel));
	asset->lods[0].surfaces = new XModelSurfaces;
	memcpy(asset->lods[0].surfaces, base->lods[0].surfaces, sizeof(XModelSurfaces));

	XModelSurfaces * surf = asset->lods[0].surfaces;
	surf->name = new char[strlen(name) + 6];
	sprintf((char*)surf->name, "%s_surf", name);

	BUFFER * buf = new BUFFER(data, dataLen);
	asset->name = new char[128];
	buf->readstr(asset->name, 128);
	buf->read(&asset->numBones, 4, 1);
	buf->read(&asset->numSubBones, 4, 1);
	buf->read(&asset->numSurfaces, 4, 1);
	surf->numSurfaces = asset->numSurfaces;
	asset->lods[0].numSurfs = surf->numSurfaces;

	asset->boneNames = new short[asset->numBones];

	for(int i=0; i<asset->numBones; i++)
	{
		char bone[64];
		buf->readstr(bone, 64);
		asset->boneNames[i] = addScriptString(info, bone);
	}

	// allocate stuff and load it
	if(asset->numBones - asset->numSubBones)
	{
		asset->parentList = new char[asset->numBones - asset->numSubBones];
		asset->tagAngles = new XModelAngle[asset->numBones - asset->numSubBones];
		asset->tagPositions = new XModelTagPos[asset->numBones - asset->numSubBones];

		buf->read(asset->parentList, sizeof(char), asset->numBones - asset->numSubBones);
		buf->read(asset->tagAngles, sizeof(XModelAngle), asset->numBones - asset->numSubBones);
		buf->read(asset->tagPositions, sizeof(XModelTagPos), asset->numBones - asset->numSubBones);
	}

	if(asset->numBones)
	{
		asset->partClassification = new char[asset->numBones];
		asset->animMatrix = new char[32 * asset->numBones];

		buf->read(asset->partClassification, sizeof(char), asset->numBones);
		buf->read(asset->animMatrix, 32, asset->numBones);
	}

	surf->surfaces = new XSurface[surf->numSurfaces];
	memset(surf->surfaces, 0, sizeof(XSurface) * surf->numSurfaces);
	
	for(int i=0; i<surf->numSurfaces; i++)
	{
		XSurface* s = &surf->surfaces[i];
		buf->read(&s->numVertices, 4, 1);
		buf->read(&s->numPrimitives, 4, 1);
		buf->read(&s->blendNum1, 4, 1);
		buf->read(&s->blendNum2, 4, 1);
		buf->read(&s->blendNum3, 4, 1);
		buf->read(&s->blendNum4, 4, 1);

		int blendCount = (s->blendNum4 * 7) + (s->blendNum3 * 5) + (s->blendNum2 * 3) + s->blendNum1;

		if(blendCount)
		{
			s->blendInfo = new char[blendCount * 2];
			buf->read(s->blendInfo, 2, blendCount);
		}
		else 
		{
			s->blendInfo = NULL;	
		}

		s->vertexBuffer = new GfxPackedVertex[s->numVertices];
		buf->read(s->vertexBuffer, 32, s->numVertices);

		int ct = 0;
		buf->read(&ct, 4, 1);

		if(ct)
		{
			buf->read(&s->numCT, 4, 1);
			s->ct = new XSurfaceCT[s->numCT];

			for(int j=0; j<s->numCT; j++)
			{
				XSurfaceCT* ct = &s->ct[j];
				buf->read(&ct->pad, 4, 1);
				buf->read(&ct->pad2, 4, 1);
				ct->entry = new XSurfaceCTEntry;
				buf->read(ct->entry, 24, 1);
				buf->read(&ct->entry->numNode, 4, 1);
				buf->read(&ct->entry->numLeaf, 4, 1);

				if(ct->entry->numNode)
				{
					ct->entry->node = new char[ct->entry->numNode * 16];
					buf->read(ct->entry->node, 16, ct->entry->numNode);
				}
				else
				{
					ct->entry->node = NULL;
				}

				if(ct->entry->numLeaf)
				{
					ct->entry->leaf = new short[ct->entry->numLeaf];
					buf->read(ct->entry->leaf, 2, ct->entry->numLeaf);
				}
				else
				{
					ct->entry->node = NULL;
				}
			}
		}
		else
		{
			s->ct = NULL;
			s->numCT = 0;
		}

		s->indexBuffer = new Face[s->numPrimitives];
		buf->read(s->indexBuffer, sizeof(Face), s->numPrimitives);
	}

	asset->materials = new Material*[asset->numSurfaces];

	// read the material stuff and load a material if we need it
	for(int i=0; i<asset->numSurfaces; i++)
	{
		char matName[64] = { 0 };
		char techName[64] = { 0 };
		char matFileName[78] = { 0 };

		buf->readstr(matName, 50);
		buf->readstr(techName, 64);

		char* filename = matName;

		// asset is already in db... dont re-add it
		if (containsAsset(info, ASSET_TYPE_MATERIAL, matName) > 0)
		{
			asset->materials[i] = (Material*)getAsset(info, ASSET_TYPE_MATERIAL, matName);
			continue;
		}

		if(!strncmp("mc/", matName, 3)) filename = matName + 3;

		_snprintf(matFileName, sizeof(matFileName), "materials/%s.txt", filename);

		void* matBuf;
		int len = FS_ReadFile(matFileName, &matBuf);

		if(len > 0)
		{
			asset->materials[i] = (Material*)addMaterial(info, matName, (char*)matBuf, len);
			FS_FreeFile(matBuf);
		}
		else
		{
			asset->materials[i] = (Material*)DB_FindXAssetHeader(ASSET_TYPE_MATERIAL, matName);
			addMaterial(info, matName, (char*)asset->materials[i], 0);
		}

		addAsset(info, ASSET_TYPE_MATERIAL, matName, asset->materials[i]);		
	}

	int test = 0;
	buf->read(&test, 4, 1);

	if(test) Com_Error(false, "Cause NTA said so!");

	buf->read(&test, 4, 1);

	if(!test) Com_Error(false, "Cause NTA said so!");

	asset->unknowns = new char[asset->numBones * 28];
	buf->read(asset->unknowns, 28, asset->numBones);

	return asset;
}
示例#10
0
void AssetRequest::start() {
    if (QThread::currentThread() != thread()) {
        QMetaObject::invokeMethod(this, "start", Qt::AutoConnection);
        return;
    }

    if (_state != NotStarted) {
        qCWarning(asset_client) << "AssetRequest already started.";
        return;
    }

    // in case we haven't parsed a valid hash, return an error now
    if (!isValidHash(_hash)) {
        _error = InvalidHash;
        _state = Finished;

        emit finished(this);
        return;
    }
    
    // Try to load from cache
    _data = loadFromCache(getUrl());
    if (!_data.isNull()) {
        _error = NoError;

        _loadedFromCache = true;

        _state = Finished;
        emit finished(this);

        return;
    }

    _state = WaitingForData;

    auto assetClient = DependencyManager::get<AssetClient>();
    auto that = QPointer<AssetRequest>(this); // Used to track the request's lifetime
    auto hash = _hash;

    _assetRequestID = assetClient->getAsset(_hash, _byteRange.fromInclusive, _byteRange.toExclusive,
        [this, that, hash](bool responseReceived, AssetServerError serverError, const QByteArray& data) {

        if (!that) {
            qCWarning(asset_client) << "Got reply for dead asset request " << hash << "- error code" << _error;
            // If the request is dead, return
            return;
        }
        _assetRequestID = INVALID_MESSAGE_ID;

        if (!responseReceived) {
            _error = NetworkError;
        } else if (serverError != AssetServerError::NoError) {
            switch (serverError) {
                case AssetServerError::AssetNotFound:
                    _error = NotFound;
                    break;
                case AssetServerError::InvalidByteRange:
                    _error = InvalidByteRange;
                    break;
                default:
                    _error = UnknownError;
                    break;
            }
        } else {
            if (!_byteRange.isSet() && hashData(data).toHex() != _hash) {
                // the hash of the received data does not match what we expect, so we return an error
                _error = HashVerificationFailed;
            }

            if (_error == NoError) {
                _data = data;
                _totalReceived += data.size();
                emit progress(_totalReceived, data.size());

                if (!_byteRange.isSet()) {
                    saveToCache(getUrl(), data);
                }
            }
        }
        
        if (_error != NoError) {
            qCWarning(asset_client) << "Got error retrieving asset" << _hash << "- error code" << _error;
        }
        
        _state = Finished;
        emit finished(this);
    }, [this, that](qint64 totalReceived, qint64 total) {
        if (!that) {
            // If the request is dead, return
            return;
        }
        emit progress(totalReceived, total);
    });
}
示例#11
0
boost::shared_ptr<Shape> Shape::insert(const std::string& name, const std::string& geometryPath) {
	Asset asset = getAsset(geometryPath);
	/*
	std::vector<glm::vec3> points;
	std::vector<glm::vec3> normals;
	std::vector<glm::vec2> texCoords;
	if (!OBJLoader::load(geometryPath.c_str(), points, normals, texCoords)) {
		std::stringstream ss;
		ss << "OBJ file cannot be read: " << geometryPath.c_str() << "." << std::endl;
		std::cout << ss.str() << std::endl;
		throw ss.str();
	}
	*/

	// compute scale
	float scaleX = 1.0f;
	float scaleY = 1.0f;
	float scaleZ = 1.0f;

	BoundingBox bbox(asset.points);
	if (_scope.x != 0 && _scope.y != 0 && _scope.z != 0) {			// all non-zero
		scaleX = _scope.x / bbox.sx();
		scaleY = _scope.y / bbox.sy();
		scaleZ = _scope.z / bbox.sz();
	} else if (_scope.x == 0 && _scope.y != 0 && _scope.z != 0) {	// sx == 0
		scaleY = _scope.y / bbox.sy();
		scaleZ = _scope.z / bbox.sz();
		scaleX = (scaleY + scaleZ) * 0.5f;
	} else if (_scope.x != 0 && _scope.y == 0 && _scope.z != 0) {	// sy == 0
		scaleX = _scope.x / bbox.sx();
		scaleZ = _scope.z / bbox.sz();
		scaleY = (scaleX + scaleZ) * 0.5f;
	} else if (_scope.x != 0 && _scope.y != 0 && _scope.z == 0) {	// sz == 0
		scaleX = _scope.x / bbox.sx();
		scaleY = _scope.y / bbox.sy();
		scaleZ = (scaleX + scaleY) * 0.5f;
	} else if (_scope.x != 0) {										// sy == 0 && sz == 0
		scaleX = _scope.x / bbox.sx();
		scaleY = scaleX;
		scaleZ = scaleX;
	} else if (_scope.y != 0) {										// sx == 0 && sz == 0
		scaleY = _scope.y / bbox.sy();
		scaleX = scaleY;
		scaleZ = scaleY;
	} else if (_scope.z != 0) {										// sx == 0 && sy == 0
		scaleZ = _scope.z / bbox.sz();
		scaleX = scaleZ;
		scaleY = scaleZ;
	} else { // all zero
		// do nothing
	}

	// scale the points
	for (int i = 0; i < asset.points.size(); ++i) {
		for (int k = 0; k < asset.points[i].size(); ++k) {
			asset.points[i][k].x = (asset.points[i][k].x - bbox.minPt.x) * scaleX;
			asset.points[i][k].y = (asset.points[i][k].y - bbox.minPt.y) * scaleY;
			asset.points[i][k].z = (asset.points[i][k].z - bbox.minPt.z) * scaleZ;
		}
	}

	// if texCoords are not defined in obj file, generate them automatically.
	if (_texCoords.size() > 0 && asset.texCoords.size() == 0) {
		asset.texCoords.resize(asset.points.size());
		for (int i = 0; i < asset.points.size(); ++i) {
			asset.texCoords[i].resize(asset.points[i].size());
			for (int k = 0; k < asset.points[i].size(); ++k) {
				asset.texCoords[i][k].x = asset.points[i][k].x / _scope.x * (_texCoords[1].x - _texCoords[0].x) + _texCoords[0].x;
				asset.texCoords[i][k].y = asset.points[i][k].y / _scope.y * (_texCoords[2].y - _texCoords[0].y) + _texCoords[0].y;
			}
		}
	}

	if (asset.texCoords.size() > 0) {
		return boost::shared_ptr<Shape>(new GeneralObject(name, _pivot, _modelMat, asset.points, asset.normals, _color, asset.texCoords, _texture));
	} else {
		return boost::shared_ptr<Shape>(new GeneralObject(name, _pivot, _modelMat, asset.points, asset.normals, _color));
	}
}