int32 SoundOVProvider::LoadData(int8 ** buffer, int32 desiredSize) { #if defined(__OGG_ENABLED__) bool infiniteLoad = false; static const int32 OV_CHUNK_SIZE = 4096; if(-1 == desiredSize) { infiniteLoad = true; desiredSize = OV_CHUNK_SIZE; } int8 * data = (int8*)Alloc(desiredSize); DVASSERT_MSG(data, "SoundOVProvider::LoadData Alloc failed"); int32 size = 0; int32 currentSection; while(size < desiredSize) { int32 result = ov_read(&oggFile, (char*)(data + size), desiredSize - size, 0, 2, 1, ¤tSection); if(result > 0) { size += result; if(infiniteLoad && size == desiredSize) { desiredSize += OV_CHUNK_SIZE; data = (int8*)Realloc(data, desiredSize); DVASSERT_MSG(data, Format("SoundOVProvider::LoadData Realloc failed for size %d", desiredSize)); } } else if(result < 0) { Logger::Error("int32 SoundOVProvider::LoadData failed for file %s with code %d", fileName.c_str(), result); return 0; } else { break; } } *buffer = data; if(infiniteLoad) { ov_clear(&oggFile); file = 0; } return size; #else //#if defined(__OGG_ENABLED__) return 0; #endif //#if defined(__OGG_ENABLED__) }
void Box2DGameObject::InitBox2DBody(const b2BodyDef &bodyDef) { DVASSERT_MSG(manager, "You need to set manager first"); DVASSERT_MSG(box2DWorld, "Your box2d world is not set"); box2DBody = box2DWorld->CreateBody(&bodyDef); box2DBody->SetUserData(this); SetPosition(((Box2DGameObjectManager *)manager)->VectorBox2DToGameManager(bodyDef.position)); SetAngle(-bodyDef.angle); manager->RecalcObjectHierarchy(this); }
void Test::LoadResources() { time = 0.f; isFinished = false; skipFrames = 100; Scene *scene = new Scene(); scene->AddNode(scene->GetRootNode(fullName)); DVASSERT_MSG(scene, "Could not load the scene"); Camera* cam = new Camera(); scene->AddCamera(cam); Core* core = DAVA::Core::Instance(); float32 aspect = core->GetVirtualScreenHeight() / core->GetVirtualScreenWidth(); cam->Setup(70.f, aspect, 1.f, 5000.f); cam->SetLeft(Vector3(1, 0, 0)); cam->SetUp(Vector3(0, 0, 1)); scene->SetCurrentCamera(cam); SafeRelease(cam); UI3DView *sceneView = new UI3DView(Rect(0, 0, GetSize().x, GetSize().y)); sceneView->SetScene(scene); AddControl(sceneView); SafeRelease(sceneView); Landscape* landscape = GetLandscape(); DVASSERT_MSG(scene, "There is no landscape in a scene"); landscape->SetTiledShaderMode(Landscape::TILED_MODE_TEXTURE); uint32 textureMemory = TextureHelper::GetSceneTextureMemory(scene, GetFilePath()); testData.SetTextureMemorySize(textureMemory); File* file = File::Create(fullName, File::OPEN | File::READ); DVASSERT_MSG(file, "Could not open file scene file"); testData.SetSceneFileSize(file->GetSize()); SafeRelease(file); PreparePath(); PrepareFpsStat(); PrepareCameraAnimation(); ZeroCurFpsStat(); MoveToNextPoint(); SafeRelease(scene); }
RenderObject * RenderObject::Clone(RenderObject *newObject) { if(!newObject) { DVASSERT_MSG(IsPointerToExactClass<RenderObject>(this), "Can clone only RenderObject"); newObject = new RenderObject(); } newObject->type = type; newObject->flags = flags; newObject->debugFlags = debugFlags; //ro->bbox = bbox; //ro->worldBBox = worldBBox; uint32 size = GetRenderBatchCount(); for(uint32 i = 0; i < size; ++i) { RenderBatch *batch = GetRenderBatch(i)->Clone(); newObject->AddRenderBatch(batch); batch->Release(); } newObject->ownerDebugInfo = ownerDebugInfo; return newObject; }
void Scene::RemoveSystem(SceneSystem * sceneSystem) { UnregisterEntitiesInSystemRecursively(sceneSystem, this); Vector<SceneSystem*>::iterator endIt = systemsToProcess.end(); for(Vector<SceneSystem*>::iterator it = systemsToProcess.begin(); it != endIt; ++it) { if(*it == sceneSystem) { systemsToProcess.erase(it); break;; } } endIt = systems.end(); for(Vector<SceneSystem*>::iterator it = systems.begin(); it != endIt; ++it) { if(*it == sceneSystem) { systems.erase(it); return; } } DVASSERT_MSG(false, "System must be at systems array"); }
BaseObject * Camera::Clone(BaseObject * dstNode) { if (!dstNode) { DVASSERT_MSG(IsPointerToExactClass<Camera>(this), "Can clone only Camera"); dstNode = new Camera(); } // SceneNode::Clone(dstNode); Camera *cnd = (Camera*)dstNode; cnd->xmin = xmin; cnd->xmax = xmax; cnd->ymin = ymin; cnd->ymax = ymax; cnd->znear = znear; cnd->zfar = zfar; cnd->aspect = aspect; cnd->fovy = fovy; cnd->ortho = ortho; cnd->position = position; cnd->target = target; cnd->up = up; cnd->left = left; //cnd->rotation = rotation; cnd->cameraTransform = cameraTransform; cnd->flags = flags; cnd->zoomFactor = zoomFactor; return dstNode; }
RenderObject* SkyboxRenderObject::Clone(RenderObject *newObject) { if(!newObject) { DVASSERT_MSG(IsPointerToExactClass<SkyboxRenderObject>(this), "Can clone only SkyboxRenderObject"); newObject = new SkyboxRenderObject(); } SkyboxRenderObject* skyboxRenderObject = static_cast<SkyboxRenderObject*>(newObject); skyboxRenderObject->type = type; skyboxRenderObject->flags = flags; skyboxRenderObject->RemoveFlag(RenderObject::TREE_NODE_NEED_UPDATE); skyboxRenderObject->debugFlags = debugFlags; skyboxRenderObject->ownerDebugInfo = ownerDebugInfo; skyboxRenderObject->bbox = bbox; skyboxRenderObject->texturePath = texturePath; skyboxRenderObject->offsetZ = offsetZ; skyboxRenderObject->rotationZ = rotationZ; skyboxRenderObject->nonClippingDistance = nonClippingDistance; uint32 size = GetRenderBatchCount(); for(uint32 i = 0; i < size; ++i) { RenderBatch *batch = GetRenderBatch(i)->Clone(); skyboxRenderObject->AddRenderBatch(batch); batch->Release(); } skyboxRenderObject->BuildSkybox(); skyboxRenderObject->UpdateMaterial(); return newObject; }
void GameObject::FastForward(float32 skipTime, float32 updateTime) { DVASSERT_MSG(skipTime>0.0f && updateTime>0.0f, "FastForward skipTime and updateTime must be greater than 0"); float32 remainingSkipTime = skipTime; while(remainingSkipTime>0.0f) { Update(updateTime); remainingSkipTime -= updateTime; } }
RenderObject * Mesh::Clone( RenderObject *newObject ) { if(!newObject) { DVASSERT_MSG(IsPointerToExactClass<Mesh>(this), "Can clone only Mesh"); newObject = new Mesh(); } return RenderObject::Clone(newObject); }
SceneNode* ReferenceNode::Clone(SceneNode *dstNode /*= NULL*/) { if (!dstNode) { DVASSERT_MSG(IsPointerToExactClass<ReferenceNode>(this), "Can clone only ReferenceNode"); dstNode = new ReferenceNode(); } return SceneNode::Clone(dstNode); }
Entity* UserNode::Clone(Entity *dstNode) { if (!dstNode) { DVASSERT_MSG(IsPointerToExactClass<UserNode>(this), "Can clone only UserNode"); dstNode = new UserNode(); } Entity::Clone(dstNode); return dstNode; }
bool SceneValidator::ValidateHeightmapPathname(const FilePath &pathForValidation, Set<String> &errorsLog) { DVASSERT_MSG(!pathForChecking.IsEmpty(), "Need to set pathname for DataSource folder"); bool pathIsCorrect = IsPathCorrectForProject(pathForValidation); if(pathIsCorrect) { String::size_type posPng = pathForValidation.GetAbsolutePathname().find(".png"); String::size_type posHeightmap = pathForValidation.GetAbsolutePathname().find(Heightmap::FileExtension()); pathIsCorrect = ((String::npos != posPng) || (String::npos != posHeightmap)); if(!pathIsCorrect) { errorsLog.insert(Format("Heightmap path %s is wrong", pathForValidation.GetAbsolutePathname().c_str())); return false; } Heightmap *heightmap = new Heightmap(); if(String::npos != posPng) { Image *image = CreateTopLevelImage(pathForValidation); pathIsCorrect = heightmap->BuildFromImage(image); SafeRelease(image); } else { pathIsCorrect = heightmap->Load(pathForValidation); } if(!pathIsCorrect) { SafeRelease(heightmap); errorsLog.insert(Format("Can't load Heightmap from path %s", pathForValidation.GetAbsolutePathname().c_str())); return false; } pathIsCorrect = IsPowerOf2(heightmap->Size() - 1); if(!pathIsCorrect) { errorsLog.insert(Format("Heightmap %s has wrong size", pathForValidation.GetAbsolutePathname().c_str())); } SafeRelease(heightmap); return pathIsCorrect; } else { errorsLog.insert(Format("Path %s is incorrect for project %s", pathForValidation.GetAbsolutePathname().c_str(), pathForChecking.GetAbsolutePathname().c_str())); } return pathIsCorrect; }
bool FileSystem::MoveFile(const String & existingFile, const String & newFile) { #ifdef __DAVAENGINE_WIN32__ BOOL ret = ::MoveFileA(existingFile.c_str(), newFile.c_str()); return ret != 0; #elif defined(__DAVAENGINE_ANDROID__) DVASSERT_MSG(0, "Not implemented"); #else //iphone & macos int ret = copyfile(existingFile.c_str(), newFile.c_str(), NULL, COPYFILE_ALL | COPYFILE_EXCL | COPYFILE_MOVE); return ret==0; #endif //PLATFORMS }
Entity* ImposterNode::Clone(Entity *dstNode /*= NULL*/) { if (!dstNode) { DVASSERT_MSG(IsPointerToExactClass<ImposterNode>(this), "Can clone only ImposterNode"); dstNode = new ImposterNode(); } Entity::Clone(dstNode); return dstNode; }
RenderObject * ParticleEmitter::Clone(RenderObject *newObject) { if(!newObject) { DVASSERT_MSG(IsPointerToExactClass<ParticleEmitter>(this), "Can clone only ParticleEmitter"); newObject = new ParticleEmitter(); } ((ParticleEmitter*)newObject)->LoadFromYaml(configPath); return newObject; }
const char* EnumMap::ToString(const int e) const { const char* ret = NULL; if(map.count(e)) { ret = map.at(e).c_str(); } else { DVASSERT_MSG(false, "Be sure that e is declared at global enum"); //example ENUM_ADD_DESCR(FORMAT_ATC_RGBA_EXPLICIT_ALPHA, "ATC_RGBA_EXPLICIT_ALPHA"); } return ret; }
Entity* ShadowVolumeNode::Clone(Entity *dstNode /*= NULL*/) { if (!dstNode) { DVASSERT_MSG(IsPointerToExactClass<ShadowVolumeNode>(this), "Can clone only ShadowVolumeNode"); dstNode = new ShadowVolumeNode(); } Entity::Clone(dstNode); ShadowVolumeNode *nd = (ShadowVolumeNode *)dstNode; nd->shadowPolygonGroup = shadowPolygonGroup; SafeRetain(nd->shadowPolygonGroup); return dstNode; }
Entity* ParticleEmitterNode::Clone(Entity *dstNode /*= NULL*/) { if (!dstNode) { DVASSERT_MSG(IsPointerToExactClass<ParticleEmitterNode>(this), "Can clone only ParticleEmitterNode"); dstNode = new ParticleEmitterNode(); } Entity::Clone(dstNode); ParticleEmitterNode *nd = (ParticleEmitterNode *)dstNode; nd->yamlPath = yamlPath; nd->LoadFromYaml(yamlPath); return dstNode; }
FMOD_RESULT F_CALLBACK FMODSoundEvent::FMODEventCallback(FMOD_EVENT *event, FMOD_EVENT_CALLBACKTYPE type, void *param1, void *param2, void *userdata) { if(type == FMOD_EVENT_CALLBACKTYPE_STOLEN || type == FMOD_EVENT_CALLBACKTYPE_EVENTFINISHED) { DVASSERT_MSG(Thread::IsMainThread(), DAVA::Format("FMOD Callback type %d", type).c_str()); FMOD::Event * fEvent = (FMOD::Event *)event; FMODSoundEvent * sEvent = (FMODSoundEvent *)userdata; if(sEvent && fEvent) { FMOD_VERIFY(fEvent->setCallback(0, 0)); sEvent->PerformCallback(fEvent); } } return FMOD_OK; }
float32 LandscapeEditorDrawSystem::GetHeightAtPoint(const Vector2& point) { Heightmap *heightmap = GetHeightmapProxy(); int32 x = (int32)point.x; int32 y = (int32)point.y; DVASSERT_MSG((x >= 0 && x < heightmap->Size()) && (y >= 0 && y < heightmap->Size()), "Point must be in heightmap coordinates"); int32 index = x + y * heightmap->Size(); float32 height = heightmap->Data()[index]; float32 maxHeight = GetLandscapeMaxHeight(); height *= maxHeight; height /= Heightmap::MAX_VALUE; return height; }
void UpdateSingleTouchPosition(int32 phase, AInputEvent* event, int32 index) { int32 id = AMotionEvent_getPointerId(event, index); bool isFound = false; for(int32 touchIndex = 0; touchIndex < (int32)activeTouches.size(); ++touchIndex) { if(id == activeTouches[touchIndex].tid) { FillEventData(activeTouches[touchIndex], phase, event, index); isFound = true; break; } } DVASSERT_MSG(isFound, "Touch can be found"); ProcessTouches(phase); }
BaseObject * Light::Clone(BaseObject *dstNode) { if(!dstNode) { DVASSERT_MSG(IsPointerToExactClass<Light>(this), "Can clone only LightNode"); dstNode = new Light(); } //BaseObject::Clone(dstNode); Light *lightNode = (Light *)dstNode; lightNode->type = type; lightNode->ambientColor = ambientColor; lightNode->diffuseColor = diffuseColor; lightNode->specularColor = specularColor; lightNode->intensity = intensity; lightNode->flags = flags; return dstNode; }
bool SceneValidator::ValidateTexturePathname(const FilePath &pathForValidation, Set<String> &errorsLog) { DVASSERT_MSG(!pathForChecking.IsEmpty(), "Need to set pathname for DataSource folder"); bool pathIsCorrect = IsPathCorrectForProject(pathForValidation); if(pathIsCorrect) { String textureExtension = pathForValidation.GetExtension(); String::size_type extPosition = TextureDescriptor::GetSupportedTextureExtensions().find(textureExtension); if(String::npos == extPosition) { errorsLog.insert(Format("Path %s has incorrect extension", pathForValidation.GetAbsolutePathname().c_str())); return false; } } else { errorsLog.insert(Format("Path %s is incorrect for project %s", pathForValidation.GetAbsolutePathname().c_str(), pathForChecking.GetAbsolutePathname().c_str())); } return pathIsCorrect; }
void Box2DGameObject::SetManager(GameObjectManager * _manager) { DVASSERT_MSG(!_manager || dynamic_cast<Box2DGameObjectManager *> (_manager), "Box2DGameObject can be added only to the Box2DGameObjectManager"); // DVASSERT_MSG(!_manager || !manager || ((Box2DGameObjectManager *)_manager)->box2DWorld == box2DWorld, "You can't move phisycal body to the another manager"); manager = _manager; if (manager) { box2DWorld = ((Box2DGameObjectManager *)manager)->box2DWorld; Box2DWorldDidInit(); } else { if (box2DBody) { Box2DWorldWillDeinit(); box2DWorld->DestroyBody(box2DBody); box2DBody = NULL; box2DWorld = NULL; } } //TODO: Добваить активацию и деактивацию боди при добавлении и убирании из менежера. }
b2Fixture* Box2DGameObject::AddFixture(const b2FixtureDef &fixtureDef) { DVASSERT_MSG(box2DBody, "You need to init body first"); return box2DBody->CreateFixture(&fixtureDef); }
File * APKFile::CreateFromAssets(const FilePath &filePath, uint32 attributes) { // Logger::Debug("[APKFile::CreateFromAssets] wan't to create file %s", filePath.c_str()); // FileSystem * fileSystem = FileSystem::Instance(); for (List<FileSystem::ResourceArchiveItem>::iterator ai = fileSystem->resourceArchiveList.begin(); ai != fileSystem->resourceArchiveList.end(); ++ai) { FileSystem::ResourceArchiveItem & item = *ai; String filenamecpp = filePath.GetAbsolutePathname(); String::size_type pos = filenamecpp.find(item.attachPath); if (pos == 0) { String relfilename = filenamecpp.substr(item.attachPath.length()); int32 size = item.archive->LoadResource(relfilename, 0); if ( size == -1 ) { return 0; } uint8 * buffer = new uint8[size]; item.archive->LoadResource(relfilename, buffer); APKFile *fileInstance = CreateFromData(relfilename, buffer, size, attributes); SafeDeleteArray(buffer); return fileInstance; } } bool isDirectory = FileSystem::Instance()->IsDirectory(filePath); if(isDirectory) { Logger::Error("[APKFile::CreateFromAssets] Can't create file because of it is directory (%s)", filePath.GetAbsolutePathname().c_str()); return NULL; } CorePlatformAndroid *core = (CorePlatformAndroid *)Core::Instance(); DVASSERT_MSG(core, "Need create core before loading of files"); AAssetManager *assetManager = core->GetAssetManager(); DVASSERT_MSG(assetManager, "Need setup assetManager on core creation"); AAsset * asset = AAssetManager_open(assetManager, filePath.GetAbsolutePathname().c_str(), AASSET_MODE_UNKNOWN); if(!asset) { Logger::Error("[APKFile::CreateFromAssets] Can't load asset for path %s", filePath.GetAbsolutePathname().c_str()); return NULL; } uint32 dataSize = AAsset_getLength(asset); // Logger::Debug("[APKFile::CreateFromAssets] fileSize is %d (%s)", dataSize, filePath.c_str()); uint8 *data = new uint8[dataSize]; uint32 readSize = AAsset_read(asset, data, dataSize * sizeof(uint8)); AAsset_close(asset); DVASSERT_MSG(readSize == dataSize * sizeof(uint8), "Can't read full file"); APKFile *fileInstance = CreateFromData(filePath, data, readSize, attributes); DVASSERT_MSG(fileInstance, "Can't create dynamic file from memory"); SafeDeleteArray(data); return fileInstance; }
b2Fixture* Box2DGameObject::AddFixture(const b2Shape &shape, float32 density/* = 0*/) { DVASSERT_MSG(box2DBody, "You need to init body first"); return box2DBody->CreateFixture(&shape, density); }
void TextureDescriptor::Save() const { DVASSERT_MSG(!pathname.IsEmpty(), "Can use this method only after calling Load()"); Save(pathname); }
Entity* LodNode::Clone(Entity *dstNode) { if (!dstNode) { DVASSERT_MSG(IsPointerToExactClass<LodNode>(this), "Can clone only LodNode"); dstNode = new LodNode(); } Entity::Clone(dstNode); LodNode *nd = (LodNode *)dstNode; nd->lodLayers = lodLayers; int32 lodIdx = 0;// Don't ask me how it's works if(!nd->lodLayers.empty()) { const List<LodData>::const_iterator &end = nd->lodLayers.end(); nd->currentLod = &(*nd->lodLayers.begin()); for (List<LodData>::iterator it = nd->lodLayers.begin(); it != end; ++it) { LodData & ld = *it; size_t size = ld.nodes.size(); for (size_t idx = 0; idx < size; ++idx) { for (int i = 0; i < (int)children.size(); i++) { if(children[i] == ld.nodes[idx]) { ld.nodes[idx] = nd->children[i]; if (nd->currentLod != &ld) { ld.nodes[idx]->SetUpdatable(false); } else { ld.nodes[idx]->SetUpdatable(true); } break; } } } lodIdx++; } } //Lod values for(int32 iLayer = 0; iLayer < MAX_LOD_LAYERS; ++iLayer) { nd->lodLayersArray[iLayer].distance = lodLayersArray[iLayer].distance; nd->lodLayersArray[iLayer].nearDistance = lodLayersArray[iLayer].nearDistance; nd->lodLayersArray[iLayer].nearDistanceSq = lodLayersArray[iLayer].nearDistanceSq; nd->lodLayersArray[iLayer].farDistance = lodLayersArray[iLayer].farDistance; nd->lodLayersArray[iLayer].farDistanceSq = lodLayersArray[iLayer].farDistanceSq; } nd->forceDistance = forceDistance; nd->forceDistanceSq = forceDistanceSq; nd->forceLodLayer = forceLodLayer; return dstNode; }
RenderObject * ParticleEmitter3D::Clone(RenderObject *newObject) { if(!newObject) { DVASSERT_MSG(IsPointerToExactClass<ParticleEmitter3D>(this), "Can clone only ParticleEmitter3D"); newObject = new ParticleEmitter3D(); } else { CleanupLayers(); ReleaseFromCache(static_cast<ParticleEmitter *>(newObject)->emitterFileName); } ParticleEmitter* clonedEmitter = static_cast<ParticleEmitter*>(newObject); clonedEmitter->SetConfigPath(this->configPath); clonedEmitter->SetPosition(this->position); clonedEmitter->SetAngle(this->angle); clonedEmitter->SetLifeTime(this->lifeTime); clonedEmitter->SetRepeatCount(this->repeatCount); clonedEmitter->SetTime(this->time); clonedEmitter->SetEmitPointsCount(this->emitPointsCount); clonedEmitter->SetPaused(this->isPaused); clonedEmitter->SetAutoRestart(this->isAutorestart); clonedEmitter->SetParticlesFollow(this->particlesFollow); clonedEmitter->Set3D(this->is3D); clonedEmitter->SetPlaybackSpeed(this->playbackSpeed); clonedEmitter->SetInitialTranslationVector(this->initialTranslationVector); if (this->emissionVector) { clonedEmitter->emissionVector = this->emissionVector->Clone(); clonedEmitter->emissionVector->Release(); } if (this->emissionAngle) { clonedEmitter->emissionAngle = this->emissionAngle->Clone(); clonedEmitter->emissionAngle->Release(); } if (this->emissionRange) { clonedEmitter->emissionRange = this->emissionRange->Clone(); clonedEmitter->emissionRange->Release(); } if (this->radius) { clonedEmitter->radius = this->radius->Clone(); clonedEmitter->radius->Release(); } if (this->colorOverLife) { clonedEmitter->colorOverLife = this->colorOverLife->Clone(); clonedEmitter->colorOverLife->Release(); } if (this->size) { clonedEmitter->size = this->size->Clone(); clonedEmitter->size->Release(); } clonedEmitter->emitterType = this->emitterType; clonedEmitter->currentColor = this->currentColor; clonedEmitter->SetShortEffect(shortEffect); // Now can add Layers. Need to update their parents. for (Vector<ParticleLayer*>::iterator iter = this->layers.begin(); iter != this->layers.end(); iter ++) { ParticleLayer* clonedLayer = (*iter)->Clone(NULL); ParticleLayer3D* clonedLayer3D = dynamic_cast<ParticleLayer3D*>(clonedLayer); if (clonedLayer3D) { clonedLayer3D->SetParent(clonedEmitter); } clonedEmitter->AddLayer(clonedLayer); SafeRelease(clonedLayer); } time = 0.0f; repeatCount = 0; lodLevelLocked = false; currentLodLevel = desiredLodLevel; clonedEmitter->emitterFileName = emitterFileName; RetainInCache(emitterFileName); return newObject; }