updated rcon

master
Martin Gerhardy 2016-03-01 07:25:05 +01:00
parent 03b2271621
commit 87bd205c26
14 changed files with 76 additions and 26 deletions

View File

@ -17,6 +17,7 @@ class AINodeStaticResolver;
* don't need this. * don't need this.
*/ */
class AIApplication: public QApplication { class AIApplication: public QApplication {
Q_OBJECT
protected: protected:
AIDebugger* _debugger; AIDebugger* _debugger;
AINodeStaticResolver* _resolver; AINodeStaticResolver* _resolver;

View File

@ -100,7 +100,7 @@ public:
AIDebugger::AIDebugger(AINodeStaticResolver& resolver) : AIDebugger::AIDebugger(AINodeStaticResolver& resolver) :
QObject(), _stateHandler(new StateHandler(*this)), _characterHandler(new CharacterHandler(*this)), _characterStaticHandler( QObject(), _stateHandler(new StateHandler(*this)), _characterHandler(new CharacterHandler(*this)), _characterStaticHandler(
new CharacterStaticHandler(*this)), _pauseHandler(new PauseHandler(*this)), _namesHandler(new NamesHandler(*this)), _nopHandler( new CharacterStaticHandler(*this)), _pauseHandler(new PauseHandler(*this)), _namesHandler(new NamesHandler(*this)), _nopHandler(
new NopHandler()), _selectedId(-1), _socket(this), _pause(false), _resolver(resolver) { new NopHandler()), _selectedId(AI_NOTHING_SELECTED), _socket(this), _pause(false), _resolver(resolver) {
connect(&_socket, SIGNAL(readyRead()), SLOT(readTcpData())); connect(&_socket, SIGNAL(readyRead()), SLOT(readTcpData()));
connect(&_socket, SIGNAL(disconnected()), SLOT(onDisconnect())); connect(&_socket, SIGNAL(disconnected()), SLOT(onDisconnect()));
@ -153,7 +153,9 @@ void AIDebugger::togglePause() {
} }
void AIDebugger::select(const ai::AIStateWorld& ai) { void AIDebugger::select(const ai::AIStateWorld& ai) {
writeMessage(AISelectMessage(ai.getId())); const ai::CharacterId id = ai.getId();
qDebug() << "select " << id;
writeMessage(AISelectMessage(id));
} }
bool AIDebugger::writeMessage(const IProtocolMessage& msg) { bool AIDebugger::writeMessage(const IProtocolMessage& msg) {
@ -185,10 +187,12 @@ bool AIDebugger::writeMessage(const IProtocolMessage& msg) {
} }
void AIDebugger::unselect() { void AIDebugger::unselect() {
writeMessage(AISelectMessage(-1)); writeMessage(AISelectMessage(AI_NOTHING_SELECTED));
_selectedId = -1; _selectedId = AI_NOTHING_SELECTED;
_aggro.clear(); _aggro.clear();
_node = AIStateNode(); _node = AIStateNode();
_attributes.clear();
emit onSelected();
qDebug() << "unselect entity"; qDebug() << "unselect entity";
} }
@ -248,7 +252,7 @@ void AIDebugger::onDisconnect() {
emit onPause(_pause); emit onPause(_pause);
} }
{ {
_selectedId = -1; _selectedId = AI_NOTHING_SELECTED;
_aggro.clear(); _aggro.clear();
_attributes.clear(); _attributes.clear();
_node = AIStateNode(); _node = AIStateNode();
@ -262,7 +266,6 @@ void AIDebugger::onDisconnect() {
_entities.clear(); _entities.clear();
emit onEntitiesUpdated(); emit onEntitiesUpdated();
} }
emit disconnect();
} }
void AIDebugger::readTcpData() { void AIDebugger::readTcpData() {
@ -278,7 +281,8 @@ void AIDebugger::readTcpData() {
for (;;) { for (;;) {
if (!mf.isNewMessageAvailable(_stream)) if (!mf.isNewMessageAvailable(_stream))
break; break;
std::unique_ptr<ai::IProtocolMessage> msg(mf.create(_stream)); // don't free this - preallocated memory that is reused
ai::IProtocolMessage* msg = mf.create(_stream);
if (!msg) { if (!msg) {
qDebug() << "unknown server message - disconnecting"; qDebug() << "unknown server message - disconnecting";
_socket.disconnectFromHost(); _socket.disconnectFromHost();
@ -303,16 +307,27 @@ MapView* AIDebugger::createMapWidget() {
void AIDebugger::setNames(const std::vector<std::string>& names) { void AIDebugger::setNames(const std::vector<std::string>& names) {
_names.clear(); _names.clear();
for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) { _names.reserve(names.size());
_names << QString::fromStdString(*i); // TODO: measure if contains/remove/insert manually is faster
for (const std::string& name : names) {
_names << QString::fromStdString(name);
} }
} }
void AIDebugger::setEntities(const std::vector<AIStateWorld>& entities) { void AIDebugger::setEntities(const std::vector<AIStateWorld>& entities) {
_entities.clear(); _entities.clear();
for (std::vector<AIStateWorld>::const_iterator i = entities.begin(); i != entities.end(); ++i) { // TODO: measure if contains/remove/insert manually is faster
_entities.insert(i->getId(), *i); for (const AIStateWorld& state : entities) {
_entities.insert(state.getId(), state);
} }
if (_selectedId == AI_NOTHING_SELECTED) {
return;
}
if (_entities.contains(_selectedId)) {
return;
}
// TODO: this doesn't work for some reason
// unselect();
} }
} }

View File

@ -5,7 +5,7 @@ namespace ai {
namespace debug { namespace debug {
AggroTable::AggroTable(AIDebugger& debugger) : AggroTable::AggroTable(AIDebugger& debugger) :
QTableView(), _model(debugger, this), _debugger(debugger) { QTableView(), _model(debugger, this) {
_proxyModel.setSourceModel(&_model); _proxyModel.setSourceModel(&_model);
setModel(&_proxyModel); setModel(&_proxyModel);
setAlternatingRowColors(true); setAlternatingRowColors(true);

View File

@ -16,7 +16,6 @@ class AggroTable: public QTableView {
private: private:
AggroTableModel _model; AggroTableModel _model;
QSortFilterProxyModel _proxyModel; QSortFilterProxyModel _proxyModel;
AIDebugger& _debugger;
public: public:
AggroTable(AIDebugger& debugger); AggroTable(AIDebugger& debugger);
virtual ~AggroTable(); virtual ~AggroTable();

View File

@ -10,9 +10,10 @@ EntityList::EntityList(AIDebugger& debugger, QLineEdit* entityFilter) :
_proxyModel.setSourceModel(&_model); _proxyModel.setSourceModel(&_model);
setModel(&_proxyModel); setModel(&_proxyModel);
setAlternatingRowColors(true); setAlternatingRowColors(true);
setSortingEnabled(true); setSortingEnabled(false);
setSelectionMode(QAbstractItemView::SingleSelection); setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionBehavior(QAbstractItemView::SelectRows);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
verticalHeader()->hide(); verticalHeader()->hide();
horizontalHeader()->setStretchLastSection(true); horizontalHeader()->setStretchLastSection(true);
@ -26,12 +27,14 @@ EntityList::~EntityList() {
void EntityList::updateEntityList() { void EntityList::updateEntityList() {
_model.update(); _model.update();
_model.sort(0);
} }
void EntityList::selectEntity(const QModelIndex &current, const QModelIndex &previous) { void EntityList::selectEntity(const QModelIndex &current, const QModelIndex &previous) {
Q_UNUSED(previous); Q_UNUSED(previous);
const AIStateWorld& state = _model.getEntities().at(_proxyModel.mapToSource(current).row()); if (!current.isValid())
return;
const QModelIndex index = _proxyModel.mapToSource(current);
const AIStateWorld& state = _model.getEntities().at(index.row());
_debugger.select(state); _debugger.select(state);
} }

View File

@ -11,9 +11,21 @@ EntityListModel::EntityListModel(AIDebugger& debugger, QTableView *parent) :
EntityListModel::~EntityListModel() { EntityListModel::~EntityListModel() {
} }
QModelIndex EntityListModel::characterIndex(CharacterId id) const {
int row = 0;
for (const AIStateWorld& state : _list) {
if (state.getId() == id)
return createIndex(row, 0);
++row;
}
qDebug() << "Could not find entity " << id << " in the model";
return QModelIndex();
}
void EntityListModel::update() { void EntityListModel::update() {
beginResetModel(); beginResetModel();
_list = _debugger.getEntities().values(); _list = _debugger.getEntities().values();
// TODO: sort list - not model
endResetModel(); endResetModel();
} }

View File

@ -23,6 +23,7 @@ public:
} }
void update(); void update();
QModelIndex characterIndex(CharacterId id) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;

View File

@ -20,23 +20,41 @@ MapView::~MapView() {
} }
MapItem* MapView::createMapItem(const AIStateWorld& state) { MapItem* MapView::createMapItem(const AIStateWorld& state) {
MapItem* item = new MapItem(nullptr, state, _debugger); auto i = _items.find(state.getId());
MapItem* item;
if (i != _items.end()) {
item = i.value();
} else {
item = new MapItem(nullptr, state, _debugger);
}
item->setPos((qreal)state.getPosition().x, (qreal)state.getPosition().z); item->setPos((qreal)state.getPosition().x, (qreal)state.getPosition().z);
if (_debugger.isSelected(state)) { if (_debugger.isSelected(state)) {
item->setZValue(std::numeric_limits<qreal>::max()); item->setZValue(std::numeric_limits<qreal>::max());
} else { } else {
item->setZValue((qreal)state.getPosition().y); item->setZValue((qreal)state.getPosition().y);
} }
if (i == _items.end())
return nullptr;
_items[state.getId()] = item;
return item; return item;
} }
void MapView::updateMapView() { void MapView::updateMapView() {
_scene.clear(); QHash<ai::CharacterId, MapItem*> copy(_items);
const AIDebugger::Entities& e = _debugger.getEntities(); const AIDebugger::Entities& e = _debugger.getEntities();
for (AIDebugger::EntitiesIter i = e.begin(); i != e.end(); ++i) { for (AIDebugger::EntitiesIter i = e.begin(); i != e.end(); ++i) {
copy.remove(i->getId());
MapItem* item = createMapItem(*i); MapItem* item = createMapItem(*i);
if (item == nullptr)
continue;
_scene.addItem(item); _scene.addItem(item);
} }
// remove the remaining entities - they are no longer part of the snapshot
for (auto i = copy.begin(); i != copy.end(); ++i) {
_scene.removeItem(i.value());
_items.remove(i.key());
}
} }
} }

View File

@ -22,6 +22,7 @@ class MapView: public IGraphicsView {
protected: protected:
QGraphicsScene _scene; QGraphicsScene _scene;
AIDebugger& _debugger; AIDebugger& _debugger;
QHash<ai::CharacterId, MapItem*> _items;
public: public:
MapView(AIDebugger& debugger); MapView(AIDebugger& debugger);
virtual ~MapView(); virtual ~MapView();

View File

@ -5,7 +5,7 @@ namespace ai {
namespace debug { namespace debug {
StateTable::StateTable(AIDebugger& debugger) : StateTable::StateTable(AIDebugger& debugger) :
QTableView(), _model(debugger), _debugger(debugger) { QTableView(), _model(debugger) {
_proxyModel.setSourceModel(&_model); _proxyModel.setSourceModel(&_model);
setModel(&_proxyModel); setModel(&_proxyModel);
setAlternatingRowColors(true); setAlternatingRowColors(true);

View File

@ -16,7 +16,6 @@ class StateTable: public QTableView {
private: private:
StateTableModel _model; StateTableModel _model;
QSortFilterProxyModel _proxyModel; QSortFilterProxyModel _proxyModel;
AIDebugger& _debugger;
public: public:
StateTable(AIDebugger& debugger); StateTable(AIDebugger& debugger);
virtual ~StateTable(); virtual ~StateTable();

View File

@ -153,8 +153,11 @@ void BehaviourTreeModel::setRootNode(AIStateNode* node) {
beginResetModel(); beginResetModel();
if (_rootItem) { if (_rootItem) {
delete _rootItem; delete _rootItem;
_rootItem = nullptr;
} }
if (node->getNodeId() != -1) {
_rootItem = new BehaviourTreeModelItem(node, _resolver); _rootItem = new BehaviourTreeModelItem(node, _resolver);
}
endResetModel(); endResetModel();
} }

View File

@ -7,12 +7,12 @@ namespace ai {
namespace debug { namespace debug {
BehaviourTreeModelItem::BehaviourTreeModelItem(AIStateNode* node, AINodeStaticResolver& resolver, BehaviourTreeModelItem* parent) : BehaviourTreeModelItem::BehaviourTreeModelItem(AIStateNode* node, AINodeStaticResolver& resolver, BehaviourTreeModelItem* parent) :
_node(node), _staticNodeData(resolver.get(node->getNodeId())), _populated(false), _rowCount(0), _parent(parent) { _node(node), _staticNodeData(resolver.get(node->getNodeId())), _parent(parent) {
if (_parent == nullptr) { if (_parent == nullptr) {
_rows.push_back(new BehaviourTreeModelItem(_node, resolver, this)); _rows.push_back(new BehaviourTreeModelItem(_node, resolver, this));
} else { } else {
for (const AIStateNode& node : _node->getChildren()) { for (const AIStateNode& stateNode : _node->getChildren()) {
_rows.push_back(new BehaviourTreeModelItem(const_cast<AIStateNode*>(&node), resolver, this)); _rows.push_back(new BehaviourTreeModelItem(const_cast<AIStateNode*>(&stateNode), resolver, this));
} }
} }
const QString type = QString::fromStdString(_staticNodeData.getType()).toLower(); const QString type = QString::fromStdString(_staticNodeData.getType()).toLower();

View File

@ -23,8 +23,6 @@ class BehaviourTreeModelItem {
private: private:
AIStateNode* _node; AIStateNode* _node;
const AIStateNodeStatic& _staticNodeData; const AIStateNodeStatic& _staticNodeData;
bool _populated;
int _rowCount;
QList<BehaviourTreeModelItem*> _rows; QList<BehaviourTreeModelItem*> _rows;
BehaviourTreeModelItem* _parent; BehaviourTreeModelItem* _parent;
QIcon _icon; QIcon _icon;