Skip to content

Commit

Permalink
add more parameters to ClosestPos creator
Browse files Browse the repository at this point in the history
  • Loading branch information
rtldg committed Nov 2, 2021
1 parent 05eff08 commit 128f9ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
31 changes: 28 additions & 3 deletions extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ void ClosestPos::SDK_OnUnload()
g_pHandleSys->RemoveType(g_ClosestPosType, myself->GetIdentity());
}

#define asdfMIN(a,b) (((a)<(b))?(a):(b))
#define asdfMAX(a,b) (((a)>(b))?(a):(b))

static cell_t sm_CreateClosestPos(IPluginContext *pContext, const cell_t *params)
{
ICellArray *pArray;
Expand All @@ -228,12 +231,34 @@ static cell_t sm_CreateClosestPos(IPluginContext *pContext, const cell_t *params
return pContext->ThrowNativeError("Invalid ArrayList Handle %x (error %d)", arraylist, err);
}

auto size = pArray->size();
cell_t startidx = 0;
cell_t count = size;

if (params[0] > 2)
{
startidx = params[3];
count = params[4];

if (startidx < 0 || startidx > (size-1))
{
return pContext->ThrowNativeError("startidx (%d) must be >=0 and less than the ArrayList size (%d)", startidx, size);
}

if (count < 1)
{
return pContext->ThrowNativeError("count must be 1 or greater (given %d)", count);
}

count = asdfMIN(count, size-startidx);
}

KDTreeContainer *container = new KDTreeContainer();
container->cloud.pts.resize(pArray->size());
container->cloud.pts.resize(count);

for (size_t i = 0; i < pArray->size(); i++)
for (size_t i = 0; i < count; i++)
{
cell_t *blk = pArray->at(i);
cell_t *blk = pArray->at(startidx+i);
container->cloud.pts[i].x = sp_ctof(blk[offset+0]);
container->cloud.pts[i].y = sp_ctof(blk[offset+1]);
container->cloud.pts[i].z = sp_ctof(blk[offset+2]);
Expand Down
2 changes: 1 addition & 1 deletion include/closestpos.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define _closestpos_included

methodmap ClosestPos < Handle {
public native ClosestPos(ArrayList input, int offset=0);
public native ClosestPos(ArrayList input, int offset=0, int startidx=0, int count=2147483646);
public native int Find(float pos[3]);
};

Expand Down
2 changes: 1 addition & 1 deletion smsdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/* Basic information exposed publicly */
#define SMEXT_CONF_NAME "ClosestPos"
#define SMEXT_CONF_DESCRIPTION "Provides a type that can be used to quickly find the closest point to the input position."
#define SMEXT_CONF_VERSION "1.0.0.0"
#define SMEXT_CONF_VERSION "1.1.0.0"
#define SMEXT_CONF_AUTHOR "rtldg"
#define SMEXT_CONF_URL "https://github.com/rtldg/sm_closestpos"
#define SMEXT_CONF_LOGTAG "CLOSESTPOS"
Expand Down

0 comments on commit 128f9ea

Please sign in to comment.