Skip to content

Commit

Permalink
Bar105 ground move perf improve (#1370)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: lostsquirrel <lostsquirrel43@gmail.com>
  • Loading branch information
marcushutchings and lostsquirrel1 authored Jun 30, 2024
1 parent 4b0f131 commit ab62871
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 134 deletions.
21 changes: 18 additions & 3 deletions rts/Sim/MoveTypes/Components/MoveTypesComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#ifndef MOVE_TYPE_COMPONENTS_H__
#define MOVE_TYPE_COMPONENTS_H__

#include "MoveTypesEvents.h"
#include "System/Ecs/Components/BaseComponents.h"

#include <System/Threading/ThreadPool.h>

struct CUnit;
struct CFeature;

namespace MoveTypes {

Expand All @@ -17,7 +18,7 @@ ALIAS_COMPONENT(GeneralMoveType, int);
// Special multi-thread ground move type.
ALIAS_COMPONENT(GroundMoveType, int);

// Used by units that have updated the ground collision map and may have trap units as a result.
// Used by units that have updated the ground collision map and may have trapped units as a result.
// This is used to allow such a situation to be detected immediately. The fall-back checks are too
// slow in practice.
enum UnitTrapCheckType {
Expand All @@ -28,6 +29,7 @@ struct UnitTrapCheck {
UnitTrapCheckType type;
int id;
};

template<class Archive>
void serialize(Archive &ar, UnitTrapCheck &c) { ar(c.type, c.id); }

Expand All @@ -38,13 +40,26 @@ void serializeComponents(Archive &archive, Snapshot &snapshot) {
>(archive);
}

struct YardmapTrapCheckSystemSystemComponent {
struct GroundMoveSystemComponent {
static constexpr std::size_t page_size = 1;
static constexpr std::size_t INITIAL_TRAP_UNIT_LIST_ALLOC_SIZE = 64;
};

struct YardmapTrapCheckSystemComponent {
static constexpr std::size_t page_size = 1;
static constexpr std::size_t INITIAL_TRAP_UNIT_LIST_ALLOC_SIZE = 8;

std::array<std::vector<CUnit*>, ThreadPool::MAX_THREADS> trappedUnitLists;
};

constexpr size_t UNIT_EVENT_VECTOR_RESERVE = 4;

ALIAS_COMPONENT_LIST_RESERVE(FeatureCollisionEvents, std::vector<FeatureCollisionEvent>, UNIT_EVENT_VECTOR_RESERVE);
ALIAS_COMPONENT_LIST_RESERVE(UnitCollisionEvents, std::vector<UnitCollisionEvent>, UNIT_EVENT_VECTOR_RESERVE);
ALIAS_COMPONENT_LIST_RESERVE(FeatureCrushEvents, std::vector<FeatureCrushEvent>, UNIT_EVENT_VECTOR_RESERVE);
ALIAS_COMPONENT_LIST_RESERVE(UnitCrushEvents, std::vector<UnitCrushEvent>, UNIT_EVENT_VECTOR_RESERVE);
ALIAS_COMPONENT_LIST_RESERVE(FeatureMoveEvents, std::vector<FeatureMoveEvent>, UNIT_EVENT_VECTOR_RESERVE);

}

#endif
96 changes: 96 additions & 0 deletions rts/Sim/MoveTypes/Components/MoveTypesEvents.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef MOVE_TYPE_EVENTS_H__
#define MOVE_TYPE_EVENTS_H__

#include "System/float3.h"

class CUnit;
class CFeature;
class CGroundMoveType;

namespace MoveTypes {

struct FeatureCollisionEvent {
CUnit* collider;
CFeature* collidee;

FeatureCollisionEvent(CUnit* _collider, CFeature* _collidee)
: collider(_collider)
, collidee(_collidee)
{}
};

struct FeatureCrushEvent {
CUnit* collider;
CFeature* collidee;
float3 crushImpulse;

FeatureCrushEvent(CUnit* _collider, CFeature* _collidee, float3 _crushImpulse)
: collider(_collider)
, collidee(_collidee)
, crushImpulse(_crushImpulse)
{}
};

struct FeatureMoveEvent {
CUnit* collider;
CFeature* collidee;
float3 moveImpulse;

FeatureMoveEvent(CUnit* _collider, CFeature* _collidee, float3 _moveImpulse)
: collider(_collider)
, collidee(_collidee)
, moveImpulse(_moveImpulse)
{}
};

struct UnitCollisionEvent {
CUnit* collider;
CUnit* collidee;

UnitCollisionEvent(CUnit* _collider, CUnit* _collidee)
: collider(_collider)
, collidee(_collidee)
{}
};

struct UnitCrushEvent {
CUnit* collider;
CUnit* collidee;
float3 crushImpulse;

UnitCrushEvent(CUnit* _collider, CUnit* _collidee, float3 _crushImpulse)
: collider(_collider)
, collidee(_collidee)
, crushImpulse(_crushImpulse)
{}
};

struct UnitMovedEvent {
CUnit* unit = nullptr;
bool moved = false;
};

struct ChangeHeadingEvent {
int unitId;
short deltaHeading = 0;
bool changed = false;

ChangeHeadingEvent(int _unitId)
: unitId(_unitId)
{}
};

struct ChangeMainHeadingEvent {
int unitId;
bool changed = false;

ChangeMainHeadingEvent(int _unitId)
: unitId(_unitId)
{}
};

}

#endif
Loading

0 comments on commit ab62871

Please sign in to comment.