修改OpenGl渲染底层之前
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
#include "ActiveObject.h"
|
||||
|
||||
void ActiveObject::SetPosition(VecFPos3 pos)
|
||||
void ActiveObject::SetPosition(VecPos3 pos)
|
||||
{
|
||||
BaseObject::SetPosition(pos);
|
||||
BaseObject::SetRenderZOrder(this->Position.y);
|
||||
}
|
||||
|
||||
void ActiveObject::SetYpos(float y)
|
||||
void ActiveObject::SetYpos(int y)
|
||||
{
|
||||
BaseObject::SetYpos(y);
|
||||
BaseObject::SetRenderZOrder(this->Position.y);
|
||||
}
|
||||
|
||||
void ActiveObject::SetSpeed(VecSpeed3 speed)
|
||||
@@ -24,27 +21,49 @@ VecSpeed3 ActiveObject::GetSpeed()
|
||||
|
||||
void ActiveObject::Update(float deltaTime)
|
||||
{
|
||||
// X Y 轴方向的加速度计算
|
||||
if (Speed.x != 0 || Speed.y != 0)
|
||||
int IntegerDelta = static_cast<int>(deltaTime * 1000);
|
||||
const int Gravity = 1020;
|
||||
|
||||
// X轴移动(含余数补偿)
|
||||
if (Speed.x != 0)
|
||||
{
|
||||
MoveBy(Speed.x * deltaTime, Speed.y * deltaTime, 0);
|
||||
int totalX = Speed.x * IntegerDelta + Remainder.x; // 加上上次余数
|
||||
int moveX = totalX / 1000; // 整数部分为实际移动
|
||||
Remainder.x = totalX % 1000; // 保留余数(-999~999)
|
||||
MoveBy(moveX, 0, 0);
|
||||
}
|
||||
// Z轴只在Z轴大于0时 或者 Z轴速度向上时才会有重力
|
||||
|
||||
// Y轴移动(同上)
|
||||
if (Speed.y != 0)
|
||||
{
|
||||
int totalY = Speed.y * IntegerDelta + Remainder.y;
|
||||
int moveY = totalY / 1000;
|
||||
Remainder.y = totalY % 1000;
|
||||
MoveBy(0, moveY, 0);
|
||||
}
|
||||
|
||||
// Z轴重力与移动(含余数补偿)
|
||||
if (Position.z > 0 || Speed.z > 0)
|
||||
{
|
||||
// TODO 还没有写角色属性 要读了角色属性以后才是正确的
|
||||
float Gravity = 68000.0 / 1000.0 * 15.0;
|
||||
Speed.z -= Gravity * deltaTime;
|
||||
MoveBy(0, 0, Speed.z * deltaTime);
|
||||
// 重力对速度的影响(先更新Speed.z,含余数)
|
||||
int speedZTotal = -Gravity * IntegerDelta + Remainder.z; // 注意负号(减速)
|
||||
Speed.z += speedZTotal / 1000; // 速度的整数部分
|
||||
Remainder.z = speedZTotal % 1000; // 速度的余数
|
||||
|
||||
// 基于更新后的Speed.z计算移动量(同样含余数)
|
||||
int moveZTotal = Speed.z * IntegerDelta + _zRemainderMove; // 新增_zRemainderMove记录移动余数
|
||||
int moveZ = moveZTotal / 1000;
|
||||
_zRemainderMove = moveZTotal % 1000;
|
||||
MoveBy(0, 0, moveZ);
|
||||
}
|
||||
// Z轴小于0时要修正
|
||||
else if (Position.z < 0)
|
||||
{
|
||||
Position.z = 0;
|
||||
Speed.z = 0;
|
||||
Remainder.z = 0; // 重置余数
|
||||
_zRemainderMove = 0;
|
||||
SetPosition(Position);
|
||||
SDL_LogError(0, "修正Z轴");
|
||||
}
|
||||
// 执行父类的更新
|
||||
|
||||
BaseObject::Update(deltaTime);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,16 @@ class ActiveObject : public BaseObject
|
||||
{
|
||||
|
||||
public:
|
||||
// 三轴速度
|
||||
VecSpeed3 Speed;
|
||||
// 三轴移动余数
|
||||
VecPos3 Remainder;
|
||||
int _zRemainderMove = 0;
|
||||
|
||||
public:
|
||||
void SetPosition(VecFPos3 pos) override;
|
||||
void SetYpos(float y) override;
|
||||
void
|
||||
SetPosition(VecPos3 pos) override;
|
||||
void SetYpos(int y) override;
|
||||
|
||||
void SetSpeed(VecSpeed3 speed);
|
||||
VecSpeed3 GetSpeed();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "BaseObject.h"
|
||||
#include "Actor/Map/GameMap.h"
|
||||
#include "Actor/Map/GameMapCamera.h"
|
||||
|
||||
BaseObject::BaseObject()
|
||||
{
|
||||
Init(); // 调用了RenderBase的Init函数 对象才会被执行回调
|
||||
@@ -10,41 +12,50 @@ BaseObject::~BaseObject()
|
||||
{
|
||||
}
|
||||
|
||||
void BaseObject::SetPosition(VecFPos3 pos)
|
||||
void BaseObject::Update(float deltaTime)
|
||||
{
|
||||
if (_AffCamera != nullptr)
|
||||
{
|
||||
_AffCamera->SyncPos(deltaTime);
|
||||
}
|
||||
Actor::Update(deltaTime);
|
||||
}
|
||||
|
||||
void BaseObject::SetPosition(VecPos3 pos)
|
||||
{
|
||||
if (pos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder((int)(this->Position.y)); // 设置渲染顺序
|
||||
SetRenderZOrder(pos.y); // 设置渲染顺序
|
||||
}
|
||||
this->Position = pos;
|
||||
Actor::SetPos(VecFPos{this->Position.x, this->Position.y - this->Position.z});
|
||||
SetPos(VecFPos{this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
|
||||
VecFPos3 BaseObject::GetPosition()
|
||||
VecPos3 BaseObject::GetPosition()
|
||||
{
|
||||
return this->Position;
|
||||
}
|
||||
|
||||
void BaseObject::SetXpos(float x)
|
||||
void BaseObject::SetXpos(int x)
|
||||
{
|
||||
this->Position.x = x;
|
||||
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
|
||||
void BaseObject::SetYpos(float y)
|
||||
void BaseObject::SetYpos(int y)
|
||||
{
|
||||
if (y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder((int)(this->Position.y)); // 设置渲染顺序
|
||||
SetRenderZOrder(y); // 设置渲染顺序
|
||||
}
|
||||
this->Position.y = y;
|
||||
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
|
||||
void BaseObject::SetZpos(float z)
|
||||
void BaseObject::SetZpos(int z)
|
||||
{
|
||||
this->Position.z = z;
|
||||
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
|
||||
int BaseObject::GetXpos()
|
||||
@@ -62,28 +73,33 @@ int BaseObject::GetZpos()
|
||||
return this->Position.z;
|
||||
}
|
||||
|
||||
void BaseObject::MoveBy(VecFPos3 pos)
|
||||
void BaseObject::MoveBy(VecPos3 pos)
|
||||
{
|
||||
// 只有moveby移动时判断所在地图中是否能够这样移动
|
||||
VecFPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), pos);
|
||||
if (pos.y != 0)
|
||||
VecPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), pos);
|
||||
if (RealPos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder((int)(this->Position.y)); // 设置渲染顺序
|
||||
SetRenderZOrder(RealPos.y); // 设置渲染顺序
|
||||
}
|
||||
if (RealPos != this->Position){
|
||||
this->Position = RealPos;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
this->Position = RealPos;
|
||||
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
|
||||
void BaseObject::MoveBy(float x, float y, float z)
|
||||
void BaseObject::MoveBy(int x, int y, int z)
|
||||
{
|
||||
// 只有moveby移动时判断所在地图中是否能够这样移动
|
||||
VecFPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), VecFPos3({x, y, z}));
|
||||
if (y != 0)
|
||||
VecPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), VecPos3({x, y, z}));
|
||||
if (RealPos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder((int)(this->Position.y)); // 设置渲染顺序
|
||||
SetRenderZOrder(RealPos.y); // 设置渲染顺序
|
||||
}
|
||||
if (RealPos != this->Position)
|
||||
{
|
||||
this->Position = RealPos;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
this->Position = RealPos;
|
||||
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
|
||||
void BaseObject::SetDirection(int dir)
|
||||
|
||||
@@ -1,38 +1,43 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Actor/Actor.h"
|
||||
#include "Asset/Common/ObjectVars.h"
|
||||
#include "Global/Global_Enum.h"
|
||||
class GameMap;
|
||||
class GameMapCamera;
|
||||
class BaseObject : public Actor
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
VecFPos3 Position; // 位置
|
||||
public:
|
||||
ObjectType m_objecttype; // 对象类型
|
||||
VecPos3 Position; // 位置
|
||||
int Direction = 0; // 方向
|
||||
GameMap *_AffMap = nullptr; // 所在地图
|
||||
GameMapCamera *_AffCamera = nullptr; // 跟随相机
|
||||
|
||||
public:
|
||||
BaseObject(/* args */);
|
||||
~BaseObject();
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
// 数据储存器
|
||||
ObjectVars _ObjectVars;
|
||||
|
||||
public:
|
||||
virtual void SetPosition(VecFPos3 pos);
|
||||
virtual void SetXpos(float x);
|
||||
virtual void SetYpos(float y);
|
||||
virtual void SetZpos(float z);
|
||||
virtual void SetPosition(VecPos3 pos);
|
||||
virtual void SetXpos(int x);
|
||||
virtual void SetYpos(int y);
|
||||
virtual void SetZpos(int z);
|
||||
|
||||
VecFPos3 GetPosition();
|
||||
VecPos3 GetPosition();
|
||||
int GetXpos();
|
||||
int GetYpos();
|
||||
int GetZpos();
|
||||
|
||||
void MoveBy(VecFPos3 pos);
|
||||
void MoveBy(float x, float y, float z);
|
||||
|
||||
void SetDirection(int dir);
|
||||
virtual void MoveBy(VecPos3 pos);
|
||||
virtual void MoveBy(int x, int y, int z);
|
||||
|
||||
virtual void SetDirection(int dir);
|
||||
int GetDirection();
|
||||
|
||||
ObjectVars &GetObjectVars();
|
||||
|
||||
@@ -5,21 +5,16 @@ CharacterObject::~CharacterObject()
|
||||
{
|
||||
}
|
||||
|
||||
void CharacterObject::Update(float deltaTime)
|
||||
{
|
||||
ActiveObject::Update(deltaTime);
|
||||
}
|
||||
|
||||
void CharacterObject::Render()
|
||||
{
|
||||
ActiveObject::Render();
|
||||
}
|
||||
|
||||
void CharacterObject::Construction(int job)
|
||||
{
|
||||
m_objecttype = ObjectType::CHARACTER;
|
||||
this->Job = job;
|
||||
// 创建装备管理器
|
||||
_EquipmentManager = new Chr_Equipment();
|
||||
_EquipmentManager->Init(this);
|
||||
// 创建阴影对象
|
||||
_Shadow = new Chr_Shadow();
|
||||
_Shadow->Init(this);
|
||||
// 创建动画管理器(一定要先创建装备管理器再创建动画管理器 因为需要读取身上的装备)
|
||||
_AnimationManager = new Chr_Animation();
|
||||
_AnimationManager->Init(this);
|
||||
@@ -55,3 +50,20 @@ void CharacterObject::ControllerMsg(CONTROLLER_MSG_TYPE msgType, void *msgData)
|
||||
this->_StateMachine->ChangeState(BASE_STATE::MOVE);
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterObject::Update(float deltaTime)
|
||||
{
|
||||
ActiveObject::Update(deltaTime);
|
||||
}
|
||||
|
||||
void CharacterObject::SetPos(VecFPos pos)
|
||||
{
|
||||
BaseObject::SetPos(pos);
|
||||
if(_Shadow)_Shadow->SetPos(this->GetPos());
|
||||
}
|
||||
|
||||
void CharacterObject::SetDirection(int dir)
|
||||
{
|
||||
BaseObject::SetDirection(dir);
|
||||
if(_Shadow)_Shadow->SetDirection(this->GetDirection());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Asset/Character/Chr_Equipment.h"
|
||||
#include "Asset/Character/Chr_Controller.h"
|
||||
#include "Asset/Character/Chr_StateMachine.h"
|
||||
#include "Asset/Character/Chr_Shadow.h"
|
||||
#include "Global/Global_Enum.h"
|
||||
class CharacterObject : public ActiveObject
|
||||
{
|
||||
@@ -16,6 +17,9 @@ public:
|
||||
RefPtr<Chr_Controller> _Controller = nullptr;
|
||||
// 角色状态机
|
||||
RefPtr<Chr_StateMachine> _StateMachine = nullptr;
|
||||
|
||||
// 角色阴影对象
|
||||
RefPtr<Chr_Shadow> _Shadow = nullptr;
|
||||
// 职业
|
||||
int Job = 0;
|
||||
// 转职职业 如果是-1则没有转职
|
||||
@@ -25,8 +29,6 @@ public:
|
||||
~CharacterObject();
|
||||
|
||||
public:
|
||||
void Update(float deltaTime) override;
|
||||
void Render() override;
|
||||
|
||||
// 通过职业创建角色
|
||||
void Construction(int job);
|
||||
@@ -36,4 +38,8 @@ public:
|
||||
void DisableController();
|
||||
// 控制器信息
|
||||
void ControllerMsg(CONTROLLER_MSG_TYPE msgType, void* msgData);
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void SetPos(VecFPos pos) override;
|
||||
void SetDirection(int dir) override;
|
||||
};
|
||||
|
||||
10
source_game/Actor/Object/MonsterObject.cpp
Normal file
10
source_game/Actor/Object/MonsterObject.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "MonsterObject.h"
|
||||
#include "Global/Global_Game.h"
|
||||
void MonsterObject::Construction(int MonsterID)
|
||||
{
|
||||
this->Id = MonsterID;
|
||||
|
||||
// 创建动画管理器(一定要先创建装备管理器再创建动画管理器 因为需要读取身上的装备)
|
||||
_AnimationManager = new Mon_Animation();
|
||||
_AnimationManager->Init(this);
|
||||
}
|
||||
18
source_game/Actor/Object/MonsterObject.h
Normal file
18
source_game/Actor/Object/MonsterObject.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Actor/Object/ActiveObject.h"
|
||||
#include "Global/Global_Enum.h"
|
||||
#include "Asset/Monster/Mon_Animation.h"
|
||||
class MonsterObject : public ActiveObject
|
||||
{
|
||||
public:
|
||||
// 怪物动画管理器
|
||||
RefPtr<Mon_Animation> _AnimationManager = nullptr;
|
||||
|
||||
// 怪物ID
|
||||
int Id = 0;
|
||||
|
||||
public:
|
||||
// 通过ID创建怪物
|
||||
void Construction(int MonsterID);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user