修改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

@@ -29,8 +29,11 @@ enum BASE_STATE
JUMP, // 跳跃
};
// 对象类型
enum ObjectType
{
BASE = 0, // 基础对象
ACTIVE = 1 << 0, // 动态对象
CHARACTER = 1 << 1, // 角色对象
MONSTER = 1 << 2 // 怪物对象
};

View File

@@ -27,6 +27,8 @@ void Global_Game::InitGame()
CharacterConfigs = GlobalCharacterScript::InitCharacterLst();
// 读取装备配置文件
EquipmentPathMap = GlobalEquipmentScript::InitEquipmentLst();
// 读取怪物配置文件
MonsterPathMap = GlobalMonsterScript::InitMonsterLst();
// 初始化松鼠脚本管理器
SquirrelManager::GetInstance().Init();
@@ -36,3 +38,24 @@ void Global_Game::InitGame()
// 游戏初始化完成标志
InitFlag = true;
}
GlobalMonsterScript::MonsterConfig Global_Game::GetMonsterInfo(int id)
{
if (!InitFlag)
{
SDL_LogError(0, "游戏未初始化");
return GlobalMonsterScript::MonsterConfig();
}
if (MonsterInfoMap.count(id))
return MonsterInfoMap[id];
if (!MonsterPathMap.count(id))
{
SDL_LogError(0, "怪物ID不存在");
return GlobalMonsterScript::MonsterConfig();
}
std::string path = MonsterPathMap[id];
GlobalMonsterScript::MonsterConfig MonsterConfig = GlobalMonsterScript::ReadMonsterConfig(path);
MonsterConfig.id = id;
MonsterInfoMap[id] = MonsterConfig;
return MonsterConfig;
}

View File

@@ -2,6 +2,7 @@
#include "EngineCore/Game.h"
#include "Global/Script/CharacterConfig.h"
#include "Global/Script/EquipmentConfig.h"
#include "Global/Script/MonsterConfig.h"
#include "Global/Save/SavaManager.h"
#include "Asset/Squirrel/SquirrelManager.h"
class Global_Game
@@ -36,6 +37,11 @@ public:
// 装备路径Map
std::map<int, std::string> EquipmentPathMap;
// 怪物相关
std::map<int, std::string> MonsterPathMap; // 路径
std::map<int, GlobalMonsterScript::MonsterConfig> MonsterInfoMap; // 信息
GlobalMonsterScript::MonsterConfig GetMonsterInfo(int id); // 获取怪物信息
// 游戏资源初始化标志
bool InitFlag = false;

View File

@@ -0,0 +1,46 @@
#include "MonsterConfig.h"
#include "Asset/AssetManager.h"
#include "Tool/Tool_String.h"
namespace GlobalMonsterScript
{
std::map<int, std::string> InitMonsterLst()
{
std::map<int, std::string> EquipList;
ScriptData Data = AssetManager::GetInstance().GetScriptInfo("monster/monster.lst");
while (!Data.IsEnd())
{
std::string Index = Data.Get();
std::string MonsterPath = std::string("monster/") + Data.Get();
EquipList[std::stoi(Index)] = MonsterPath;
}
return EquipList;
}
MonsterConfig ReadMonsterConfig(std::string path)
{
MonsterConfig Config;
Config.folder = path.substr(0, path.find_last_of('/') + 1);
ScriptData Data = AssetManager::GetInstance().GetScriptInfo(path);
while (!Data.IsEnd())
{
std::string Segment = Data.Get();
if (Segment == "name")
{
Config.name = Data.Get();
}
else if (Segment == "[动作动画]")
{
while (true)
{
std::string Ret = Data.Get();
if (Ret == "[/动作动画]")
break;
std::string path = Data.Get();
Config.animationPath[Ret] = path;
}
}
}
return Config;
}
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include <string>
#include <vector>
#include <map>
namespace GlobalMonsterScript
{
// 怪物配置
struct MonsterConfig
{
//编号
int id = -1;
//名称
std::string name = "none";
//动作动画
std::map<std::string, std::string> animationPath;
//所在文件夹
std::string folder = "none";
};
// 读取怪物列表
std::map<int, std::string> InitMonsterLst();
// 读取怪物数据
MonsterConfig ReadMonsterConfig(std::string path);
}