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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix vectors, required and optional parameters handling in ColShape.Polygon APIs (client and server) #163
Fix vectors, required and optional parameters handling in ColShape.Polygon APIs (client and server) #163
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,10 +215,12 @@ int CLuaColShapeDefs::CreateColRectangle ( lua_State* luaVM ) | |
int CLuaColShapeDefs::CreateColPolygon ( lua_State* luaVM ) | ||
{ | ||
// colshape createColPolygon ( float fX, float fY, float fX1, float fY1, float fX2, float fY2, float fX3, float fY3, ... ) | ||
|
||
std::vector < CVector2D > vecPointList; | ||
|
||
// Get position and first 3 required points | ||
CScriptArgReader argStream ( luaVM ); | ||
for ( uint i = 0; i < 4 || argStream.NextCouldBeNumber (); i++ ) | ||
for ( uint i = 0; i < 4; i++ ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why didn't Did you test with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The former did work fine with numbers only, it couldn't work with more than 3 points passed as vectors. The latter worked fine, I indeed tested it first. I guess I then decided to make Client and Server side code look more alike. |
||
{ | ||
CVector2D vecPoint; | ||
argStream.ReadVector2D ( vecPoint ); | ||
|
@@ -233,6 +235,14 @@ int CLuaColShapeDefs::CreateColPolygon ( lua_State* luaVM ) | |
CResource* pResource = pLuaMain->GetResource (); | ||
if ( pResource ) | ||
{ | ||
// Get additional points | ||
while ( argStream.NextIsVector2D () ) | ||
{ | ||
CVector2D vecPoint; | ||
argStream.ReadVector2D ( vecPoint ); | ||
vecPointList.push_back ( vecPoint ); | ||
} | ||
|
||
CColPolygon* pShape = CStaticFunctionDefinitions::CreateColPolygon ( pResource, vecPointList ); | ||
if ( pShape ) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does
vecPointList
need to exist if its sole purpose is to performpShape->AddPoint( vecPointList[i] );
?Can't this line be replaced with
pShape->AddPoint( vecPoint );
?(This is an honest question. There's probably a very good reason as to why you're doing this!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is needed to store first 4 required vectors (position + 3 points),. An alternative would be to declare 4 separate variables. And since the list already exists and must be iterated over anyway, I thought it's reasonable to reuse it by pushing optional points to it too. This way
AddPoint
is called only in one loop instead of two which is more clean IMHO :) I don't know much about performance aspects here though.