void MSoundRef::clear(void) { MEngine * engine = MEngine::getInstance(); MSoundContext * soundContext = engine->getSoundContext(); soundContext->deleteBuffer(&m_bufferId); }
void Atlas::Save() { MEngine* engine = MEngine::getInstance(); std::string imgName = (std::string("atlases/") + m_Name + ".png"); engine->getImageSaver()->loadData(imgName.c_str(), &m_Atlas); if(m_ConfigFile) { m_ConfigFile->Write("atlas.filename", imgName); m_ConfigFile->Write("atlas.images", m_Images.size()); int i = 0; for(imageMapIter iImage = m_Images.begin(); iImage != m_Images.end(); iImage++) { std::string root = "atlas.image"; char num[32]; snprintf(num, 32, "%d.", i); root += num; ++i; m_ConfigFile->Write((root + "name").c_str(), iImage->first); m_ConfigFile->Write((root + "pos").c_str(), iImage->second.uv); m_ConfigFile->Write((root + "w").c_str(), iImage->second.width); m_ConfigFile->Write((root + "h").c_str(), iImage->second.height); } m_ConfigFile->Save(); } }
void MLevel::changeCurrentScene(unsigned int id) { if(id == m_currentSceneId) return; MEngine * engine = MEngine::getInstance(); if(id < getScenesNumber()) { MScene * scene = getCurrentScene(); // onEndScene MGame * game = engine->getGame(); if(game) game->onEndScene(); // change scene setCurrentSceneId(id); scene = getCurrentScene(); // onBeginScene if(game) game->onBeginScene(); } }
void MaratisPlayer::loadProject(MProject* proj, const char * filename) { MWindow * window = MWindow::getInstance(); MEngine * engine = MEngine::getInstance(); // working directory char workingDir[256]; getRepertory(workingDir, filename); window->setWorkingDirectory(workingDir); // restart restart(); loadGamePlugin(); // renderer changeRenderer(proj->renderer.c_str()); // if we have a package manager, try to load the package if(MPackageManager* pPackMan = MEngine::getInstance()->getPackageManager()) { char projName[256]; getLocalFilename(projName, workingDir, filename); if(char* ext = strstr(projName, ".mproj")) { sprintf(ext, ".npk"); char packageFile[256]; getGlobalFilename(packageFile, workingDir, projName); pPackMan->loadPackage(packageFile); } } // load start level engine->loadLevel(proj->startLevel.c_str()); }
void MScene::draw(MOCamera * camera) { MEngine * engine = MEngine::getInstance(); MRenderer * renderer = engine->getRenderer(); if(renderer) renderer->drawScene(this, camera); }
void MaratisPlayer::graphicLoop(void) { MWindow * window = MWindow::getInstance(); MEngine * engine = MEngine::getInstance(); MRenderingContext * render = engine->getRenderingContext(); // game MGame * game = engine->getGame(); if(game) { if(game->isRunning()) { render->disableScissorTest(); render->setViewport(0, 0, window->getWidth(), window->getHeight()); game->draw(); } else { render->clear(M_BUFFER_COLOR); } } else { render->clear(M_BUFFER_COLOR); } }
void Atlas::Generate(bool clear) { m_Atlas.create(M_UBYTE, m_Width, m_Height, m_BPP); unsigned char col[]= {255, 255, 255, 0}; for(uint32 x = 0; x < m_Width; ++x) for(uint32 y = 0; y < m_Height; ++y) m_Atlas.writePixel(x, y, col); for(imageMapIter iImage = m_Images.begin(); iImage != m_Images.end(); iImage++) WriteImage(iImage->second); MEngine* engine = MEngine::getInstance(); MRenderingContext* render = engine->getRenderingContext(); if(m_TextureID == 0) render->createTexture(&m_TextureID); render->bindTexture(m_TextureID); render->sendTextureImage(&m_Atlas, false, 1, 0); if(clear) { // remove images delete [] m_Layout; m_Layout = NULL; } }
void MGame::onBeginScene(void) { MEngine * engine = MEngine::getInstance(); // get level MLevel * level = MEngine::getInstance()->getLevel(); if(! level) return; // get current scene MScene * scene = level->getCurrentScene(); if(! scene) return; // update objects scene->updateObjectsMatrices(); // start sound scene->playLoopSounds(); // prepare physics scene->preparePhysics(); // run script if(engine->getScriptContext()) engine->getScriptContext()->runScript(scene->getScriptFilename()); }
void MFontRef::update(void * arg) { MEngine * engine = MEngine::getInstance(); if(! m_font) m_font = MFont::getNew(); engine->getFontLoader()->loadData(getFilename(), m_font, arg); }
int ScriptAtlasSelect() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); if(Atlas* atlas = (Atlas*)script->getPointer(0)) atlas->Select(); return 0; }
void MPluginEnd(MScriptExt) { MResource::unregisterFactory("MScriptExt", MScriptExtGetter); MEngine* engine = MEngine::getInstance(); if(engine->getScriptContext() == s_script) engine->setScriptContext(NULL); delete s_script; }
void MMaterialsAnimRef::update(void * arg) { MEngine * engine = MEngine::getInstance(); if(! m_materialsAnim) m_materialsAnim = MMaterialsAnim::getNew(); engine->getMaterialsAnimLoader()->loadData(getFilename(), m_materialsAnim, arg); }
void MTexturesAnimRef::update(void) { MEngine * engine = MEngine::getInstance(); if(! m_texturesAnim) m_texturesAnim = MTexturesAnim::getNew(); engine->getTexturesAnimLoader()->loadData(getFilename(), m_texturesAnim); }
int ScriptAtlasWrite() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); Atlas* atlas = (Atlas*)script->getPointer(0); atlas->Save(); return 0; }
void MMaterialsAnimRef::update(void) { M_PROFILE_SCOPE(MMaterialsAnimRef::update); MEngine * engine = MEngine::getInstance(); if(! m_materialsAnim) m_materialsAnim = MMaterialsAnim::getNew(); engine->getMaterialsAnimLoader()->loadData(getFilename(), m_materialsAnim); }
int ScriptAtlasCreate() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); unsigned int size = script->getInteger(0); const char* name = script->getString(1); script->pushPointer(new Atlas(size, 4, name)); return 1; }
bool MEmbedFile::IsFile(const char* name) { M_PROFILE_SCOPE(MEmbedFile::IsFile); MEngine* engine = MEngine::getInstance(); MSystemContext* system = engine->getSystemContext(); char localFilename[256]; getLocalFilename(localFilename, system->getWorkingDirectory(), name); return strcmp(localFilename, m_Filename) == 0; }
const char* getPubDir() { MEngine* engine = MEngine::getInstance(); MSystemContext* system = engine->getSystemContext(); char dir[256]; getGlobalFilename(dir, system->getWorkingDirectory(), "published"); s_pubDir = dir; return s_pubDir.c_str(); }
int ScriptAtlasImageWrite() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); MImage* image = (MImage*)script->getPointer(0); const char* file = script->getString(1); engine->getImageSaver()->loadData(file, image); return 0; }
int ScriptAtlasImageDestroy() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); MImage* image = (MImage*)script->getPointer(0); if(image) delete image; return 0; }
int ScriptAtlasDestroy() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); Atlas* atlas = (Atlas*)script->getPointer(0); if(atlas) delete atlas; return 0; }
void MScene::begin(void) { MEngine * engine = MEngine::getInstance(); MScriptContext * scriptContext = engine->getScriptContext(); updateObjectsMatrices(); playLoopSounds(); preparePhysics(); // run script if(scriptContext) scriptContext->runScript(getScriptFilename()); }
void MaratisPlayer::logicLoop(void) { MEngine * engine = MEngine::getInstance(); // game MGame * game = engine->getGame(); if(game) { if(game->isRunning()){ game->update(); } } }
void update(void) { MEngine * engine = MEngine::getInstance(); MGame * game = engine->getGame(); if(game) { if(game->isRunning()) { game->update(); } } }
void MaratisPlayer::changeRenderer(const char * name) { MEngine * engine = MEngine::getInstance(); MRendererManager * rendererManager = engine->getRendererManager(); MRendererCreator * renderer = rendererManager->getRendererByName(name); if(renderer) { if(m_renderer) m_renderer->destroy(); m_renderer = renderer->getNewRenderer(); engine->setRenderer(m_renderer); } }
int ScriptAtlasImageGetSize() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); MImage* image = (MImage*)script->getPointer(0); if(image) { script->pushInteger(image->getWidth()); script->pushInteger(image->getHeight()); return 2; } return 0; }
int ScriptAtlasGetSize() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); Atlas* atlas = (Atlas*)script->getPointer(0); if(atlas) { MImage* image = atlas->GetImage(); script->pushInteger(image->getWidth()); script->pushInteger(image->getHeight()); return 2; } return 0; }
void copySysOSX(const char* projName) { #ifdef _DEBUG const char * appName = "MaratisPlayerDebug"; #else const char * appName = "MaratisPlayer"; #endif MWindow * window = MWindow::getInstance(); MEngine* engine = MEngine::getInstance(); MSystemContext* system = engine->getSystemContext(); char filename[256]; getLocalFilename(filename, system->getWorkingDirectory(), projName); if(char* ext = strstr(filename, ".mproj")) { MProject proj; if(proj.loadXML(projName)) { strcpy(ext, ".app"); char path[256]; char srcName[256]; char destName[256]; char appPath[256]; char level[256]; getLocalFilename(level, system->getWorkingDirectory(), proj.startLevel.c_str()); getGlobalFilename(appPath, getPubDir(), filename); sprintf(path, "../../../%s.app", appName); getGlobalFilename(srcName, window->getCurrentDirectory(), path); copyDirectory(srcName, appPath); strcpy(ext, ""); sprintf(srcName, "%s/Contents/MacOS/%s", appPath, appName); strcpy(ext, ".mproj"); embedProject(srcName, srcName, filename, level, proj.renderer.c_str()); chmod(srcName, 0777); // we need to put all data in app/Contents/Resources/ sprintf(destName, "%s/Contents/Resources", appPath); createDirectory(destName); s_dataDir = destName; } } }
int ScriptAtlasGetUVs() { MEngine* engine = MEngine::getInstance(); MScriptContext* script = engine->getScriptContext(); MVector2 uvs[2]; if(Atlas* atlas = (Atlas*)script->getPointer(0)) atlas->GetUVs(uvs, script->getString(1)); script->pushFloat(uvs[0].x); script->pushFloat(uvs[0].y); script->pushFloat(uvs[1].x); script->pushFloat(uvs[1].y); return 4; }
void MSoundRef::update(void) { MEngine * engine = MEngine::getInstance(); MSoundContext * soundContext = engine->getSoundContext(); // force clear clear(); MSound sound; if(engine->getSoundLoader()->loadData(getFilename(), &sound)) { // create new buffer soundContext->createBuffer(&m_bufferId); soundContext->sendBufferSound(m_bufferId, &sound); } }