Files
bluflame/aiwaz/Aiwaz/Commands/CommandBuffer.h
2026-04-18 22:31:51 +02:00

96 lines
2.4 KiB
C++

#pragma once
#include "ICommandUser.h"
class CommandBuffer
: public ICommandBuffer
{
public:
CommandBuffer(bool argCommandOwer, bool argChildBufferOwner);
virtual ~CommandBuffer();
virtual void Clear();
virtual void AddCommand(Command& argCommand);
virtual void Perform(bool argUseOptimizedList);
virtual void Optimize();
virtual void AddChildCommandBuffer(ICommandBuffer& argCommandBuffer);
virtual void RemoveChildCommandBuffer(ICommandBuffer& argCommandBuffer);
virtual std::vector<Command*>& get_BufferedCommands();
virtual const std::vector<ICommandBuffer*>& get_ChildCommandBuffers() const;
virtual ICommandBuffer* get_ParentBuffer() const;
virtual void set_ParentBuffer(ICommandBuffer* ar_CommandBuffer_);
protected:
void SearchDrawableCommandChain(ICommandBuffer* ar_Buffer_, std::vector<Command*>& argCurrentChain);
void FlushGatheredCommandChains();
private:
struct CommandChainInternal
{
CommandChainInternal() : m_Priority(0) {}
void UpdatePriority()
{
m_Priority = -1;
for (uint32 i = 0; i < m_Chain.size(); ++i)
{
if (m_Chain[i]->Flags & CommandFlags::SubChainStart)
{
m_Priority = m_Chain[i]->SubPriority;
break;
}
}
}
UINT8 m_Priority;
std::vector<Command*> m_Chain;
struct CommandChainSort
{
bool operator()(CommandChainInternal* ar_Left_, CommandChainInternal* ar_Right_) const
{
if (ar_Left_->m_Priority == ar_Right_->m_Priority)
return ar_Left_->m_Chain.size() < ar_Right_->m_Chain.size();
return ar_Left_->m_Priority < ar_Right_->m_Priority;
}
};
struct CommandSort
{
bool operator()(Command* ar_Left_, Command* ar_Right_) const
{
return ar_Left_->Priority < ar_Right_->Priority;
}
};
};
private:
ICommandBuffer* m_ParentCommandBuffer;
ICommandBuffer* m_OptimizedCommandBuffer;
std::vector<Command*> m_CommandList;
std::vector<ICommandBuffer*> m_ChildCommandBuffers;
bool m_CommandOwer;
bool m_ChildBufferOwner;
std::map<uint32, std::vector<Command*> > m_HashToCommandChain;
intptr_t GenerateHashValue(const std::vector<Command*>& argCommands) const
{
intptr_t hash = 0;
for (uint32 i = 0; i < argCommands.size(); ++i)
{
hash += (intptr_t)argCommands[i];
hash += (hash << 10);
hash ^= (hash >> 6);
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
}
return hash;
}
std::vector<CommandChainInternal*> m_GatheredCommandChains;
};