From 49fd11ab5aebcbce86ca2ee48711287cf020d798 Mon Sep 17 00:00:00 2001 From: Nefarion Date: Fri, 8 Mar 2013 21:41:30 +0100 Subject: First step of comment style refactoring to doxygen-style. --- src/server/shared/Database/DatabaseWorkerPool.h | 2 +- src/server/shared/Database/MySQLConnection.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/server/shared/Database') diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h index c43cc8fab82..524a3de2628 100644 --- a/src/server/shared/Database/DatabaseWorkerPool.h +++ b/src/server/shared/Database/DatabaseWorkerPool.h @@ -388,7 +388,7 @@ class DatabaseWorkerPool } //! Handle MySQL Errno 1213 without extending deadlock to the core itself - //! TODO: More elegant way + /// @todo More elegant way if (con->GetLastError() == 1213) { uint8 loopBreaker = 5; diff --git a/src/server/shared/Database/MySQLConnection.cpp b/src/server/shared/Database/MySQLConnection.cpp index ce23f4ca4f6..a5bcac7eeef 100644 --- a/src/server/shared/Database/MySQLConnection.cpp +++ b/src/server/shared/Database/MySQLConnection.cpp @@ -188,7 +188,7 @@ bool MySQLConnection::Execute(PreparedStatement* stmt) MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index); ASSERT(m_mStmt); // Can only be null if preparation failed, server side error or bad query m_mStmt->m_stmt = stmt; // Cross reference them for debug output - stmt->m_stmt = m_mStmt; // TODO: Cleaner way + stmt->m_stmt = m_mStmt; /// @todo Cleaner way stmt->BindParameters(); @@ -238,7 +238,7 @@ bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint6 MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index); ASSERT(m_mStmt); // Can only be null if preparation failed, server side error or bad query m_mStmt->m_stmt = stmt; // Cross reference them for debug output - stmt->m_stmt = m_mStmt; // TODO: Cleaner way + stmt->m_stmt = m_mStmt; /// @todo Cleaner way stmt->BindParameters(); -- cgit v1.2.3 From 4e789d4c5c83dd6f0f582fe24e9d49b39950fffe Mon Sep 17 00:00:00 2001 From: Vincent_Michael Date: Sat, 9 Mar 2013 23:05:27 +0100 Subject: Core/Commands: Optimize for command .npc near --- src/server/scripts/Commands/cs_npc.cpp | 42 ++++++++-------------- .../Database/Implementation/WorldDatabase.cpp | 1 - .../shared/Database/Implementation/WorldDatabase.h | 1 - 3 files changed, 14 insertions(+), 30 deletions(-) (limited to 'src/server/shared/Database') diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index 79a74b0823d..f640d257a3a 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -665,43 +665,29 @@ public: static bool HandleNpcNearCommand(ChatHandler* handler, char const* args) { + WorldObject* object = handler->GetSession()->GetPlayer(); float distance = (!*args) ? 10.0f : float((atof(args))); uint32 count = 0; - Player* player = handler->GetSession()->GetPlayer(); + CellCoord pair(Trinity::ComputeCellCoord(object->GetPositionX(), object->GetPositionY())); + Cell cell(pair); + cell.SetNoCreate(); + + std::list creatureList; + Trinity::AnyUnitInObjectRangeCheck check(object, distance); + Trinity::CreatureListSearcher search(object, creatureList, check); + TypeContainerVisitor, GridTypeMapContainer> visit(search); - PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_NEAREST); - stmt->setFloat(0, player->GetPositionX()); - stmt->setFloat(1, player->GetPositionY()); - stmt->setFloat(2, player->GetPositionZ()); - stmt->setUInt32(3, player->GetMapId()); - stmt->setFloat(4, player->GetPositionX()); - stmt->setFloat(5, player->GetPositionY()); - stmt->setFloat(6, player->GetPositionZ()); - stmt->setFloat(7, distance * distance); - PreparedQueryResult result = WorldDatabase.Query(stmt); + cell.Visit(pair, visit, *(object->GetMap()), *object, distance); - if (result) + if (!creatureList.empty()) { - do + for (std::list::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr) { - Field* fields = result->Fetch(); - uint32 guid = fields[0].GetUInt32(); - uint32 entry = fields[1].GetUInt32(); - float x = fields[2].GetFloat(); - float y = fields[3].GetFloat(); - float z = fields[4].GetFloat(); - uint16 mapId = fields[5].GetUInt16(); - - CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry); - if (!creatureTemplate) - continue; - - handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, creatureTemplate->Name.c_str(), x, y, z, mapId); - + handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, (*itr)->GetGUIDLow(), (*itr)->GetGUIDLow(), (*itr)->GetName().c_str(), + (*itr)->GetPositionX(), (*itr)->GetPositionY(), (*itr)->GetPositionZ(), (*itr)->GetMapId()); ++count; } - while (result->NextRow()); } handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count); diff --git a/src/server/shared/Database/Implementation/WorldDatabase.cpp b/src/server/shared/Database/Implementation/WorldDatabase.cpp index 89f3cf8fdce..94060330d82 100644 --- a/src/server/shared/Database/Implementation/WorldDatabase.cpp +++ b/src/server/shared/Database/Implementation/WorldDatabase.cpp @@ -84,7 +84,6 @@ void WorldDatabaseConnection::DoPrepareStatements() PrepareStatement(WORLD_SEL_ITEM_TEMPLATE_BY_NAME, "SELECT entry FROM item_template WHERE name = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH); - PrepareStatement(WORLD_SEL_CREATURE_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM creature WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH); PrepareStatement(WORLD_INS_CREATURE, "INSERT INTO creature (guid, id , map, spawnMask, phaseMask, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(WORLD_DEL_GAME_EVENT_CREATURE, "DELETE FROM game_event_creature WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_DEL_GAME_EVENT_MODEL_EQUIP, "DELETE FROM game_event_model_equip WHERE guid = ?", CONNECTION_ASYNC); diff --git a/src/server/shared/Database/Implementation/WorldDatabase.h b/src/server/shared/Database/Implementation/WorldDatabase.h index 032baf29dd9..f6fd92b11cd 100644 --- a/src/server/shared/Database/Implementation/WorldDatabase.h +++ b/src/server/shared/Database/Implementation/WorldDatabase.h @@ -104,7 +104,6 @@ enum WorldDatabaseStatements WORLD_SEL_ITEM_TEMPLATE_BY_NAME, WORLD_SEL_CREATURE_BY_ID, WORLD_SEL_GAMEOBJECT_NEAREST, - WORLD_SEL_CREATURE_NEAREST, WORLD_SEL_GAMEOBJECT_TARGET, WORLD_INS_CREATURE, WORLD_DEL_GAME_EVENT_CREATURE, -- cgit v1.2.3 From 4ee0a4a4460ff0a44f39a5359c6e234c9d31fc6b Mon Sep 17 00:00:00 2001 From: Vincent_Michael Date: Sat, 9 Mar 2013 23:28:32 +0100 Subject: Revert "Core/Commands: Optimize for command .npc near" This reverts commit 4e789d4c5c83dd6f0f582fe24e9d49b39950fffe. --- src/server/scripts/Commands/cs_npc.cpp | 42 ++++++++++++++-------- .../Database/Implementation/WorldDatabase.cpp | 1 + .../shared/Database/Implementation/WorldDatabase.h | 1 + 3 files changed, 30 insertions(+), 14 deletions(-) (limited to 'src/server/shared/Database') diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index f640d257a3a..79a74b0823d 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -665,29 +665,43 @@ public: static bool HandleNpcNearCommand(ChatHandler* handler, char const* args) { - WorldObject* object = handler->GetSession()->GetPlayer(); float distance = (!*args) ? 10.0f : float((atof(args))); uint32 count = 0; - CellCoord pair(Trinity::ComputeCellCoord(object->GetPositionX(), object->GetPositionY())); - Cell cell(pair); - cell.SetNoCreate(); - - std::list creatureList; - Trinity::AnyUnitInObjectRangeCheck check(object, distance); - Trinity::CreatureListSearcher search(object, creatureList, check); - TypeContainerVisitor, GridTypeMapContainer> visit(search); + Player* player = handler->GetSession()->GetPlayer(); - cell.Visit(pair, visit, *(object->GetMap()), *object, distance); + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_NEAREST); + stmt->setFloat(0, player->GetPositionX()); + stmt->setFloat(1, player->GetPositionY()); + stmt->setFloat(2, player->GetPositionZ()); + stmt->setUInt32(3, player->GetMapId()); + stmt->setFloat(4, player->GetPositionX()); + stmt->setFloat(5, player->GetPositionY()); + stmt->setFloat(6, player->GetPositionZ()); + stmt->setFloat(7, distance * distance); + PreparedQueryResult result = WorldDatabase.Query(stmt); - if (!creatureList.empty()) + if (result) { - for (std::list::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr) + do { - handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, (*itr)->GetGUIDLow(), (*itr)->GetGUIDLow(), (*itr)->GetName().c_str(), - (*itr)->GetPositionX(), (*itr)->GetPositionY(), (*itr)->GetPositionZ(), (*itr)->GetMapId()); + Field* fields = result->Fetch(); + uint32 guid = fields[0].GetUInt32(); + uint32 entry = fields[1].GetUInt32(); + float x = fields[2].GetFloat(); + float y = fields[3].GetFloat(); + float z = fields[4].GetFloat(); + uint16 mapId = fields[5].GetUInt16(); + + CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry); + if (!creatureTemplate) + continue; + + handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, creatureTemplate->Name.c_str(), x, y, z, mapId); + ++count; } + while (result->NextRow()); } handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count); diff --git a/src/server/shared/Database/Implementation/WorldDatabase.cpp b/src/server/shared/Database/Implementation/WorldDatabase.cpp index 94060330d82..89f3cf8fdce 100644 --- a/src/server/shared/Database/Implementation/WorldDatabase.cpp +++ b/src/server/shared/Database/Implementation/WorldDatabase.cpp @@ -84,6 +84,7 @@ void WorldDatabaseConnection::DoPrepareStatements() PrepareStatement(WORLD_SEL_ITEM_TEMPLATE_BY_NAME, "SELECT entry FROM item_template WHERE name = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_CREATURE_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM creature WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH); PrepareStatement(WORLD_INS_CREATURE, "INSERT INTO creature (guid, id , map, spawnMask, phaseMask, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, spawndist, currentwaypoint, curhealth, curmana, MovementType, npcflag, unit_flags, dynamicflags) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(WORLD_DEL_GAME_EVENT_CREATURE, "DELETE FROM game_event_creature WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_DEL_GAME_EVENT_MODEL_EQUIP, "DELETE FROM game_event_model_equip WHERE guid = ?", CONNECTION_ASYNC); diff --git a/src/server/shared/Database/Implementation/WorldDatabase.h b/src/server/shared/Database/Implementation/WorldDatabase.h index f6fd92b11cd..032baf29dd9 100644 --- a/src/server/shared/Database/Implementation/WorldDatabase.h +++ b/src/server/shared/Database/Implementation/WorldDatabase.h @@ -104,6 +104,7 @@ enum WorldDatabaseStatements WORLD_SEL_ITEM_TEMPLATE_BY_NAME, WORLD_SEL_CREATURE_BY_ID, WORLD_SEL_GAMEOBJECT_NEAREST, + WORLD_SEL_CREATURE_NEAREST, WORLD_SEL_GAMEOBJECT_TARGET, WORLD_INS_CREATURE, WORLD_DEL_GAME_EVENT_CREATURE, -- cgit v1.2.3