bool graphicsRenderDebugMsg( GameMap* MainMap) { if (!gRDM_Show) return true; #define my_get_tiny_guid(_a) (_a * 1.0842021724855044340074528008699e-19) std::vector<std::string> Vec; std::map<double, Entity*> LifeIdx; // Initializing initial font database if (gRDM_FVec.size() < 11) for (int i = 0; i < 11; i++) gRDM_FVec.push_back(new GuiFont); for (int i = 0; i < 11; i++) if (gRDM_FVec[i]->RequireUpdate()) gRDM_FVec[i]->SetProperties( -GameConfig.WindowWidth / 2 + 20, GameConfig.WindowHeight / 2 - (i + 1) * 28, 0.251, 0.349, 0.596, 20, ANSI_CHARSET, "OCR A Std"); // Loading player information Entity* SelfPlyr = MainMap->EntityList[InputControl.PlayerGuid]; if (!SelfPlyr) throw RuntimeErrorException(); // That should ultimately not happen! for (auto itert : MainMap->PlayerEntityList) { Entity* PlayerEnt = itert.second; PlayerEntity* PlayerExt = NULL; if (!PlayerEnt->DataIntact()) continue; PlayerExt = (PlayerEntity*)PlayerEnt->Physics.ExtendedTags; double PlayerLif = PlayerExt->IsCreative ? 0.0 + my_get_tiny_guid(itert.first) : PlayerExt->Life + my_get_tiny_guid(itert.first); LifeIdx[- PlayerLif] = PlayerEnt; // Notice the minus, it's a trick for replacement of std::greater } // Converting player data into strings for (auto itert : LifeIdx) { Entity* PlayerEnt = itert.second; PlayerEntity* PlayerExt = NULL; if (!PlayerEnt->DataIntact()) continue; PlayerExt = (PlayerEntity*)PlayerEnt->Physics.ExtendedTags; // The default player which never ought to be discovered if (PlayerEnt->Properties.Name == "__ZwDefaultEntity7Player") continue; // The disconnected players which should not by now discovered if (!PlayerEnt->PhysicsEnabled() && !PlayerEnt->RenderEnabled()) continue; std::stringstream SStream, StreamTmp; std::string SName, SOutput; // Define the player's life indicator if (PlayerExt->IsCreative) { SOutput = "[CREATIVE]"; } else { StreamTmp << "[" << (int)PlayerExt->Life << "]"; StreamTmp >> SOutput; } // Define the player's name if (PlayerEnt->Properties.Name.length() <= 15) { SName = PlayerEnt->Properties.Name; } else { SName = ""; for (unsigned int i = 0; i < 12; i++) SName += PlayerEnt->Properties.Name[i]; SName += "..."; } // Send into pipeline to concatenate int defX = SelfPlyr->Physics.PosX, defY = SelfPlyr->Physics.PosY, defZ = SelfPlyr->Properties.Layer; if (PlayerEnt != SelfPlyr) { defX = PlayerEnt->Physics.PosX - defX; defY = PlayerEnt->Physics.PosY - defY; defZ = PlayerEnt->Properties.Layer - defZ; } SStream << std::left << std::setw(16) << SName << std::setw(11) << SOutput << "(" << defX << ", " << defY << ", " << defZ << ")"; SOutput = ""; getline(SStream, SOutput); Vec.push_back(SOutput); } // Projecting all pre-processed strings to display for (int i = 0; i < 9; i++) Vec.push_back(""); gRDM_FVec[0]->SetContent("Player Name Health Relative Position"); gRDM_FVec[1]->SetContent("=================================================="); for (int i = 0; i < 9; i++) gRDM_FVec[i + 2]->SetContent(Vec[i]); // Typesetting all pre-defined fonts for (int i = 0; i < 11; i++) gRDM_FVec[i]->RenderObject(); return true; }
bool graphicsRenderGame( GameMap* MainMap) { if (PhEngine::PhEngineState == PhEngine::Stopped) { GuiCtrl::GuiState = GuiCtrl::MainGui; return false; } GuiDeclareObject(GuiObject, pictBackground, - GameConfig.WindowWidth / 2, GameConfig.WindowWidth / 2, GameConfig.WindowHeight / 2, - GameConfig.WindowHeight / 2, "misc/game_bg.png"); static GuiFont fontPlayerName; pictBackground.RenderObject(); MainMap->LockMemory(); // Find player chunk and locate its number Entity* PlayerEnt = MainMap->EntityList[InputControl.PlayerGuid]; std::set<Chunk*>RendChunks; std::set<int> RendLayers; int MidNum = GetEntityChunkNum(InputControl.CameraX); if (PlayerEnt == NULL) return false; RendChunks.clear(); RendLayers.clear(); // Process required chunks for (int chnk = MidNum - GameConfig.ViewDistance; chnk <= MidNum + GameConfig.ViewDistance; chnk++) if (MainMap->ChunkList[chnk] != NULL) RendChunks.insert(MainMap->ChunkList[chnk]); // Process required layers for (auto itert : RendChunks) for (auto layerItrt : itert->EntityLayerList) if (RendLayers.find(layerItrt.first) == RendLayers.end()) RendLayers.insert(layerItrt.first); // Main render system for (int layer : RendLayers) for (auto chnk : RendChunks) if (chnk->EntityLayerList.find(layer) != chnk->EntityLayerList.end()) { auto& layerList = chnk->EntityLayerList[layer]; for (auto itrt : layerList) { Entity* RenEnt = itrt.second; if (!RenEnt->DataIntact()) continue; EntityType* RenTyp = RenEnt->Properties.Type; EntityType::typeGraphics nGraphics = RenTyp->Graphics[RenEnt->Properties.TypeState]; // If hidden, do not render if (!RenEnt->RenderEnabled()) continue; // If out of render area, do not render. if ((RenEnt->Physics.PosX - nGraphics.LengthX - InputControl.CameraX) * GameConfig.PixelRatio > 0.5 * GameConfig.WindowWidth || (RenEnt->Physics.PosX + nGraphics.LengthX - InputControl.CameraX) * GameConfig.PixelRatio < -0.5 * GameConfig.WindowWidth || (RenEnt->Physics.PosY - nGraphics.LengthY - InputControl.CameraY) * GameConfig.PixelRatio > 0.5 * GameConfig.WindowHeight || (RenEnt->Physics.PosY + nGraphics.LengthY - InputControl.CameraY) * GameConfig.PixelRatio < -0.5 * GameConfig.WindowHeight) continue; graphicsFuncRenderEntity(MainMap, RenTyp, RenEnt, nGraphics, false, RenEnt->Physics.PosX - InputControl.CameraX, RenEnt->Physics.PosY - InputControl.CameraY, nGraphics.LengthX, nGraphics.LengthY, GameConfig.PixelRatio); // Render player entities, this is an exception. if (RenTyp->Properties.Type == "Player") { // Render things on the player's hand PlayerEntity* PlyEnt = (PlayerEntity*)RenEnt->Physics.ExtendedTags; if (PlyEnt->InventoryFocus > 0 && PlyEnt->InventoryFocus <= (int)PlyEnt->Inventory.size() && PlyEnt->InventoryFocus <= 9) { // That means there's something he is holding auto workPair = &PlyEnt->Inventory[PlyEnt->InventoryFocus - 1]; EntityType* HldEnt = workPair->first; EntityType::typeGraphics hnGraphics = HldEnt->Graphics[workPair->second]; // To render its held item or not, this is a question. bool renderHeldItem = true; if (RenEnt->Properties.Name == GameConfig.PlayerName && HldEnt->Properties.Type == "Block") renderHeldItem = false; double scaleFactor = 0.6 / std::min(hnGraphics.LengthX, hnGraphics.LengthY); graphicsFuncRenderEntity(MainMap, HldEnt, NULL, hnGraphics, renderHeldItem, RenEnt->Physics.PosX + nGraphics.LengthX * 0.5 - InputControl.CameraX, RenEnt->Physics.PosY - InputControl.CameraY, hnGraphics.LengthX * scaleFactor, hnGraphics.LengthY * scaleFactor, GameConfig.PixelRatio); } // Render player name double RenderX = (- nGraphics.LengthX * 0.5 + RenEnt->Physics.PosX - InputControl.CameraX) * GameConfig.PixelRatio; double RenderY = (nGraphics.LengthY * 0.5 + RenEnt->Physics.PosY - InputControl.CameraY) * GameConfig.PixelRatio; fontPlayerName.SetProperties( RenderX, RenderY, 0.0, 0.0, 0.0, 20, ANSI_CHARSET, "OCR A Std"); fontPlayerName.SetContent(RenEnt->Properties.Name); fontPlayerName.RenderObject(); } continue; } } // Rendering some overlays graphicsRenderGameOverlay(MainMap); // Finalising render procedure MainMap->UnlockMemory(); return true; }