save::State DatabaseCodec::saveMoves(util::ByteStream const& gameData, Provider const& provider) { //M_REQUIRE(isOpen()); //M_REQUIRE(provider.index() >= 0); GameInfo* info = m_db->m_gameInfoList[provider.index()]; if (gameData.size() > maxGameRecordLength()) return save::GameTooLong; if (provider.plyCount() > maxGameLength()) return save::GameTooLong; unsigned gameOffset = putGame(gameData, info->gameOffset(), info->gameRecordLength()); switch (gameOffset) { /*case util::BlockFile::MaxFileSizeExceeded: IO_RAISE(Game, Max_File_Size_Exceeded, "maximal file size (2 GB) exceeded"); case util::BlockFile::SyncFailed: IO_RAISE(Game, Write_Failed, "sync failed"); case util::BlockFile::ReadError: IO_RAISE(Game, Read_Error, "read error"); case util::BlockFile::IllegalOffset: IO_RAISE(Game, Write_Failed, "offset failure (internal error)");*/ } info->setup(gameOffset, gameData.size()); sync(); return save::Ok; }
/* static */ SQInteger GameInfo::Constructor(HSQUIRRELVM vm) { /* Get the GameInfo */ SQUserPointer instance = NULL; if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == NULL) return sq_throwerror(vm, _SC("Pass an instance of a child class of GameInfo to RegisterGame")); GameInfo *info = (GameInfo *)instance; SQInteger res = ScriptInfo::Constructor(vm, info); if (res != 0) return res; if (info->engine->MethodExists(*info->SQ_instance, "MinVersionToLoad")) { if (!info->engine->CallIntegerMethod(*info->SQ_instance, "MinVersionToLoad", &info->min_loadable_version, MAX_GET_OPS)) return SQ_ERROR; } else { info->min_loadable_version = info->GetVersion(); } /* When there is an IsSelectable function, call it. */ if (info->engine->MethodExists(*info->SQ_instance, "IsDeveloperOnly")) { if (!info->engine->CallBoolMethod(*info->SQ_instance, "IsDeveloperOnly", &info->is_developer_only, MAX_GET_OPS)) return SQ_ERROR; } else { info->is_developer_only = false; } /* Try to get the API version the AI is written for. */ if (!info->CheckMethod("GetAPIVersion")) return SQ_ERROR; if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAPIVersion", &info->api_version, MAX_GET_OPS)) return SQ_ERROR; if (!CheckAPIVersion(info->api_version)) { DEBUG(script, 1, "Loading info.nut from (%s.%d): GetAPIVersion returned invalid version", info->GetName(), info->GetVersion()); return SQ_ERROR; } /* Remove the link to the real instance, else it might get deleted by RegisterGame() */ sq_setinstanceup(vm, 2, NULL); /* Register the Game to the base system */ info->GetScanner()->RegisterScript(info); return 0; }
void do_argv(int* argc, char*** argv, GameInfo &gameInfo) { while(true) { if(strcmp(**argv, "-t") == 0) { (*argv)++; (*argc)--; gameInfo.setTeamName(**argv); } else if(strcmp(**argv, "-p") == 0) { (*argv)++; (*argc)--; gameInfo.setTeamPassword(**argv); } else if(strcmp(**argv, "-m") == 0) { (*argv)++; (*argc)--; gameInfo.setMatchToken(**argv); } else if(strcmp(**argv, "-n") == 0) { (*argv)++; (*argc)--; gameInfo.setHostName(**argv); } // move to next command if(*argc > 1) { (*argv)++; (*argc)--; } else { break; } } }
UI::EventReturn GameScreen::OnCreateShortcut(UI::EventParams &e) { GameInfo *info = g_gameInfoCache.GetInfo(NULL, gamePath_, 0); if (info) { host->CreateDesktopShortcut(gamePath_, info->GetTitle()); } return UI::EVENT_DONE; }
void Client::run(int argc, char* argv[]) { argv++; argc--; if(argc < 8) { cout << "usage: " << client_usage_string << endl; exit(1); } GameInfo gameInfo; do_argv(&argc, &argv, gameInfo); cout << "Starting Battle Tetris Client..." << endl; Command command; string connectCmd = command.getMatchConnectCommand(gameInfo); cout << "Connecting to server..." << endl; Communication comm(gameInfo.getHostName()); string clientToken = comm.send(connectCmd, Command::Keys::CLIENT_TOKEN); gameInfo.setClientToken(clientToken); cout << "Received client token... " << gameInfo.getClientToken() << endl; cout << "Starting game..." << endl; /// /// ADD ALGORITHM cout << "Missing algorithm..." << endl; /// cout << "Exiting..." << endl; }
void JudgeDredd::putPieceOnMap(GameInfo& game, coord_t& coord) { this->twinTriple(game, coord); game.putPieceOnMap(coord); game.incScore(takeAPiece(game, coord)); this->lookAlignement(game, coord); game.endRoundOfPlayer(); }
void GameScreen::CallbackDeleteSaveData(bool yes) { GameInfo *info = g_gameInfoCache.GetInfo(NULL, gamePath_, 0); if (yes) { info->DeleteAllSaveData(); info->saveDataSize = 0; info->installDataSize = 0; } }
void GameScreen::CallbackDeleteGame(bool yes) { GameInfo *info = g_gameInfoCache.GetInfo(NULL, gamePath_, 0); if (yes) { info->Delete(); g_gameInfoCache.Clear(); screenManager()->switchScreen(new MainScreen()); } }
string Command::getMatchConnectCommand(GameInfo gameInfo) { cJSON *root = cJSON_CreateObject(); cJSON_AddItemToObject(root, "comm_type", cJSON_CreateString("MatchConnect")); cJSON_AddItemToObject(root, "team_name", cJSON_CreateString(gameInfo.getTeamName().c_str())); cJSON_AddItemToObject(root, "password", cJSON_CreateString(gameInfo.getTeamPassword().c_str())); cJSON_AddItemToObject(root, "match_token", cJSON_CreateString(gameInfo.getMatchToken().c_str())); return cJSON_PrintUnformatted(root); }
void GameScreen::CreateViews() { GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, GAMEINFO_WANTBG | GAMEINFO_WANTSIZE); I18NCategory *d = GetI18NCategory("Dialog"); I18NCategory *ga = GetI18NCategory("Game"); // Information in the top left. // Back button to the bottom left. // Scrolling action menu to the right. using namespace UI; Margins actionMenuMargins(0, 100, 15, 0); root_ = new LinearLayout(ORIENT_HORIZONTAL); ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f)); root_->Add(leftColumn); leftColumn->Add(new Choice(d->T("Back"), "", false, new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle(this, &GameScreen::OnSwitchBack); if (info) { texvGameIcon_ = leftColumn->Add(new TextureView(0, IS_DEFAULT, new AnchorLayoutParams(144 * 2, 80 * 2, 10, 10, NONE, NONE))); tvTitle_ = leftColumn->Add(new TextView(info->title, ALIGN_LEFT, false, new AnchorLayoutParams(10, 200, NONE, NONE))); // This one doesn't need to be updated. leftColumn->Add(new TextView(gamePath_, ALIGN_LEFT, true, new AnchorLayoutParams(10, 250, NONE, NONE))); tvGameSize_ = leftColumn->Add(new TextView("...", ALIGN_LEFT, true, new AnchorLayoutParams(10, 290, NONE, NONE))); tvSaveDataSize_ = leftColumn->Add(new TextView("...", ALIGN_LEFT, true, new AnchorLayoutParams(10, 320, NONE, NONE))); tvInstallDataSize_ = leftColumn->Add(new TextView("", ALIGN_LEFT, true, new AnchorLayoutParams(10, 350, NONE, NONE))); tvRegion_ = leftColumn->Add(new TextView("", ALIGN_LEFT, true, new AnchorLayoutParams(10, 380, NONE, NONE))); } ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins)); root_->Add(rightColumn); LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL); rightColumnItems->SetSpacing(0.0f); rightColumn->Add(rightColumnItems); Choice *play = new Choice(ga->T("Play")); rightColumnItems->Add(play)->OnClick.Handle(this, &GameScreen::OnPlay); rightColumnItems->Add(new Choice(ga->T("Game Settings")))->OnClick.Handle(this, &GameScreen::OnGameSettings); std::vector<std::string> saveDirs = info->GetSaveDataDirectories(); if (saveDirs.size()) { rightColumnItems->Add(new Choice(ga->T("Delete Save Data")))->OnClick.Handle(this, &GameScreen::OnDeleteSaveData); } rightColumnItems->Add(new Choice(ga->T("Delete Game")))->OnClick.Handle(this, &GameScreen::OnDeleteGame); if (host->CanCreateShortcut()) { rightColumnItems->Add(new Choice(ga->T("Create Shortcut")))->OnClick.Handle(this, &GameScreen::OnCreateShortcut); } if (isRecentGame(gamePath_)) { rightColumnItems->Add(new Choice(ga->T("Remove From Recent")))->OnClick.Handle(this, &GameScreen::OnRemoveFromRecent); } #ifdef _WIN32 rightColumnItems->Add(new Choice(ga->T("Show In Folder")))->OnClick.Handle(this, &GameScreen::OnShowInFolder); #endif UI::SetFocusedView(play); }
void DatabaseCodec::getGameRecord(GameInfo const& info, util::BlockFile& reader, util::ByteStream& src) { switch (reader.get(src, info.gameOffset(), info.gameRecordLength())) {/* case util::BlockFile::SyncFailed: IO_RAISE(Game, Write_Failed, "sync failed (write error)"); case util::BlockFile::IllegalOffset: IO_RAISE(Game, Corrupted, "illegal offset"); case util::BlockFile::ReadError: IO_RAISE(Game, Read_Error, "read error");*/ } }
UI::EventReturn SavedataScreen::OnSavedataButtonClick(UI::EventParams &e) { GameInfo *ginfo = g_gameInfoCache->GetInfo(screenManager()->getDrawContext(), e.s, 0); SavedataPopupScreen *popupScreen = new SavedataPopupScreen(e.s, ginfo->GetTitle()); if (e.v) { popupScreen->SetPopupOrigin(e.v); } screenManager()->push(popupScreen); // the game path: e.s; return UI::EVENT_DONE; }
// Runs on the main thread. GameInfo *GameInfoCache::GetInfo(Thin3DContext *thin3d, const std::string &gamePath, int wantFlags) { GameInfo *info = 0; auto iter = info_.find(gamePath); if (iter != info_.end()) { info = iter->second; if ((info->wantFlags & wantFlags) != wantFlags) { // Need to start over. We'll just add a new work item. goto again; } if (thin3d && info->iconDataLoaded) { SetupTexture(info, info->iconTextureData, thin3d, info->iconTexture, info->timeIconWasLoaded); info->iconDataLoaded = false; } if (thin3d && info->pic0DataLoaded) { SetupTexture(info, info->pic0TextureData, thin3d, info->pic0Texture, info->timePic0WasLoaded); info->pic0DataLoaded = false; } if (thin3d && info->pic1DataLoaded) { SetupTexture(info, info->pic1TextureData, thin3d, info->pic1Texture, info->timePic1WasLoaded); info->pic1DataLoaded = false; } iter->second->lastAccessedTime = time_now_d(); return iter->second; } again: if (!info) { info = new GameInfo(); } { lock_guard lock(info->lock); if (info->IsWorking()) { // Uh oh, it's currently in process. It could mark pending = false with the wrong wantFlags. // Let's wait it out, then queue. WaitUntilDone(info); } info->wantFlags |= wantFlags; info->pending = true; } GameInfoWorkItem *item = new GameInfoWorkItem(gamePath, info); gameInfoWQ_->Add(item); info_[gamePath] = info; return info; }
void GameScreen::update(InputState &input) { UIScreen::update(input); I18NCategory *ga = GetI18NCategory("Game"); Thin3DContext *thin3d = screenManager()->getThin3DContext(); GameInfo *info = g_gameInfoCache.GetInfo(thin3d, gamePath_, GAMEINFO_WANTBG | GAMEINFO_WANTSIZE); if (tvTitle_) tvTitle_->SetText(info->GetTitle() + " (" + info->id + ")"); if (info->iconTexture && texvGameIcon_) { texvGameIcon_->SetTexture(info->iconTexture); // Fade the icon with the background. double loadTime = info->timeIconWasLoaded; if (info->pic1Texture) { loadTime = std::max(loadTime, info->timePic1WasLoaded); } if (info->pic0Texture) { loadTime = std::max(loadTime, info->timePic0WasLoaded); } uint32_t color = whiteAlpha(ease((time_now_d() - loadTime) * 3)); texvGameIcon_->SetColor(color); } if (info->gameSize) { char temp[256]; sprintf(temp, "%s: %1.1f %s", ga->T("Game"), (float) (info->gameSize) / 1024.f / 1024.f, ga->T("MB")); tvGameSize_->SetText(temp); sprintf(temp, "%s: %1.2f %s", ga->T("SaveData"), (float) (info->saveDataSize) / 1024.f / 1024.f, ga->T("MB")); tvSaveDataSize_->SetText(temp); if (info->installDataSize > 0) { sprintf(temp, "%s: %1.2f %s", ga->T("InstallData"), (float) (info->installDataSize) / 1024.f / 1024.f, ga->T("MB")); tvInstallDataSize_->SetText(temp); } } if (info->region >= 0 && info->region < GAMEREGION_MAX && info->region != GAMEREGION_OTHER) { static const char *regionNames[GAMEREGION_MAX] = { "Japan", "USA", "Europe", "Hong Kong", "Asia" }; tvRegion_->SetText(ga->T(regionNames[info->region])); } }
UI::EventReturn GameScreen::OnDeleteSaveData(UI::EventParams &e) { I18NCategory *d = GetI18NCategory("Dialog"); I18NCategory *ga = GetI18NCategory("Game"); GameInfo *info = g_gameInfoCache.GetInfo(NULL, gamePath_, GAMEINFO_WANTBG | GAMEINFO_WANTSIZE); if (info) { // Check that there's any savedata to delete std::vector<std::string> saveDirs = info->GetSaveDataDirectories(); if (saveDirs.size()) { screenManager()->push( new PromptScreen(d->T("DeleteConfirmAll", "Do you really want to delete all\nyour save data for this game?"), ga->T("ConfirmDelete"), d->T("Cancel"), std::bind(&GameScreen::CallbackDeleteSaveData, this, placeholder::_1))); } } RecreateViews(); return UI::EVENT_DONE; }
GameInfo *GameScannerInfo::FindInfo(const char *nameParam, int versionParam, bool force_exact_match) { if (this->info_list.size() == 0) return NULL; if (nameParam == NULL) return NULL; char game_name[1024]; ttd_strlcpy(game_name, nameParam, sizeof(game_name)); strtolower(game_name); GameInfo *info = NULL; int version = -1; if (versionParam == -1) { /* We want to load the latest version of this Game script; so find it */ if (this->info_single_list.find(game_name) != this->info_single_list.end()) return static_cast<GameInfo *>(this->info_single_list[game_name]); /* If we didn't find a match Game script, maybe the user included a version */ char *e = strrchr(game_name, '.'); if (e == NULL) return NULL; *e = '\0'; e++; versionParam = atoi(e); /* FALL THROUGH, like we were calling this function with a version. */ } if (force_exact_match) { /* Try to find a direct 'name.version' match */ char game_name_tmp[1024]; snprintf(game_name_tmp, sizeof(game_name_tmp), "%s.%d", game_name, versionParam); strtolower(game_name_tmp); if (this->info_list.find(game_name_tmp) != this->info_list.end()) return static_cast<GameInfo *>(this->info_list[game_name_tmp]); } /* See if there is a compatible Game script which goes by that name, with the highest * version which allows loading the requested version */ ScriptInfoList::iterator it = this->info_list.begin(); for (; it != this->info_list.end(); it++) { GameInfo *i = static_cast<GameInfo *>((*it).second); if (strcasecmp(game_name, i->GetName()) == 0 && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) { version = (*it).second->GetVersion(); info = i; } } return info; }
void rendering::render_time(sf::RenderWindow& screen,const GameInfo& stats) { static sf::Text text; static sf::Font f; f.loadFromFile("../data/Font/Loma.ttf"); text.setFont(f); text.setColor(sf::Color::Red); text.setCharacterSize(24); text.setPosition(700,100); text.setString(stats.GetFormattedElapsed()); screen.draw(text); text.setString(std::to_string(stats.getFps())); text.setPosition(700,125); screen.draw(text); }
void play(GameInfo& info) { int power = (13 <= info.turn && info.turn < 20 ? 10 : 7); while (power >= 2) { int action = generator()/1024%10 + 1; static const int required[] = {0, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1}; if (required[action] <= power && info.isValid(action)) { power -= required[action]; info.doAction(action); } } if (power != 0) { if (generator()/1024%11>8) { int action = (info.samuraiInfo[info.weapon].hidden ? 10 : 9); if (info.isValid(action)) { info.doAction(action); } } } }
pacman_interface::PacmanAction BehaviorKeyboardAgent::getHuntAction(GameInfo game_info) { pacman_interface::PacmanAction action; GameInfo game_info_ = game_info; geometry_msgs::Pose pacman_pose = game_info_.getPacmanPose(); std::map< std::pair<int, int>, int > distances = game_info_.getDistances(pacman_pose.position.x, pacman_pose.position.y); int min_distance = util::MAX_DISTANCE; game_info.printMap(); std::vector< geometry_msgs::Pose > ghosts_poses = game_info_.getGhostsPoses(); std::vector< geometry_msgs::Pose >::reverse_iterator closest_ghost = ghosts_poses.rend(); ROS_INFO_STREAM("Ghost size: " << ghosts_poses.size() << " num: " << game_info_.getNumberOfGhosts(););
extern "C" jstring Java_org_ppsspp_ppsspp_ShortcutActivity_queryGameName(JNIEnv *env, jclass, jstring jpath) { std::string path = GetJavaString(env, jpath); std::string result = ""; GameInfoCache *cache = new GameInfoCache(); GameInfo *info = cache->GetInfo(nullptr, path, 0); // Wait until it's done: this is synchronous, unfortunately. if (info) { cache->WaitUntilDone(info); if (info->fileType != FILETYPE_UNKNOWN) { result = info->GetTitle(); // Pretty arbitrary, but the home screen will often truncate titles. // Let's remove "The " from names since it's common in English titles. if (result.length() > strlen("The ") && startsWithNoCase(result, "The ")) { result = result.substr(strlen("The ")); } } } delete cache; return env->NewStringUTF(result.c_str()); }
void MenuList::AddItem( GameInfo gameInfo, SDL_Renderer* renderer, TTF_Font* font, const SDL_Color &color ) { std::string gameLine = gameInfo.GetAsSrting(); SDL_Rect r; r.x = GetMainArea().rect.x + 10; r.y = GetItemsTop(); SDL_Texture* text = RenderHelpers::RenderTextTexture_Solid ( font, gameLine, color, r, renderer ); AddItem( gameInfo, gameLine, text, r ); }
VOID Player::turn(ProgramManager &rProgramManager, GameInfo &rGameInfo) { if(rGameInfo.first == first_) { if(rGameInfo.scoredEight) rProgramManager.endGame(name_ + L" выиграл со счЄтом: " + getScoreWStr()); else if(rGameInfo.scoredZero) { rGameInfo.scoredZero = FALSE; rGameInfo.drawCue = FALSE; rGameInfo.turn = Turns::SetZeroPos; rProgramManager.updateZero(); } else if(rGameInfo.scoredWrong) { rGameInfo.scoredWrong = FALSE; rGameInfo.drawCue = FALSE; rGameInfo.turn = Turns::SetPos; } if(!copied_) { memcpy(tmpBallsStatus_, rProgramManager.getScored(), sizeof(tmpBallsStatus_)); memcpy(tmpBallsPos_, rProgramManager.getPoints(), sizeof(tmpBallsPos_)); copied_ = !copied_; } if(rGameInfo.turn == Turns::SetZeroPos) { rProgramManager.setBallCoords(rProgramManager.getMousePos()); rProgramManager.work(textToDraw(), PointF(0, 0), static_cast<ARGB>(Color::LightGreen), FALSE); if(Key(VK_END)) { rGameInfo.turn = Turns::Blow; rGameInfo.drawCue = TRUE; } } else if(rGameInfo.turn == Turns::SetPos) { rProgramManager.setBallCoords(rProgramManager.getMousePos(), rGameInfo.wrongBall); rProgramManager.work(textToDraw(), PointF(0, 0), static_cast<ARGB>(Color::LightGreen), FALSE); if(Key(VK_END)) { rGameInfo.turn = Turns::Blow; rGameInfo.drawCue = TRUE; } } else if(rGameInfo.turn == Turns::Blow) { if(Key(VK_SPACE)) { POINT cursor = { 0, 0 }; GetCursorPos(&cursor); rProgramManager.nextMove(); rGameInfo.turn = Turns::Step; } else rProgramManager.work(textToDraw()); } else if(rGameInfo.turn == Turns::Step) { if(!rProgramManager.stopBalls()) rProgramManager.work(textToDraw()); else { updateScore(checkScored(rProgramManager, rGameInfo)); if(!checkPoints(rProgramManager)) if(score_ != 0) score_--; resetValues(); rGameInfo.resetToNext(); } } } else rProgramManager.work(textToDraw(), PointF(static_cast<REAL>(rProgramManager.getMemDCWindow().width - 6 * sizestenaRIGHT), 0), static_cast<ARGB>(Color::Red), rGameInfo.drawCue); }
void SavedataButton::Draw(UIContext &dc) { GameInfo *ginfo = g_gameInfoCache->GetInfo(dc.GetDrawContext(), savePath_, GAMEINFO_WANTSIZE); Draw::Texture *texture = 0; u32 color = 0, shadowColor = 0; using namespace UI; if (ginfo->icon.texture) { texture = ginfo->icon.texture->GetTexture(); } int x = bounds_.x; int y = bounds_.y; int w = 144; int h = bounds_.h; UI::Style style = dc.theme->itemStyle; if (down_) style = dc.theme->itemDownStyle; h = bounds_.h; if (HasFocus()) style = down_ ? dc.theme->itemDownStyle : dc.theme->itemFocusedStyle; Drawable bg = style.background; dc.Draw()->Flush(); dc.RebindTexture(); dc.FillRect(bg, bounds_); dc.Draw()->Flush(); if (texture) { color = whiteAlpha(ease((time_now_d() - ginfo->icon.timeLoaded) * 2)); shadowColor = blackAlpha(ease((time_now_d() - ginfo->icon.timeLoaded) * 2)); float tw = texture->Width(); float th = texture->Height(); // Adjust position so we don't stretch the image vertically or horizontally. // TODO: Add a param to specify fit? The below assumes it's never too wide. float nw = h * tw / th; x += (w - nw) / 2.0f; w = nw; } int txOffset = down_ ? 4 : 0; txOffset = 0; Bounds overlayBounds = bounds_; // Render button int dropsize = 10; if (texture) { if (txOffset) { dropsize = 3; y += txOffset * 2; overlayBounds.y += txOffset * 2; } if (HasFocus()) { dc.Draw()->Flush(); dc.RebindTexture(); float pulse = sinf(time_now() * 7.0f) * 0.25 + 0.8; dc.Draw()->DrawImage4Grid(dc.theme->dropShadow4Grid, x - dropsize*1.5f, y - dropsize*1.5f, x + w + dropsize*1.5f, y + h + dropsize*1.5f, alphaMul(color, pulse), 1.0f); dc.Draw()->Flush(); } else { dc.Draw()->Flush(); dc.RebindTexture(); dc.Draw()->DrawImage4Grid(dc.theme->dropShadow4Grid, x - dropsize, y - dropsize*0.5f, x + w + dropsize, y + h + dropsize*1.5, alphaMul(shadowColor, 0.5f), 1.0f); dc.Draw()->Flush(); } } if (texture) { dc.Draw()->Flush(); dc.GetDrawContext()->BindTexture(0, texture); dc.Draw()->DrawTexRect(x, y, x + w, y + h, 0, 0, 1, 1, color); dc.Draw()->Flush(); } dc.Draw()->Flush(); dc.RebindTexture(); dc.SetFontStyle(dc.theme->uiFont); float tw, th; dc.Draw()->Flush(); dc.PushScissor(bounds_); const std::string currentTitle = ginfo->GetTitle(); if (!currentTitle.empty()) { title_ = CleanSaveString(currentTitle); } if (subtitle_.empty() && ginfo->gameSize > 0) { std::string savedata_title = ginfo->paramSFO.GetValueString("SAVEDATA_TITLE"); subtitle_ = CleanSaveString(savedata_title) + StringFromFormat(" (%d kB)", ginfo->gameSize / 1024); } dc.MeasureText(dc.GetFontStyle(), 1.0f, 1.0f, title_.c_str(), &tw, &th, 0); int availableWidth = bounds_.w - 150; float sineWidth = std::max(0.0f, (tw - availableWidth)) / 2.0f; float tx = 150; if (availableWidth < tw) { float overageRatio = 1.5f * availableWidth * 1.0f / tw; tx -= (1.0f + sin(time_now_d() * overageRatio)) * sineWidth; Bounds tb = bounds_; tb.x = bounds_.x + 150; tb.w = bounds_.w - 150; dc.PushScissor(tb); } dc.DrawText(title_.c_str(), bounds_.x + tx, bounds_.y + 4, style.fgColor, ALIGN_TOPLEFT); dc.SetFontScale(0.6f, 0.6f); dc.DrawText(subtitle_.c_str(), bounds_.x + tx, bounds_.y2() - 7, style.fgColor, ALIGN_BOTTOM); dc.SetFontScale(1.0f, 1.0f); if (availableWidth < tw) { dc.PopScissor(); } dc.Draw()->Flush(); dc.PopScissor(); dc.RebindTexture(); }
UI::EventReturn SavedataPopupScreen::OnDeleteButtonClick(UI::EventParams &e) { GameInfo *ginfo = g_gameInfoCache->GetInfo(nullptr, savePath_, GAMEINFO_WANTSIZE); ginfo->Delete(); TriggerFinish(DR_NO); return UI::EVENT_DONE; }
save::State DatabaseCodec::updateCharacteristics(unsigned index, TagSet const& tags) { //M_REQUIRE(isOpen()); typedef Namebase::PlayerEntry* Player; typedef Namebase::EventEntry* Event; typedef Namebase::SiteEntry* Site; typedef Namebase::Entry* Entry; GameInfo* info = m_db->m_gameInfoList[index]; *m_storedInfo = *info; info->resetCharacteristics(m_db->m_namebases); unsigned maxAnnotatorCount = this->maxAnnotatorCount(); unsigned maxPlayerCount = this->maxPlayerCount(); InfoData data(tags); Player whiteEntry = namebase(Namebase::Player).insertPlayer( tags.value(tag::White), data.whiteCountry, data.whiteTitle, data.whiteType, data.whiteSex, data.whiteFideID, maxPlayerCount); Player blackEntry = namebase(Namebase::Player).insertPlayer( tags.value(tag::Black), data.blackCountry, data.blackTitle, data.blackType, data.blackSex, data.blackFideID, maxPlayerCount); Site siteEntry = namebase(Namebase::Site).insertSite( tags.value(tag::Site), data.eventCountry, maxSiteCount()); Event eventEntry = namebase(Namebase::Event).insertEvent( tags.value(tag::Event), data.eventDate, data.eventType, data.timeMode, data.eventMode, maxEventCount(), siteEntry ? siteEntry : NamebaseEvent::emptySite()); Entry annotatorEntry = NamebaseEntry::emptyEntry(); if (maxAnnotatorCount) { annotatorEntry = namebase(Namebase::Annotator). insert(tags.value(tag::Annotator), maxAnnotatorCount); } bool failed = whiteEntry == 0 || blackEntry == 0 || eventEntry == 0 || siteEntry == 0 || annotatorEntry == 0; save::State state = save::Ok; if (!failed && format() != format::Scidb) { } if (failed) { info->restore(*m_storedInfo, m_db->m_namebases); namebases().update(); if (!whiteEntry) return save::TooManyPlayerNames; if (!blackEntry) return save::TooManyPlayerNames; if (!eventEntry) return save::TooManyEventNames; if (!siteEntry) return save::TooManySiteNames; return save::TooManyAnnotatorNames; } info->update( whiteEntry, blackEntry, eventEntry, annotatorEntry, tags, m_db->m_namebases); return state; }
save::State DatabaseCodec::saveGame(ByteStream const& gameData, TagSet const& tags, Provider const& provider) { //M_REQUIRE(isOpen()); typedef Namebase::PlayerEntry* Player; typedef Namebase::EventEntry* Event; typedef Namebase::SiteEntry* Site; typedef Namebase::Entry* Entry; if (gameData.size() > maxGameRecordLength()) return save::GameTooLong; if (provider.plyCount() > maxGameLength()) return save::GameTooLong; GameInfo* info = 0; unsigned index; if (provider.index() >= 0) { index = provider.index(); info = m_db->m_gameInfoList[index]; *m_storedInfo = *info; info->reset(m_db->m_namebases); } else if (m_db->size() == maxGameCount()) { return save::TooManyGames; } else { index = m_db->m_gameInfoList.size(); } unsigned maxAnnotatorCount = this->maxAnnotatorCount(); unsigned maxPlayerCount = this->maxPlayerCount(); InfoData data(tags); Player whiteEntry; Player blackEntry; Site siteEntry; switch (provider.sourceFormat()) { case format::Scid3: case format::Scid4: { mstl::string name; whiteEntry = namebase(Namebase::Player).insertPlayer( ::normalizePlayerName(tags.value(tag::White), name), data.whiteCountry, data.whiteTitle, data.whiteType, data.whiteSex, data.whiteFideID, maxPlayerCount); blackEntry = namebase(Namebase::Player).insertPlayer( ::normalizePlayerName(tags.value(tag::Black), name), data.blackCountry, data.blackTitle, data.blackType, data.blackSex, data.blackFideID, maxPlayerCount); siteEntry = namebase(Namebase::Site).insertSite( ::normalizeSiteName(tags.value(tag::Site), name), data.eventCountry, maxSiteCount()); } break; default: whiteEntry = namebase(Namebase::Player).insertPlayer( tags.value(tag::White), data.whiteCountry, data.whiteTitle, data.whiteType, data.whiteSex, data.whiteFideID, maxPlayerCount); blackEntry = namebase(Namebase::Player).insertPlayer( tags.value(tag::Black), data.blackCountry, data.blackTitle, data.blackType, data.blackSex, data.blackFideID, maxPlayerCount); siteEntry = namebase(Namebase::Site).insertSite( tags.value(tag::Site), data.eventCountry, maxSiteCount()); } Event eventEntry = namebase(Namebase::Event).insertEvent( tags.value(tag::Event), data.eventDate, data.eventType, data.timeMode, data.eventMode, maxEventCount(), siteEntry ? siteEntry : NamebaseEvent::emptySite()); Entry annotatorEntry = NamebaseEntry::emptyEntry(); if (maxAnnotatorCount) { annotatorEntry = namebase(Namebase::Annotator).insert(tags.value(tag::Annotator), maxAnnotatorCount); } save::State state = save::Ok; bool failed = whiteEntry == 0 || blackEntry == 0 || eventEntry == 0 || siteEntry == 0 || annotatorEntry == 0; unsigned gameOffset = 0; // shut up compiler if (!failed) { if (info) gameOffset = putGame(gameData, info->gameOffset(), info->gameRecordLength()); else gameOffset = putGame(gameData); } if (failed || int(gameOffset) < 0) { if (info) info->restore(*m_storedInfo, m_db->m_namebases); namebases().update(); switch (gameOffset) { /*case util::BlockFile::MaxFileSizeExceeded: IO_RAISE(Game, Max_File_Size_Exceeded, "maximal file size (2 GB) exceeded"); case util::BlockFile::SyncFailed: IO_RAISE(Game, Write_Failed, "sync failed"); case util::BlockFile::ReadError: IO_RAISE(Game, Read_Error, "read error"); case util::BlockFile::IllegalOffset: IO_RAISE(Game, Write_Failed, "offset failure (internal error)");*/ } if (!whiteEntry) return save::TooManyPlayerNames; if (!blackEntry) return save::TooManyPlayerNames; if (!eventEntry) return save::TooManyEventNames; if (!siteEntry) return save::TooManySiteNames; return save::TooManyAnnotatorNames; } if (info == 0) { info = allocGameInfo(); m_db->m_gameInfoList.push_back(info); } info->setup(gameOffset, gameData.size(), whiteEntry, blackEntry, eventEntry, annotatorEntry, tags, provider, m_db->m_namebases); return state; }
void GameScreen::CallbackDeleteSaveData(bool yes) { GameInfo *info = g_gameInfoCache.GetInfo(gamePath_, false); if (yes) { info->DeleteAllSaveData(); } }
RuntimeGame::RuntimeGame(_In_ const DeviceContext& deviceContext) : _deviceContext(deviceContext), _game(g_gameInfo.onCreate(deviceContext)) { }
namespace GDK { static GameInfo g_gameInfo; static bool g_gameActive = false; namespace Game { void RegisterGame(_In_ const GameInfo& gameInfo) { CHECK_FALSE(g_gameActive); g_gameInfo = gameInfo; } std::shared_ptr<IRunningGame> Create(_In_ const DeviceContext& deviceContext) { CHECK_NOT_NULL(g_gameInfo.onCreate); return RuntimeGame::Create(deviceContext); } std::shared_ptr<IRunningGame> Create(_In_ const DeviceContext& deviceContext, _In_ const std::shared_ptr<GameWorldContent>& initialWorld) { CHECK_NOT_NULL(g_gameInfo.onCreate); return RuntimeGame::Create(deviceContext, initialWorld); } } std::shared_ptr<IRunningGame> RuntimeGame::Create(_In_ const DeviceContext& deviceContext) { std::shared_ptr<RuntimeGame> game(GDKNEW RuntimeGame(deviceContext)); game->LoadWorld(Content::LoadGameWorldContent(g_gameInfo.firstWorld)); return game; } std::shared_ptr<IRunningGame> RuntimeGame::Create(_In_ const DeviceContext& deviceContext, _In_ const std::shared_ptr<GameWorldContent>& initialWorld) { std::shared_ptr<RuntimeGame> game(GDKNEW RuntimeGame(deviceContext)); game->LoadWorld(initialWorld); return game; } RuntimeGame::RuntimeGame(_In_ const DeviceContext& deviceContext) : _deviceContext(deviceContext), _game(g_gameInfo.onCreate(deviceContext)) { } RuntimeGame::~RuntimeGame() { if (_deviceContext.audioDevice) { _deviceContext.audioDevice->StopAllLoopingClips(); } } const std::wstring& RuntimeGame::GetName() const { return g_gameInfo.name; } UpdateResult RuntimeGame::Update(_In_ const GameTime& gameTime) { Input::Tick(); _deviceContext.audioDevice->Tick(); UpdateResult result = UpdateResult::Continue; result = _game->OnUpdateBegin(gameTime); if (result == UpdateResult::Continue) { _world->Update(gameTime); result = _game->OnUpdateEnd(gameTime); } return result; } void RuntimeGame::Draw() { Matrix view, projection; _game->OnDrawBegin(&view, &projection); _world->Draw(view, projection); _game->OnDrawEnd(view, projection); } void RuntimeGame::LoadWorld(_In_ const std::shared_ptr<GameWorldContent>& nextWorld) { _world = RuntimeGameWorld::Create(nextWorld, _deviceContext, false); _game->OnWorldChanged(_world); } }
save::State DatabaseCodec::addGame(ByteStream const& gameData, GameInfo const& info, Allocation allocation) { //M_REQUIRE(isOpen()); if (m_db->size() == maxGameCount()) return save::TooManyGames; if (gameData.size() > maxGameRecordLength() || info.plyCount() > maxGameLength()) return save::GameTooLong; mstl::string whitePlayer; mstl::string blackPlayer; mstl::string event; mstl::string site; mstl::string annotator; if (allocation == Alloc) { namebase(Namebase::Player).copy(whitePlayer, info.playerName(color::White)); namebase(Namebase::Player).copy(blackPlayer, info.playerName(color::Black)); namebase(Namebase::Event).copy(event, info.event()); namebase(Namebase::Site).copy(site, info.site()); namebase(Namebase::Annotator).copy(annotator, info.annotator()); } else { whitePlayer.hook(info.playerName(color::White)); blackPlayer.hook(info.playerName(color::Black)); event.hook(info.event()); site.hook(info.site()); annotator.hook(info.annotator()); } unsigned maxAnnotatorCount = this->maxAnnotatorCount(); NamebasePlayer* whiteEntry; NamebasePlayer* blackEntry; NamebaseSite* siteEntry; NamebaseEvent* eventEntry; NamebaseEntry* annotatorEntry = NamebaseEntry::emptyEntry(); unsigned maxPlayerCount = this->maxPlayerCount(); whiteEntry = namebase(Namebase::Player).insertPlayer( whitePlayer, info.federation(color::White), info.title(color::White), info.playerType(color::White), info.sex(color::White), info.fideID(color::White), maxPlayerCount); blackEntry = namebase(Namebase::Player).insertPlayer( blackPlayer, info.federation(color::Black), info.title(color::Black), info.playerType(color::Black), info.sex(color::Black), info.fideID(color::Black), maxPlayerCount); siteEntry = namebase(Namebase::Site).insertSite( site, info.eventCountry(), maxSiteCount()); eventEntry = namebase(Namebase::Event).insertEvent( event, info.eventDate(), info.eventType(), info.timeMode(), info.eventMode(), maxEventCount(), siteEntry ?siteEntry : NamebaseEvent::emptySite()); if (maxAnnotatorCount) annotatorEntry = namebase(Namebase::Annotator).insert(annotator, maxAnnotatorCount); bool failed = whiteEntry == 0 || blackEntry == 0 || eventEntry == 0 || siteEntry == 0 || annotatorEntry == 0; save::State state = save::Ok; if (!failed && format() != format::Scidb) { } unsigned gameOffset = 0; // shut up compiler if (failed || int(gameOffset = putGame(gameData)) < 0) { namebases().update(); switch (gameOffset) { /*case util::BlockFile::MaxFileSizeExceeded: IO_RAISE(Game, Max_File_Size_Exceeded, "maximal file size (2 GB) exceeded"); case util::BlockFile::SyncFailed: IO_RAISE(Game, Write_Failed, "sync failed"); case util::BlockFile::ReadError: IO_RAISE(Game, Read_Error, "read error"); case util::BlockFile::IllegalOffset: IO_RAISE(Game, Write_Failed, "offset failure (internal error)");*/ } if (!whiteEntry) return save::TooManyPlayerNames; if (!blackEntry) return save::TooManyPlayerNames; if (!eventEntry) return save::TooManyEventNames; if (!siteEntry) return save::TooManySiteNames; return save::TooManyAnnotatorNames; } GameInfo* i = allocGameInfo(); *i = info; i->setup( gameOffset, gameData.size(), whiteEntry, blackEntry, eventEntry, annotatorEntry, m_db->m_namebases); m_db->m_gameInfoList.push_back(i); return state; }