Beispiel #1
0
static void Thread_push_message (LIScrArgs* args)
{
	const char* name = "";
	const char* string = NULL;
	LIScrData* data;
	LIEngModel* emodel;
	LIExtThread* self;

	/* Read the name. */
	self = args->self;
	if (!liscr_args_geti_string (args, 0, &name))
		liscr_args_gets_string (args, "name", &name);

	/* Read and push the data. */
	if (liscr_args_geti_string (args, 1, &string) ||
	    liscr_args_gets_string (args, "string", &string))
	{
		if (limai_program_push_message (self->program, LIMAI_MESSAGE_QUEUE_THREAD, LIMAI_MESSAGE_TYPE_STRING, name, string))
			liscr_args_seti_bool (args, 1);
	}
	else if (liscr_args_geti_data (args, 1, LISCR_SCRIPT_MODEL, &data) ||
	         liscr_args_gets_data (args, "model", LISCR_SCRIPT_MODEL, &data))
	{
		emodel = liscr_data_get_data (data);
		if (limai_program_push_message (self->program, LIMAI_MESSAGE_QUEUE_THREAD, LIMAI_MESSAGE_TYPE_MODEL, name, emodel->model))
			liscr_args_seti_bool (args, 1);
	}
	else
	{
		if (limai_program_push_message (self->program, LIMAI_MESSAGE_QUEUE_THREAD, LIMAI_MESSAGE_TYPE_EMPTY, name, NULL))
			liscr_args_seti_bool (args, 1);
	}
}
Beispiel #2
0
static void Terrain_add_stick_corners (LIScrArgs* args)
{
	int grid_x;
	int grid_z;
	float bot[4];
	float top[4];
	int material;

	/* Get the arguments. */
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;
	if (!liscr_args_geti_float (args, 2, bot + 0) || bot[0] < 0.0f)
		return;
	if (!liscr_args_geti_float (args, 3, bot + 1) || bot[1] < 0.0f)
		return;
	if (!liscr_args_geti_float (args, 4, bot + 2) || bot[2] < 0.0f)
		return;
	if (!liscr_args_geti_float (args, 5, bot + 3) || bot[3] < 0.0f)
		return;
	if (!liscr_args_geti_float (args, 6, top + 0) || top[0] < 0.0f)
		return;
	if (!liscr_args_geti_float (args, 7, top + 1) || top[1] < 0.0f)
		return;
	if (!liscr_args_geti_float (args, 8, top + 2) || top[2] < 0.0f)
		return;
	if (!liscr_args_geti_float (args, 9, top + 3) || top[3] < 0.0f)
		return;
	if (!liscr_args_geti_int (args, 10, &material) || material < 0)
		return;

	liscr_args_seti_bool (args, liext_terrain_add_stick_corners (args->self, grid_x, grid_z,
		bot[0], bot[1], bot[2], bot[3], top[0], top[1], top[2], top[3], material, NULL, NULL));
}
Beispiel #3
0
static void Terrain_add_stick_filter_mask (LIScrArgs* args)
{
	int grid_x;
	int grid_z;
	float world_y;
	float world_h;
	int material;
	int mask;

	/* Get the arguments. */
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;
	if (!liscr_args_geti_float (args, 2, &world_y) || world_y < 0.0f)
		return;
	if (!liscr_args_geti_float (args, 3, &world_h))
		return;
	world_h = LIMAT_MAX (world_h, LIEXT_STICK_EPSILON);
	if (!liscr_args_geti_int (args, 4, &material) || material < 0)
		return;
	if (!liscr_args_geti_int (args, 5, &mask) || mask < 0)
		return;

	liscr_args_seti_bool (args, liext_terrain_add_stick (args->self, grid_x, grid_z, world_y, world_h, material,
		liext_terrain_stick_filter_mask, &mask));
}
Beispiel #4
0
static void Terrain_unload_chunk (LIScrArgs* args)
{
	int grid_x;
	int grid_z;

	/* Get the arguments. */
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;

	liscr_args_seti_bool (args, liext_terrain_unload_chunk (args->self, grid_x, grid_z));
}
Beispiel #5
0
static void Terrain_calculate_smooth_normals (LIScrArgs* args)
{
	int grid_x;
	int grid_z;

	/* Get the arguments. */
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;

	liscr_args_seti_bool (args, liext_terrain_calculate_smooth_normals (args->self, grid_x, grid_z));
}
Beispiel #6
0
static void Terrain_smoothen_column (LIScrArgs* args)
{
	int grid_x;
	int grid_z;
	float y;
	float h;

	/* Get the arguments. */
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;
	if (!liscr_args_geti_float (args, 2, &y))
		return;
	if (!liscr_args_geti_float (args, 3, &h) || h <= 0.0f)
		return;

	liscr_args_seti_bool (args, liext_terrain_smoothen_column (args->self, grid_x, grid_z, y, h));
}
Beispiel #7
0
static void Model_calculate_lod (LIScrArgs* args)
{
	int levels = 5;
	float factor = 0.3f;
	LIEngModel* model;
	LIMdlBuilder* builder;

	model = args->self;
	if (liscr_args_geti_int (args, 0, &levels))
		levels = LIMAT_MAX (1, levels);
	if (liscr_args_geti_float (args, 1, &factor))
		factor = LIMAT_CLAMP (factor, 0.0f, 1.0f);

	builder = limdl_builder_new (model->model);
	if (builder == NULL)
		return;
	limdl_builder_calculate_lod (builder, levels, factor);
	limdl_builder_finish (builder);
	limdl_builder_free (builder);
	liscr_args_seti_bool (args, 1);
}
Beispiel #8
0
static void Model_morph (LIScrArgs* args)
{
	float value = 0.5f;
	const char* shape;
	LIEngModel* model;
	LIEngModel* ref = NULL;
	LIScrData* data;

	model = args->self;
	if (!liscr_args_geti_string (args, 0, &shape) &&
	    !liscr_args_gets_string (args, "shape", &shape))
		return;
	if (!liscr_args_geti_float (args, 1, &value))
		liscr_args_gets_float (args, "value", &value);
	if (!liscr_args_geti_data (args, 2, LISCR_SCRIPT_MODEL, &data))
		liscr_args_gets_data (args, "ref", LISCR_SCRIPT_MODEL, &data);
	if (data != NULL)
		ref = liscr_data_get_data (data);

	liscr_args_seti_bool (args, limdl_model_morph (model->model,
		(ref != NULL)? ref->model : NULL, shape, value));
}
Beispiel #9
0
static void Terrain_set_chunk_data (LIScrArgs* args)
{
	int grid_x;
	int grid_z;
	LIArcPacket* packet;
	LIScrData* data;

	/* Get the arguments. */
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;

	/* Get the packet reader. */
	if (!liscr_args_geti_data (args, 2, LISCR_SCRIPT_PACKET, &data))
		return;
	packet = liscr_data_get_data (data);

	/* Read the data. */
	if (packet->reader != NULL)
		liscr_args_seti_bool (args, liext_terrain_set_chunk_data (args->self, grid_x, grid_z, packet->reader));
}
Beispiel #10
0
static void Terrain_clear_chunk_model (LIScrArgs* args)
{
	int grid_x;
	int grid_z;
	LIExtTerrain* self;
	LIExtTerrainChunk* chunk;

	/* Get the arguments. */
	self = args->self;
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;

	/* Reset the stamp. */
	chunk = liext_terrain_get_chunk (self, grid_x, grid_z);
	if (chunk == NULL)
		return;
	liext_terrain_chunk_clear_model (chunk);

	liscr_args_seti_bool (args, 1);
}
Beispiel #11
0
static void Model_load (LIScrArgs* args)
{
	int mesh = 1;
	char* file;
	const char* name;
	const char* path;
	LIMdlModel* tmpmdl;
	LIMaiProgram* program;

	program = liscr_script_get_userdata (args->script, LISCR_SCRIPT_PROGRAM);
	if (!liscr_args_geti_string (args, 0, &name) &&
	    !liscr_args_gets_string (args, "file", &name))
		return;
	if (!liscr_args_geti_bool (args, 1, &mesh))
		liscr_args_gets_bool (args, "mesh", &mesh);

	/* Find the absolute path. */
	file = lisys_string_concat (name, ".lmdl");
	if (file == NULL)
		return;
	path = lipth_paths_find_file (program->paths, file);
	if (path == NULL)
	{
		lisys_free (file);
		return;
	}
	lisys_free (file);

	/* Load the new model data. */
	tmpmdl = limdl_model_new_from_file (path, mesh);
	if (tmpmdl == NULL)
		return;

	/* Replace the old model data. */
	if (limdl_model_replace (args->self, tmpmdl))
		liscr_args_seti_bool (args, 1);
	limdl_model_free (tmpmdl);
}
Beispiel #12
0
static void Widget_get_visible (LIScrArgs* args)
{
	liscr_args_seti_bool (args, liwdg_widget_get_visible (args->self));
}
Beispiel #13
0
static void Widget_get_fullscreen (LIScrArgs* args)
{
	liscr_args_seti_bool (args, liwdg_widget_get_fullscreen (args->self));
}
Beispiel #14
0
static void Widget_get_floating (LIScrArgs* args)
{
	liscr_args_seti_bool (args, liwdg_widget_get_floating (args->self));
}
Beispiel #15
0
static void Widget_get_fixed_size (LIScrArgs* args)
{
	liscr_args_seti_bool (args, liwdg_widget_get_fixed_size (args->self));
}
Beispiel #16
0
static void Terrain_set_column (LIScrArgs* args)
{
	float y;
	float height;
	float slope[4];
	float slope_prev[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	int i;
	int j;
	int grid_x;
	int grid_z;
	int material;
	LIExtTerrainColumn* column;

	/* Get the arguments. */
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;
	if (!liscr_args_geti_table (args, 2))
		return;

	/* Get the column. */
	column = liext_terrain_get_column (args->self, grid_x, grid_z);
	if (column == NULL)
		return;

	/* Unpack the sticks from the table. */
	for (y = 0.0f, i = 0 ; 1 ; i++)
	{
		/* Get the next stick table. */
		lua_pushnumber (args->lua, i + 1);
		lua_gettable (args->lua, -2);
		if (lua_type (args->lua, -1) != LUA_TTABLE)
			break;

		/* Get the height. */
		lua_pushnumber (args->lua, 1);
		lua_gettable (args->lua, -2);
		if (lua_type (args->lua, -1) != LUA_TNUMBER)
		{
			lua_pop (args->lua, 2);
			continue;
		}
		height = lua_tonumber (args->lua, -1);
		if (height <= LIEXT_STICK_EPSILON)
		{
			lua_pop (args->lua, 2);
			continue;
		}
		lua_pop (args->lua, 1);

		/* Get the material. */
		lua_pushnumber (args->lua, 2);
		lua_gettable (args->lua, -2);
		if (lua_type (args->lua, -1) != LUA_TNUMBER)
		{
			lua_pop (args->lua, 2);
			continue;
		}
		material = lua_tointeger (args->lua, -1);
		if (material < 0)
		{
			lua_pop (args->lua, 2);
			continue;
		}
		lua_pop (args->lua, 1);

		/* Get the slope. */
		for (j = 0 ; j < 4 ; j++)
		{
			slope[j] = 0.0f;
			lua_pushnumber (args->lua, 2 + j);
			lua_gettable (args->lua, -2);
			if (lua_type (args->lua, -1) != LUA_TNUMBER)
			{
				lua_pop (args->lua, 1);
				continue;
			}
			slope[j] = lua_tonumber (args->lua, -1);
			lua_pop (args->lua, 1);
		}
		lua_pop (args->lua, 1);

		/* Add the stick. */
		liext_terrain_column_add_stick (column, y, height, slope_prev, slope, material, NULL, NULL);
		y += height;
		memcpy (slope_prev, slope, 4 * sizeof (float));
	}

	liscr_args_seti_bool (args, 1);
}