i like to use one of two methods ,even in c++ even though i dont have to , and to accomplish
both , i use char* instead of adding more code for types or whatever.

method 1: i pack all functions in to one
Code:
//in lite-c i used such a similir function
void place_entity(ENTITY* my_ent,char* my_type)
{
	if(str_cmp(my_type,"a big rock"))
	{
	}
	if(str_cmp(my_type,"a small rock"))
	{
	}
	if(str_cmp(my_type,"a tree"))
	{
	}
}
...
place_entity(me,"a big rock");
place_entity(me,"a tree");



and method 2: a dispatcher function , it dispatches other functions
Code:
//in c++ i used this for a thread dispatcher ,same concept
void thread_dispatcher(const char* task,void* task_packet,void* second_task_packet)
{
	if(m_navbuilder)
	{
		if(strcmp(task,"build the navmesh")==0)
		{
			custombuild* build_settings=(custombuild*)task_packet;
			m_navbuilder->Nav_From_Custombuild(build_settings);
		}
		if(strcmp(task,"load the navmesh")==0)
		{
			char* filename=(char*)task_packet;
			m_navbuilder->load_all_tiles((char*)filename);
		}
		if(strcmp(task,"save the navmesh")==0)
		{
			char* filename=(char*)task_packet;
			m_navbuilder->save_all_tiles((char*)filename);
		}
		if(strcmp(task,"build all tiles")==0)
		{
			m_navbuilder->build_all_tiles();
		}
		if(strcmp(task,"add single tile")==0)
		{
			VECTOR* pos=(VECTOR*)task_packet;
			m_navbuilder->build_tile(pos);
		}
		if(strcmp(task,"build tiles in bounds")==0)
		{
			VECTOR* min=(VECTOR*)task_packet;
			VECTOR* max=(VECTOR*)second_task_packet;
			m_navbuilder->build_tiles_box(min,max);
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//************************************
// BUILD A NAVMESH
//
DLLFUNC void* nav_build(custombuild* build_settings)
{
	thread_function *thread_func=new thread_function(thread_dispatcher,"build the navmesh",(custombuild*)build_settings,(int*)NULL);
	if(thread_func->is_alive()) return (thread_function *) thread_func;
	delete thread_func;
	return NULL;
}



you can easily convert to the type you need
like

Code:
void bla(char* type ,void* arg1,void* arg2,void* arg3)
{
	if(str_cmp(type,"a string"))
	{
		STRING* this_string=(STRING*)arg1;
		if(this_string)
		{
			...
		}
	}
	if(str_cmp(type,"an integer"))
	{
		int* this_integer=(int*)arg1;
		if(this_integer)
		{
			...
		}
	}
	if(str_cmp(type,"an integer with size"))
	{
		int* this_integer=(int*)arg1;
		int* this_size=(int*)arg2;
		if(this_integer && this_size>-1)
		{
			...
		}
	}
}

bla("a string",(STRING*)mystring,(int*)NULL,(int*)NULL);
//or
bla("a string",(STRING*)mystring,NULL,NULL);
bla("an integer",(int*)myinteger,......
bla("an integer with size",(int*)myinteger,(int*)my_size,NULL);



edit ah wait sid is on it

Last edited by Wjbender; 05/06/15 14:56.

Compulsive compiler