Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core/AreaTrigger : Basic areaTrigger entities system #17997

Closed
wants to merge 11 commits into from
Closed

Core/AreaTrigger : Basic areaTrigger entities system #17997

wants to merge 11 commits into from

Conversation

Traesh
Copy link
Contributor

@Traesh Traesh commented Sep 25, 2016

Changes proposed:

  • Basic AreaTrigger Entities handlers.
  • Currently handle non-moving, non-scaling AreaTrigger created by spell effect 179
  • handle type SPHERE, BOX, CYLINDER, POLYGON
  • Added C++ script hooks

Target branch(es): 6.x

Issues addressed:

Tests performed: (Does it build, tested in-game, etc)
Builded
Tested ingame with spell 187651 (AreaTrigger 4424), type Cylinder
Tested ingame with spell 163559 (AreaTrigger 2472), type Polygon

Known issues and ToDo list:

  • This is the basic system, ToDo won't be fixed in this PR :
  • SAI Events
  • Moving areatriggers (Spline)
  • Scaling areatriggers
  • Find UNK Flags
  • Implement unhandled flags

@PalWow
Copy link

PalWow commented Sep 25, 2016

wow.


public:
// Called when the AreaTrigger has just been created
void OnCreate(AreaTrigger* areaTrigger) { }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't all of these be virtual void? sorry if it's a dumb question

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a dumb question, you were right :)

Copy link

@matukaa matukaa Sep 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, make Travis happy, use/*areaTrigger*/ /*unit*/ and /*diff*/ :D

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but all together, amazing job ^^

@@ -2297,6 +2305,9 @@ class TC_GAME_API Unit : public WorldObject
typedef std::list<GameObject*> GameObjectList;
GameObjectList m_gameObj;

typedef std::list<AreaTrigger*> AreaTriggerList;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector is prefered i think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, DEFINITELY use a vector

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well Unit::_UnregisterAreaTrigger use the .remove function, which is lacking in std::vector

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_areaTrigger.erase(std::remove(m_areaTrigger.begin(), m_areaTrigger.end(), areaTrigger));

Copy link

@matukaa matukaa Sep 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shauren erasing twice will cause out of range exception :) either .erase and provide an iterator, or std::remove. std::remove will give you a past-end iterator, so if you call .erase with that, it will crash the server. maybe you wanted std::find() instead of std::remove()?
Also, I suggest making a for through m_areaTriggers on WorldSession::LogoutPlayer, and calling Remove() function for all of them. All other objects get deleted before logging out, except AreaTriggers. this also caused crashes for me (though not on logout, but on login, Map::Update() tried to call _UnregisterAreaTrigger, but it wasn't in m_areaTriggers, so it got invalid itr, and crashed.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matukaa std::remove does not remove the element from container. It moves it to the end of it and gives you iterator pointing to it (more precisely, past the end of unerased elements = first erased one)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shauren I understand, thanks for clarification :) although m_areaTrigger.erase(std::find()) should also work, no? (completely offtopic)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

`data5` float NOT NULL DEFAULT '0',
`scriptName` char(64) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#17976 (comment) applies here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't the comment about using MyISAM ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, i cant read, ignore it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpperCamelCase style for columns since all new fields are named so
default uint32 type is int(10) unsigned
add a VerifiedBuild field for tables that have sniffable content

@frozen4
Copy link
Contributor

frozen4 commented Sep 25, 2016

great work

Copy link
Contributor

@Naios Naios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Replace self invented techniques by G3D methods.
  • Add script swap hook
  • Replace list -> vector

@@ -0,0 +1,41 @@
CREATE TABLE `areatrigger_template` (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the table before creating it please (same in the create statement below)


m_valuesCount = AREATRIGGER_END;
_dynamicValuesCount = AREATRIGGER_DYNAMIC_END;

_areaTriggerTemplate = nullptr;
Copy link
Contributor

@Naios Naios Sep 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize this in L32 after _timeSinceCreated please (_areaTriggerTemplate(nullptr)).

float tempX = vertice.VerticeX;
float tempY = vertice.VerticeY;

vertice.VerticeX = tempX * angleCos - tempY * angleSin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no rotation implementation you could use from G3D?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not found any, but I'm open to suggestions.


void AreaTrigger::SearchUnitInSphere()
{
std::list<Unit*> targetList;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Shauren said already: list -> vector

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think UnitListSearcher only accept std::list at this time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right, leave it for now as it is, the searchers probably need an overall refactoring...

Trinity::UnitListSearcher<Trinity::AnyUnitInObjectRangeCheck> searcher(this, targetList, check);
VisitNearbyObject(GetTemplate()->MaxSearchRadius, searcher);

float halfExtentsX = extentsX / 2.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of the box seems legit however G3D offers this implementation already through AABox, you could use:

AABox box({x_low, y_low, z_low}, {x_high, y_high, z_high});
...
box.contains({x, y, z});

instead.

@@ -96,6 +96,10 @@ template<>
struct is_script_database_bound<AchievementCriteriaScript>
: std::true_type { };

template<>
struct is_script_database_bound<AreaTriggerEntityScript>
Copy link
Contributor

@Naios Naios Sep 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AreaTriggerEntityScript also needs a specialization of ScriptRegistrySwapHooks to be swapped correctly when using script hotswapping (otherwise it will cause crashes because unloaded scripts are not cleaned up and will still be referenced).

If you can't make it specialize it as:

template<typename Base>
class ScriptRegistrySwapHooks<AreaTriggerEntityScript, Base>
    : public UnsupportedScriptRegistrySwapHooks<Base> { };

and I will take care of it before it gets merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review, i will take a look :)

I suppose i have to do the same thing for SceneScript ?

#17976

Copy link
Contributor

@Naios Naios Sep 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good catch. It has to be done for every database bound script (scripts that use scriptnames in the database).

@Rochet2
Copy link
Contributor

Rochet2 commented Sep 25, 2016

Should IDs be used instead to avoid dangling pointers in AreaTriggerList?

# Conflicts:
#	src/server/game/Accounts/RBAC.h
#	src/server/game/Globals/ObjectMgr.cpp
#	src/server/game/Globals/ObjectMgr.h
#	src/server/game/Scripting/ScriptMgr.cpp
#	src/server/game/Scripting/ScriptMgr.h
#	src/server/game/World/World.cpp
#	src/server/scripts/Commands/cs_reload.cpp
@ghost
Copy link

ghost commented Oct 3, 2016

Any closing comment (reason for closing) ?

@Traesh
Copy link
Contributor Author

Traesh commented Oct 3, 2016

Sry, same reason as Conversation (fail on previous repo), new PR here : #18035

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants