remove movement

This commit is contained in:
aozhiwei 2019-04-13 10:46:25 +08:00
parent b3da54c99c
commit 0e44bf23f8
13 changed files with 0 additions and 105 deletions

View File

@ -2,7 +2,6 @@
#include "android.ai.h" #include "android.ai.h"
#include "android.h" #include "android.h"
#include "movement.h"
#include "room.h" #include "room.h"
#include "metamgr.h" #include "metamgr.h"

View File

@ -2,7 +2,6 @@
#include "android.h" #include "android.h"
#include "metamgr.h" #include "metamgr.h"
#include "movement.h"
#include "android.ai.h" #include "android.ai.h"
Android::Android():Human() Android::Android():Human()
@ -27,6 +26,5 @@ void Android::Initialize()
void Android::Update(int delta_time) void Android::Update(int delta_time)
{ {
movement->Update(delta_time);
ai->Update(delta_time); ai->Update(delta_time);
} }

View File

@ -2,7 +2,6 @@
#include "bullet.h" #include "bullet.h"
#include "metamgr.h" #include "metamgr.h"
#include "movement.h"
#include "room.h" #include "room.h"
#include "collider.h" #include "collider.h"
#include "obstacle.h" #include "obstacle.h"
@ -11,14 +10,10 @@
Bullet::Bullet():Entity() Bullet::Bullet():Entity()
{ {
entity_type = ET_Bullet; entity_type = ET_Bullet;
movement = new MovementComponent();
movement->owner = this;
} }
Bullet::~Bullet() Bullet::~Bullet()
{ {
delete movement;
movement = nullptr;
} }
void Bullet::Initialize() void Bullet::Initialize()
@ -28,7 +23,6 @@ void Bullet::Initialize()
void Bullet::Update(int delta_time) void Bullet::Update(int delta_time)
{ {
movement->Update(delta_time);
pos = pos + dir * gun_meta->i->bullet_speed() / 20.0f; pos = pos + dir * gun_meta->i->bullet_speed() / 20.0f;
float distance = (pos - born_pos).Norm(); float distance = (pos - born_pos).Norm();
if (meta->i->_inventory_slot() == 5 || if (meta->i->_inventory_slot() == 5 ||

View File

@ -34,7 +34,6 @@ enum EntitySubType_e
class Room; class Room;
class Obstacle; class Obstacle;
class ColliderComponent; class ColliderComponent;
class MovementComponent;
class Entity class Entity
{ {
public: public:
@ -44,7 +43,6 @@ class Entity
Room* room = nullptr; Room* room = nullptr;
Vector2D pos; Vector2D pos;
int updated_times = 0; int updated_times = 0;
MovementComponent* movement = nullptr;
std::list<ColliderComponent*> colliders; std::list<ColliderComponent*> colliders;
bool deleted = false; bool deleted = false;

View File

@ -2,7 +2,6 @@
#include "human.h" #include "human.h"
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
#include "movement.h"
#include "metamgr.h" #include "metamgr.h"
#include "room.h" #include "room.h"
#include "bullet.h" #include "bullet.h"
@ -11,8 +10,6 @@
Human::Human() Human::Human()
{ {
movement = new MovementComponent();
movement->owner = this;
default_weapon.weapon_idx = 0; default_weapon.weapon_idx = 0;
default_weapon.weapon_id = 12101; default_weapon.weapon_id = 12101;
default_weapon.weapon_lv = 1; default_weapon.weapon_lv = 1;
@ -37,8 +34,6 @@ Human::Human()
Human::~Human() Human::~Human()
{ {
delete movement;
movement = nullptr;
} }
void Human::Initialize() void Human::Initialize()

View File

@ -2,7 +2,6 @@
#include "loot.h" #include "loot.h"
#include "metamgr.h" #include "metamgr.h"
#include "movement.h"
#include "room.h" #include "room.h"
#include "collider.h" #include "collider.h"

View File

@ -1,57 +0,0 @@
#include "precompile.h"
#include "movement.h"
#include "entity.h"
void MovementComponent::Update(int delta_time)
{
if (path_index_ < paths_.size()) {
MovePathPoint& target_point = paths_[path_index_];
if (owner->pos == target_point.pos) {
++path_index_;
return;
}
#if 1
assert(false);
#else
Vector2D dir = target_point.pos - owner->pos;
dir.Normalize();
float distance = path.Norm();
owner->pos = owner->pos + dir * std::min(move_speed_, distance);
if (owner->pos == target_point.pos) {
++path_index_;
}
#endif
}
}
bool MovementComponent::GetMovePosition(int delta_time, Vector2D& out_pos)
{
if (path_index_ < paths_.size()) {
MovePathPoint& target_point = paths_[path_index_];
out_pos = owner->pos + (target_point.pos - owner->pos) * delta_time * move_speed_;
} else {
out_pos = owner->pos;
}
return true;
}
bool MovementComponent::Arrived()
{
return path_index_ >= paths_.size();
}
void MovementComponent::AddPathPoint(Vector2D& pos, float distance, float speed)
{
MovePathPoint& point = a8::FastAppend(paths_);
point.pos = pos;
point.distance = distance;
move_speed_ = speed;
}
void MovementComponent::ClearPath()
{
move_speed_ = 0.0f;
path_index_ = 0;
paths_.clear();
}

View File

@ -1,25 +0,0 @@
#pragma once
struct MovePathPoint
{
Vector2D pos;
float distance = 0.0;
};
class Entity;
class MovementComponent
{
public:
Entity* owner = nullptr;
virtual void Update(int delta_time);
bool GetMovePosition(int delta_time, Vector2D& out_pos);
bool Arrived();
void AddPathPoint(Vector2D& pos, float distance, float speed);
void ClearPath();
private:
float move_speed_ = 0.0f;
size_t path_index_ = 0;
std::vector<MovePathPoint> paths_;
};

View File

@ -2,7 +2,6 @@
#include "obstacle.h" #include "obstacle.h"
#include "metamgr.h" #include "metamgr.h"
#include "movement.h"
#include "room.h" #include "room.h"
#include "collider.h" #include "collider.h"
#include "building.h" #include "building.h"

View File

@ -7,7 +7,6 @@
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
#include "room.h" #include "room.h"
#include "metamgr.h" #include "metamgr.h"
#include "movement.h"
#include "bullet.h" #include "bullet.h"
#include "obstacle.h" #include "obstacle.h"
#include "building.h" #include "building.h"
@ -37,7 +36,6 @@ void Player::Update(int delta_time)
if (poisoning) { if (poisoning) {
poisoning_time += delta_time; poisoning_time += delta_time;
} }
movement->Update(delta_time);
if (moving) { if (moving) {
UpdateMove(); UpdateMove();
} }

View File

@ -10,7 +10,6 @@
#include "room.h" #include "room.h"
#include "android.h" #include "android.h"
#include "metamgr.h" #include "metamgr.h"
#include "movement.h"
#include "bullet.h" #include "bullet.h"
#include "collider.h" #include "collider.h"
#include "obstacle.h" #include "obstacle.h"

View File

@ -8,7 +8,6 @@
#include "playermgr.h" #include "playermgr.h"
#include "app.h" #include "app.h"
#include "metamgr.h" #include "metamgr.h"
#include "movement.h"
void RoomMgr::Init() void RoomMgr::Init()
{ {

View File

@ -2,7 +2,6 @@
#include "smoke.h" #include "smoke.h"
#include "metamgr.h" #include "metamgr.h"
#include "movement.h"
#include "room.h" #include "room.h"
#include "collider.h" #include "collider.h"
#include "obstacle.h" #include "obstacle.h"