修改OpenGl渲染底层之前

This commit is contained in:
2025-10-20 20:50:12 +08:00
parent 1b011b9b68
commit 2b888aae5b
61 changed files with 1609 additions and 680 deletions

View File

@@ -4,6 +4,7 @@
#include "EngineFrame/Component/Animation.h"
#include "Actor/Map/GameMapCamera.h"
#include "Actor/Object/CharacterObject.h"
#include "EngineCore/Game.h"
GameMap::GameMap()
{
@@ -45,12 +46,23 @@ void GameMap::InitConfiguration(std::string mapName)
std::string Segment = Data.Get();
if (Segment == "[background pos]")
{
_MapInfo["background_pos"] = std::stoi(Data.Get());
int Offset = std::stoi(Data.Get());
MapOffsetY = Offset;
_MapInfo["background_pos"] = Offset;
}
else if (Segment == "[map name]")
{
_MapInfo["name"] = Data.Get();
}
else if (Segment == "[limit map camera move]")
{
std::vector<int> limit;
limit.push_back(std::stoi(Data.Get()));
limit.push_back(std::stoi(Data.Get()));
limit.push_back(std::stoi(Data.Get()));
limit.push_back(std::stoi(Data.Get()));
_MapInfo["limit_map_camera_move"] = limit;
}
else if (Segment == "[wide mode camera vertical correction]")
{
_MapInfo["wide_mode_camer_vertical_correction"] = std::stoi(Data.Get());
@@ -196,7 +208,10 @@ void GameMap::InitTile()
{
if (!_MapInfo.count("tile"))
return;
// 普通地板数量
int NormalTileCount = 0;
// 普通地板高度
int NormalTileHeight = 560;
std::vector<std::string> tileArr = std::get<std::vector<std::string>>(_MapInfo["tile"]);
if (tileArr.size() > 0)
{
@@ -224,7 +239,7 @@ void GameMap::InitTile()
std::string path = extileArr[i];
RefPtr<Tile> tile = new Tile(path);
int xbuf = i % NormalTileCount * 224;
int ybuf = 560 - 200 - std::get<int>(_MapInfo["background_pos"]) + 40 * (i / NormalTileCount);
int ybuf = -200 - std::get<int>(_MapInfo["background_pos"]) + NormalTileHeight + 120 * (i / NormalTileCount);
tile->SetPos(VecFPos{xbuf, ybuf});
_LayerMap["bottom"]->AddComponent(tile);
}
@@ -325,6 +340,7 @@ void GameMap::LoadMap(std::string mapName)
void GameMap::Enter(Scene *scene)
{
_Scene = scene;
scene->AddChild(_LayerMap["contact"]);
scene->AddChild(_LayerMap["distantback"]);
scene->AddChild(_LayerMap["middleback"]);
@@ -334,18 +350,6 @@ void GameMap::Enter(Scene *scene)
scene->AddChild(_LayerMap["close"]);
scene->AddChild(_LayerMap["cover"]);
scene->AddChild(_LayerMap["max"]);
// TODO
int HSU = 0;
_LayerMap["contact"]->SetPos(VecFPos{0, HSU});
_LayerMap["distantback"]->SetPos(VecFPos{0, HSU});
_LayerMap["middleback"]->SetPos(VecFPos{0, HSU});
_LayerMap["bottom"]->SetPos(VecFPos{0, HSU});
_LayerMap["closeback"]->SetPos(VecFPos{0, HSU});
_LayerMap["normal"]->SetPos(VecFPos{0, HSU});
_LayerMap["close"]->SetPos(VecFPos{0, HSU});
_LayerMap["cover"]->SetPos(VecFPos{0, HSU});
_LayerMap["max"]->SetPos(VecFPos{0, HSU});
}
void GameMap::HandleEvents(SDL_Event *e)
@@ -354,45 +358,68 @@ void GameMap::HandleEvents(SDL_Event *e)
void GameMap::Update(float deltaTime)
{
// this->_Camera->Update(deltaTime);
if (_Scene->GetCamera() == nullptr)
return;
GameMapCamera *Cam = (GameMapCamera *)(_Scene->GetCamera().Get());
int targetX = Cam->_currentPosition.x;
int targetY = Cam->_currentPosition.y;
// 屏幕中心
int width_Separate = Game::GetInstance().Screen_W / 2;
int height_Separate = Game::GetInstance().Screen_H / 2;
// if (this->_Camera)
// {
// int CamearXpos = this->_Camera->X;
// int CamearYpos = this->_Camera->Y;
// int CamearZpos = this->_Camera->Z;
// 获取摄像机可行区域限制
auto limitIt = _MapInfo.find("limit_map_camera_move");
if (limitIt != _MapInfo.end())
{
std::vector<int> limit = std::get<std::vector<int>>(_MapInfo["limit_map_camera_move"]);
int X_Limit_Min = limit[0];
int X_Limit_Max = limit[1];
int Y_Limit_Min = limit[2];
int Y_Limit_Max = limit[3];
// 应用地图边界限制
targetX = std::clamp(targetX, width_Separate, _MapLength - width_Separate);
targetY = std::clamp(targetY, height_Separate, _MapHeight - height_Separate);
// 应用自定义摄像机移动限制
if (X_Limit_Min != -1)
targetX = std::max(targetX, X_Limit_Min);
if (X_Limit_Max != -1)
targetX = std::min(targetX, X_Limit_Max);
if (Y_Limit_Min != -1)
targetY = std::max(targetY, Y_Limit_Min);
if (Y_Limit_Max != -1)
targetY = std::min(targetY, Y_Limit_Max);
}
// SDL_Log("Camera Pos: %d, %d", CamearXpos, CamearYpos);
// // 遍历
// for (auto &pair : _LayerMap)
// {
// // pair.first 是 keystd::string
// std::string key = pair.first;
// // pair.second 是 valueRefPtr<GameMapLayer>
// RefPtr<GameMapLayer> &value = pair.second;
// if (key == "distantback")
// {
// value->SetPos(VecPos{(-CamearXpos + 553), (-CamearYpos + CamearZpos + 300 + 120 + 80)});
// }
// else
// {
// value->SetPos(VecPos{(-CamearXpos + 553), (-CamearYpos + CamearZpos + 300 + 120 + 80)});
// }
// }
// }
// 更新图层位置
for (auto &Layer : _LayerMap)
{
int posX = -targetX + width_Separate;
int posY = -targetY + height_Separate + MapOffsetY;
if (Layer.first == "distantback")
{
posX *= BackgroundMoveSpeed;
posX /= 100;
}
Layer.second->SetPos(VecFPos(posX, posY));
}
}
void GameMap::AddObject(RefPtr<BaseObject> object)
{
object->_AffMap = this;
_LayerMap["normal"]->AddObject(object);
// 如果是角色对象
if (object->m_objecttype == ObjectType::CHARACTER)
{
CharacterObject *chr = (CharacterObject *)(object.Get());
_LayerMap["bottom"]->AddComponent(chr->_Shadow);
}
}
VecFPos3 GameMap::CheckIsItMovable(VecFPos3 CurPos, VecFPos3 PosOffset)
VecPos3 GameMap::CheckIsItMovable(VecPos3 CurPos, VecPos3 PosOffset)
{
// 初始化结果为原坐标(默认不移动)
VecFPos3 result = CurPos;
VecPos3 result = CurPos;
// 如果没有可移动区域限制,直接全量位移
if (_MovableArea.empty())