void ApplicationManager::setFileSystem(const char *fileSystem) { std::vector<std::string> result; pystring::split(fileSystem, result, "|"); // gvfs_setZipFiles(result[0].c_str(), result[1].c_str(), result[2].c_str()); for (size_t i = 3; i < result.size(); i += 4) { gvfs_addFile(result[i].c_str(), atoi(result[i + 1].c_str()), atoi(result[i + 2].c_str()), atoi(result[i + 3].c_str())); glog_v("%s %d %d %d", result[i].c_str(), atoi(result[i + 1].c_str()), atoi(result[i + 2].c_str()), atoi(result[i + 3].c_str())); } setDocumentsDirectory(internalDir_.c_str()); setTemporaryDirectory(cacheDir_.c_str()); }
static void *l_alloc(void *ud, void *ptr, size_t osize, size_t nsize) { if (memory_pool == NULL) { const size_t mpsize = 1024 * 1024; glog_v("init_memory_pool: %dKb", mpsize / 1024); memory_pool = tlsf_create_with_pool(malloc(mpsize), mpsize); memory_pool_end = (char*)memory_pool + mpsize; } if (nsize == 0) { g_free(ptr); return NULL; } else return g_realloc(ptr, osize, nsize); }
AudioPlayer::~AudioPlayer() { glog_v("~AudioPlayer\n"); stop(); // sem_destroy(&sem_); pthread_cond_destroy(&cond_); pthread_mutex_destroy(&mutex_); pthread_mutex_destroy(&mutex2_); free(buffer_); buffer_ = NULL; alDeleteSources(1, &source_); audiosource_->deleteStreamer(streamer_); streamer_ = NULL; }
AudioPlayer::AudioPlayer(AudioSource* audiosource, double msec, int loops) : audiosource_(audiosource), volume_(1) { glog_v("AudioPlayer\n"); streamer_ = audiosource_->newStremaer(loops); alGenSources(1, &source_); buffer_ = (unsigned char*)malloc(BUFFER_SIZE); ALuint buffer; alGenBuffers(1, &buffer); // printf("alGenBuffers: %d\n", buffer); streamer_->seek(msec); double pos = streamer_->tell(); // printf("%g\n", pos); size_t done = streamer_->read(buffer_, BUFFER_SIZE); // printf("%d\n", done); alBufferData(buffer, (audiosource_->channelCount() == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, buffer_, done, audiosource_->rate()); alSourceQueueBuffers(source_, 1, &buffer); // printf("alSourceQueueBuffers\n"); positions_.push_back(pos); alSourcePlay(source_); emptyqueue_ = false; playing_ = true; finished_ = false; callback_ = NULL; data_ = NULL; // sem_init(&sem_, 0, 0); pthread_mutex_init(&mutex_, NULL); pthread_mutex_init(&mutex2_, NULL); pthread_cond_init(&cond_, NULL); pthread_create(&thread_, NULL, tick_s, this); }
void Application::renderScene(int deltaFrameCount) { if (nframe_ < 0 || time_ < 0) { nframe_ = 0; time_ = iclock(); } double time = iclock(); nframe_++; if (nframe_ == 60) { double dtime = time - time_; time_ = time; glog_v("fps: %g %d", nframe_ / dtime, GReferenced::instanceCount); nframe_ = 0; } if (!ShaderEngine::Engine) return; ShaderEngine *gfx = ShaderEngine::Engine; //oglTextureReset(); gfx->reset(); gtexture_tick(); if (scale_ == 0) scale_ = 1; switch (hardwareOrientation_) { case eFixed: case ePortrait: case ePortraitUpsideDown: gfx->setViewport(0, 0, width_ / scale_, height_ / scale_); break; case eLandscapeLeft: case eLandscapeRight: gfx->setViewport(0, 0, height_ / scale_, width_ / scale_); break; } if (projectionDirty_) { projectionDirty_ = false; Matrix4 projection, frustum; //glMatrixMode(GL_PROJECTION); //glLoadIdentity(); //glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); projection.scale(logicalScaleX_, logicalScaleY_, 1); projection.translate(logicalTranslateX_, logicalTranslateY_, 0); projection.scale(1.f / scale_, 1.f / scale_, 1.f); if (hardwareOrientation_ == eFixed) { } else { switch (orientation_) { case ePortrait: break; case ePortraitUpsideDown: projection.translate(-(width_ / scale_) / 2, -(height_ / scale_) / 2, 0); projection.rotate(180, 0, 0, 1); projection.translate((width_ / scale_) / 2, (height_ / scale_) / 2, 0); break; case eLandscapeLeft: projection.translate(-(width_ / scale_) / 2, -(width_ / scale_) / 2, 0); projection.rotate(90, 0, 0, 1); projection.translate((width_ / scale_) / 2, (width_ / scale_) / 2, 0); break; case eLandscapeRight: projection.translate(-(height_ / scale_) / 2, -(height_ / scale_) / 2, 0); projection.rotate(270, 0, 0, 1); projection.translate((height_ / scale_) / 2, (height_ / scale_) / 2, 0); break; } switch (hardwareOrientation_) { case ePortrait: break; case ePortraitUpsideDown: projection.translate(-(width_ / scale_) / 2, -(height_ / scale_) / 2, 0); projection.rotate(180, 0, 0, 1); projection.translate((width_ / scale_) / 2, (height_ / scale_) / 2, 0); break; case eLandscapeLeft: projection.translate(-(width_ / scale_) / 2, -(width_ / scale_) / 2, 0); projection.rotate(-90, 0, 0, 1); projection.translate((width_ / scale_) / 2, (width_ / scale_) / 2, 0); break; case eLandscapeRight: projection.translate(-(height_ / scale_) / 2, -(height_ / scale_) / 2, 0); projection.rotate(-270, 0, 0, 1); projection.translate((height_ / scale_) / 2, (height_ / scale_) / 2, 0); break; } } Matrix4 vpProjection = projection; switch (hardwareOrientation_) { case eFixed: case ePortrait: case ePortraitUpsideDown: if (fov_ > 0) { float hw = width_ * 0.5 / scale_; float hh = height_ * 0.5 / scale_; float np = hh / tan(fov_ * M_PI / 360.0); float fp = (farplane_ > 0) ? farplane_ : hh * 2; float cnp = (nearplane_ > 0) ? nearplane_ : 0.01; frustum = gfx->setFrustum(-hw * cnp, hw * cnp, hh * cnp, -hh * cnp, np * cnp, np + fp); projection.translate(-hw, -hh, -np - 0.001); } else { float fp = (farplane_ > 0) ? farplane_ : 1; //Conservative default frustum = gfx->setOrthoFrustum(0, width_ / scale_, height_ / scale_, 0, -fp, fp); } gfx->adjustViewportProjection(vpProjection, width_ / scale_, height_ / scale_); break; case eLandscapeLeft: case eLandscapeRight: if (fov_ > 0) { float hw = width_ * 0.5 / scale_; float hh = height_ * 0.5 / scale_; float np = hh / tan(fov_ * M_PI / 360.0); float fp = (farplane_ > 0) ? farplane_ : hh * 2; float cnp = (nearplane_ > 0) ? nearplane_ : 0.01; frustum = gfx->setFrustum(-hh * cnp, hh * cnp, hw * cnp, -hw * cnp, np * cnp, np + fp); projection.translate(-hh, -hw, -np - 0.001); } else { float fp = (farplane_ > 0) ? farplane_ : 1; //Conservative default frustum = gfx->setOrthoFrustum(0, height_ / scale_, width_ / scale_, 0, -fp, fp); } gfx->adjustViewportProjection(vpProjection, height_ / scale_, width_ / scale_); break; } projectionMatrix_ = frustum * projection; vpProjectionMatrix_ = vpProjection; } gfx->setViewportProjection(vpProjectionMatrix_); //glMatrixMode(GL_MODELVIEW); //glLoadIdentity(); float ltx = this->getLogicalTranslateX(); float lty = this->getLogicalTranslateY(); float lsx = this->getLogicalScaleX(); float lsy = this->getLogicalScaleY(); int hw = this->getHardwareWidth(); int hh = this->getHardwareHeight(); if (hardwareOrientation_!=eFixed) { Orientation orientation = this->orientation(); if (orientation == eLandscapeLeft || orientation == eLandscapeRight) std::swap(hw, hh); } gfx->setProjection(projectionMatrix_); // hardware start/end x/y //if(lsx == 0) lsx = 1; //if(lsy == 0) lsy = 1; float sx = (0 - ltx) / lsx; float sy = (0 - lty) / lsy; float ex = (hw - ltx) / lsx; float ey = (hh - lty) / lsy; CurrentTransform currentTransform; stage_->draw(currentTransform, sx, sy, ex, ey); #if 0 && defined(QT_CORE_LIB) qDebug() << "bindTextureCount: " << getBindTextureCount(); qDebug() << "clientStateCount: " << getClientStateCount(); qDebug() << "texture2DStateCount: " << getTexture2DStateCount(); qDebug() << getVertexArrayCount() << getTextureCoordArrayCount(); #endif // Referenced::emptyPool(); lastFrameRenderTime_ = iclock() - time; }
void ApplicationManager::play(const char *gapp) { FILE *fd=fopen(gapp,"rb"); if (!fd) return; //No file/not openable fseek(fd,0,SEEK_END); long pksz=ftell(fd); if (pksz < 16) return; //Invalid file size struct { uint32_t flistOffset; uint32_t version; char signature[8]; } PACKED tlr; fseek(fd,pksz - 16,SEEK_SET); fread(&tlr,1,16,fd); tlr.version = BIGENDIAN4(tlr.version); tlr.flistOffset = BIGENDIAN4(tlr.flistOffset); if ((!strncmp(tlr.signature, "GiDeRoS", 7)) && (tlr.version == 0)) { glog_v("GAPP-ARCH: %s", gapp); gvfs_setZipFile(gapp); char *buffer = (char *) malloc(pksz - tlr.flistOffset); fseek(fd,tlr.flistOffset,SEEK_SET); fread(buffer, 1,pksz - tlr.flistOffset,fd); int offset = 0; while (offset < (pksz - tlr.flistOffset)) { int plen = strlen(buffer + offset); if (!plen) break; //End of list uint32_t foffset=PBULONG(buffer + offset + plen + 1); uint32_t fsize=PBULONG(buffer + offset + plen + 1+sizeof(uint32_t)); const char *norm = gpath_normalizeArchivePath(buffer + offset); gvfs_addFile(norm, 0, foffset, fsize); //glog_d("GAPP-FILE: %s,%d,%d", norm, foffset, fsize); offset += (plen + 1 + 2 * sizeof(uint32_t)); } free(buffer); } else glog_w("GAPP: Invalid signature/version"); fclose(fd); if (running_ == true) { Event event(Event::APPLICATION_EXIT); GStatus status; application_->broadcastEvent(&event, &status); running_ = false; } std::string gappfile=gapp; std::string projectName=gappfile.substr(0,gappfile.find_last_of('.')-1); const char* documentsDirectory; const char* temporaryDirectory; std::string dir = "/"; std::string documents = dir + "documents"+appPath; std::string temporary = dir + "temporary"; _mkdir(documents.c_str()); _mkdir(temporary.c_str()); glog_v("documents: %s", documents.c_str()); glog_v("temporary: %s", temporary.c_str()); mkdir(documents.c_str(), 0755); mkdir(temporary.c_str(), 0755); setDocumentsDirectory(documents.c_str()); setTemporaryDirectory(temporary.c_str()); setResourceDirectory(""); loadProperties(); loadLuaFiles(); }