Finding an object by name
Hi all,
I'm trying to think of an efficient method in straight C that basically achieves this:
As you can see I have to go through an entire loop to 'find' an object.
Though ok performance wise now, will become an issue later :-)
I *guess* i really want a method where I don't iterate over all objects each frame, and also be able to deal with 'killed' objects (i.e. name removal).
Any suggestions?;
Cheers
I'm trying to think of an efficient method in straight C that basically achieves this:
Code:
int find_object(lua_State *L)
{
const char *find=lua_tostring(L,1);
OBJECT_DEF *obj;
obj = objects_head;
while( obj != NULL)
{
if (!strcmp(obj->name,find))
{
lua_pushlightuserdata(L, obj);
return 1;
}
obj=obj->next;
}
lua_pushnumber(L,0);
return 0;
}As you can see I have to go through an entire loop to 'find' an object.
Though ok performance wise now, will become an issue later :-)
I *guess* i really want a method where I don't iterate over all objects each frame, and also be able to deal with 'killed' objects (i.e. name removal).
Any suggestions?;
Cheers
Since you're using lua anyway, use a lua table as a hashtable.
Won't that be slow though? (how do I do that anyway???).
I assumed some method where I call a 'c' func would be better.
But out of interest how would I achieve this in Lua?
thanks
I assumed some method where I call a 'c' func would be better.
But out of interest how would I achieve this in Lua?
thanks
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| finding a training center - Heeeelp | Glauter | 1 | 2,491 |
Dec 26, 2011 12:30 PM Last Post: zenkimoto |
|
| Finding the closest point to (x1,y1) in array of [x1,y1,z1,x2... | mikey | 17 | 7,989 |
Aug 28, 2009 08:12 AM Last Post: mikey |
|
| Finding Outer Vertices of Shapes | Nick | 18 | 7,650 |
Nov 27, 2006 07:01 AM Last Post: Nick |
|
| Path Finding | bwalters | 22 | 9,349 |
Mar 27, 2006 11:36 AM Last Post: Blacktiger |
|
| Finding 2D Perpendicular Vector | Nick | 4 | 12,419 |
Oct 30, 2005 08:24 PM Last Post: Nick |
|

