修改底层渲染为OpenGL

This commit is contained in:
2025-10-23 15:21:12 +08:00
parent 1fe898e09c
commit f9a2300b5a
37 changed files with 2782 additions and 3761 deletions

View File

@@ -412,7 +412,7 @@ void GameMap::AddObject(RefPtr<BaseObject> object)
if (object->m_objecttype == ObjectType::CHARACTER)
{
CharacterObject *chr = (CharacterObject *)(object.Get());
_LayerMap["bottom"]->AddComponent(chr->_Shadow);
if( chr->_Shadow != nullptr)_LayerMap["bottom"]->AddComponent(chr->_Shadow);
}
}

View File

@@ -12,9 +12,8 @@ GameMapLayer::~GameMapLayer()
void GameMapLayer::Render()
{
Actor::Render();
SDL_Renderer *renderer = Game::GetInstance().GetRenderer();
// 设置绘制颜色
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 128);
RenderManager *renderer = Game::GetInstance().GetRenderer();
// 自身坐标
float Xpos = GetIterationPos().x + GetPos().x;
float Ypos = GetIterationPos().y + GetPos().y;
@@ -25,10 +24,8 @@ void GameMapLayer::Render()
buf.y = info.y + Ypos;
buf.w = info.w;
buf.h = info.h;
// 绘制填充矩形
SDL_RenderFillRect(renderer, &buf);
//TODO: 渲染可行区域
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 250);
}
void GameMapLayer::AddDebugFeasibleAreaInfo(VecFPos pos, VecSize size)

View File

@@ -11,7 +11,8 @@ Tile::Tile(std::string Path) : Sprite()
if (std::get<std::string>(m_data["path"]) == "")
m_data["path"] = "sprite/character/common/circlecooltime.img";
m_texture = new Texture(std::get<std::string>(m_data["path"]), std::get<int>(m_data["idx"]));
m_texture = new Texture();
m_texture->Init(std::get<std::string>(m_data["path"]), std::get<int>(m_data["idx"]));
Sprite::Init();
this->imgPath = Path;
}

View File

@@ -12,9 +12,9 @@ void CharacterObject::Construction(int job)
// 创建装备管理器
_EquipmentManager = new Chr_Equipment();
_EquipmentManager->Init(this);
// 创建阴影对象
_Shadow = new Chr_Shadow();
_Shadow->Init(this);
// // 创建阴影对象
// _Shadow = new Chr_Shadow();
// _Shadow->Init(this);
// 创建动画管理器(一定要先创建装备管理器再创建动画管理器 因为需要读取身上的装备)
_AnimationManager = new Chr_Animation();
_AnimationManager->Init(this);

View File

@@ -33,17 +33,17 @@ void Chr_Animation::CreateSkinmationBySlot(std::string actionName, std::string s
// 构造好Ani以后 统一设置为不可见 然后放入ActionAnis表
RefPtr<Animation> Ani = new Animation(path, FormatImgPath, Data);
Ani->SetVisible(false);
Ani->SetRenderZOrder(Variation.Layer);
this->AddChild(Ani);
ActionAnis[actionName].push_back(Ani);
// 构造一下阴影对象
RefPtr<Animation> ShadowAni = new Animation(path, FormatImgPath, Data);
ShadowAni->SetVisible(false);
// 皮肤统一设置阴影
ShadowAni->SetShadow();
chr_parent->_Shadow->AddChild(ShadowAni);
chr_parent->_Shadow->ActionAnis[actionName].push_back(ShadowAni);
// 构造一下阴影对象 //TODO
// RefPtr<Animation> ShadowAni = new Animation(path, FormatImgPath, Data);
// ShadowAni->SetVisible(false);
// chr_parent->_Shadow->AddChild(ShadowAni);
// chr_parent->_Shadow->ActionAnis[actionName].push_back(ShadowAni);
}
}
}
@@ -82,7 +82,7 @@ void Chr_Animation::Init(CharacterObject *parent)
parent->AddChild(this);
chr_parent = parent;
GlobalCharacterScript::CharacterConfig Config = Global_Game::GetInstance().CharacterConfigs[parent->Job];
// 遍历所有动作Ani路径
for (const auto &pair : Config.animationPath)
{
@@ -116,5 +116,5 @@ void Chr_Animation::SetAction(std::string actionName)
CurrentActionTag = actionName;
// 设置阴影的动作
chr_parent->_Shadow->SetAction(actionName);
if(chr_parent->_Shadow)chr_parent->_Shadow->SetAction(actionName);
}

View File

@@ -130,6 +130,23 @@ static SQInteger SQR_SetPos(HSQUIRRELVM v)
return 0;
}
static SQInteger SQR_GetWorldPos(HSQUIRRELVM v)
{
SQUserPointer A_obj;
sq_getuserpointer(v, 2, &A_obj);
Actor *Aobj = (Actor *)A_obj;
VecFPos Pos = Aobj->GetWorldPos();
sq_newtable(v);
sq_pushstring(v, _SC("x"), -1);
sq_pushfloat(v, Pos.x);
sq_newslot(v, 3, SQFalse);
sq_pushstring(v, _SC("y"), -1);
sq_pushfloat(v, Pos.y);
sq_newslot(v, 3, SQFalse);
return 1;
}
static SQInteger SQR_GetAlpha(HSQUIRRELVM v)
{
SQUserPointer A_obj;
@@ -287,6 +304,16 @@ static SQInteger SQR_SetSize(HSQUIRRELVM v)
return 0;
}
static SQInteger SQR_SetVisible(HSQUIRRELVM v){
SQUserPointer A_obj;
sq_getuserpointer(v, 2, &A_obj);
SQBool Value;
sq_getbool(v, 3, &Value);
Actor *Aobj = (Actor *)A_obj;
Aobj->SetVisible(Value);
return 0;
}
static SQInteger SQR_CreateSprite(HSQUIRRELVM v)
{
const SQChar *ImgPath;
@@ -323,6 +350,7 @@ static void RegisterUI()
RegisterUINutApi(_SC("sq_SetZOrder"), SQR_SetZOrder, v);
RegisterUINutApi(_SC("sq_GetPos"), SQR_GetPos, v);
RegisterUINutApi(_SC("sq_SetPos"), SQR_SetPos, v);
RegisterUINutApi(_SC("sq_GetWorldPos"), SQR_GetWorldPos, v);
RegisterUINutApi(_SC("sq_GetAlpha"), SQR_GetAlpha, v);
RegisterUINutApi(_SC("sq_SetAlpha"), SQR_SetAlpha, v);
RegisterUINutApi(_SC("sq_GetScale"), SQR_GetScale, v);
@@ -331,6 +359,7 @@ static void RegisterUI()
RegisterUINutApi(_SC("sq_SetRotation"), SQR_SetRotation, v);
RegisterUINutApi(_SC("sq_GetSize"), SQR_GetSize, v);
RegisterUINutApi(_SC("sq_SetSize"), SQR_SetSize, v);
RegisterUINutApi(_SC("sq_SetVisible"), SQR_SetVisible, v);
RegisterUINutApi(_SC("sq_CreateSprite"), SQR_CreateSprite, v);
}

View File

@@ -10,10 +10,10 @@ Global_Game::~Global_Game()
void Global_Game::Init()
{
// 初始化ttf字体资源
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/LXGWWenKai-Regular.ttf", 24);
TTF_Font *FontBuf = TTF_OpenFont("Fonts/VonwaonBitmap-12px.ttf", 24);
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/Gothica-Book.ttf", 24);
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/Gasinamu.ttf", 24);
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/NotoSansSC-Regular.otf", 24);
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/calibri.ttf", 24);
if (!FontBuf)
{
SDL_LogError(0, "字体加载失败: %s", TTF_GetError());

View File

@@ -27,7 +27,7 @@ void Scene_Loading_UI::Enter()
RefPtr<Sprite> LoadCircleSp = new Sprite("ImagePacks2/Loading2.png");
LoadCircleSp->SetName("LoadCircle");
LoadCircleSp->SetPos(VecFPos{1280 - 60, 686 - 60});
LoadCircleSp->SetBlendMode(SDL_BLENDMODE_ADD);
LoadCircleSp->SetBlendMode(LINEARDODGE);
LoadCircleSp->SetAnchor(VecFPos{0.5f, 0.5f});
actor->AddComponent(LoadCircleSp);

View File

@@ -16,12 +16,59 @@ void Scene_MainUi::Enter()
sq_call(v, 2, SQFalse, SQTrue);
}
sq_settop(v, top);
}
void Scene_MainUi::HandleEvents(SDL_Event *e)
void Scene_MainUi::HandleEvents(SDL_Event *event)
{
Scene::HandleEvents(e);
SQInteger EventType = -1;
std::vector<SQInteger> EventData;
switch (event->type)
{
// 鼠标移动
case SDL_MOUSEMOTION:
{
EventType = 0;
EventData.push_back(event->motion.x);
EventData.push_back(event->motion.y);
break;
}
// 鼠标按键按下
case SDL_MOUSEBUTTONDOWN:
{
EventType = 1;
EventData.push_back(event->button.button);
break;
}
// 鼠标按键释放
case SDL_MOUSEBUTTONUP:
{
EventType = 2;
EventData.push_back(event->button.button);
break;
}
// 鼠标滚轮
case SDL_MOUSEWHEEL:
{
EventType = 3;
EventData.push_back(event->wheel.y);
break;
}
// 键盘按键按下
case SDL_KEYDOWN:
{
EventType = 4;
EventData.push_back(event->key.keysym.sym);
break;
}
// 键盘按键释放
case SDL_KEYUP:
{
EventType = 5;
EventData.push_back(event->key.keysym.sym);
break;
}
}
HSQUIRRELVM v = SquirrelEx::GetInstance().GetSquirrelVM();
SQInteger top = sq_gettop(v);
sq_pushroottable(v);
@@ -29,8 +76,14 @@ void Scene_MainUi::HandleEvents(SDL_Event *e)
if (SQ_SUCCEEDED(sq_get(v, -2)))
{
sq_pushroottable(v);
sq_pushinteger(v, 1);
sq_call(v, 2, SQFalse, SQTrue);
sq_pushinteger(v, EventType);
sq_newarray(v, 0);
for (SQInteger i = 0; i < EventData.size(); i++)
{
sq_pushinteger(v, EventData[i]);
sq_arrayappend(v, -2);
}
sq_call(v, 3, SQFalse, SQTrue);
}
sq_settop(v, top);
}

View File

@@ -1,7 +1,10 @@
#include "Scene_Test.h"
#include <memory>
#include <EngineCore/Game.h>
#include <EngineFrame/Component/AnimationManager.h>
#include "EngineCore/Game.h"
#include "EngineFrame/Component/AnimationManager.h"
#include "EngineFrame/Component/Text.h"
#include "EngineFrame/Component/Canvas.h"
#include "Global/Global_Game.h"
Scene_Test::Scene_Test()
{
}
@@ -13,44 +16,55 @@ Scene_Test::~Scene_Test()
void Scene_Test::Enter()
{
map = new GameMap;
map->LoadMap("map/cataclysm/town/elvengard/new_elvengard.map");
map->Enter(this);
// SetScale(VecFPos(1.2f, 1.2f));
// map = new GameMap;
// map->LoadMap("map/cataclysm/town/elvengard/new_elvengard.map");
// map->Enter(this);
RefPtr<CharacterObject> obj = new CharacterObject();
obj->SetPosition({1000, 300, 0});
obj->Construction(0);
// RefPtr<CharacterObject> obj = new CharacterObject();
// obj->SetPosition({1000, 300, 0});
// obj->Construction(0);
RefPtr<MonsterObject> monster = new MonsterObject();
monster->SetPosition({1200, 301, 0});
monster->Construction(1);
monster->SetDirection(1);
// RefPtr<MonsterObject> monster = new MonsterObject();
// monster->SetPosition({1200, 301, 0});
// monster->Construction(1);
// monster->SetDirection(1);
map->AddObject(obj);
map->AddObject(monster);
// map->AddObject(obj);
// map->AddObject(monster);
_camera = new GameMapCamera;
_camera->SetFromActor(obj.Get());
return;
// _camera = new GameMapCamera;
// _camera->SetFromActor(obj.Get());
// return;
// SDL_Log("Scene_Test::进入测试场景!");
// // SDL_Log("Scene_Test::进入测试场景!");
RefPtr<Actor> actor = new Actor;
AddChild(actor);
// RefPtr<Sprite> sprite = new Sprite("ImagePacks2/test_white_background.png");
// actor->AddComponent(sprite);
// RefPtr<Sprite> chr = new Sprite("sprite/character/swordman/equipment/avatar/skin/sm_body0000.img", 90);
RefPtr<Sprite> sprite = new Sprite("ImagePacks2/test_white_background.png");
RefPtr<Sprite> chr = new Sprite("sprite/interface2/hud/hud.img", 0);
// chr->SetPos(VecFPos{200, 100});
// chr->SetAlpha(0.5);
// chr->SetShadow();
// actor->AddComponent(chr);
actor->AddComponent(chr);
RefPtr<AnimationManager> Am = new AnimationManager;
RefPtr<Animation> ani4 = new Animation("map/cataclysm/town/hendonmyre/animation/object/gateall_02.ani");
Am->AddAnimation(ani4);
// RefPtr<Canvas> canvas = new Canvas(VecSize{1280, 720});
// actor->AddChild(canvas);
// Am->SetPos(VecFPos{200, 100});
actor->AddChild(Am);
// canvas->AddChild(chr);
// RefPtr<AnimationManager> Am = new AnimationManager;
// RefPtr<Animation> ani4 = new Animation("map/cataclysm/town/hendonmyre/animation/object/gateall_02.ani");
// Am->AddAnimation(ani4);
// // Am->SetPos(VecFPos{200, 100});
// actor->AddChild(Am);
// RefPtr<Text> text = new Text();
// text->Init("测试文本", Global_Game::GetInstance().Fonts[0], SDL_Color{255, 255, 255, 255});
// text->SetPos(VecFPos{200, 100});
// actor->AddChild(text);
// // sprite2->UnsetClipRect();

View File

@@ -69,7 +69,6 @@ int main(int argc, char *argv[])
Asset_Script::GetInstance();
// 初始化线程池
ThreadPool::GetInstance();
// 初始化日志系统
// Logger::GetInstance().Init();
// 初始化Squirrel脚本系统