Exemple #1
0
static void Widget_add_child (LIScrArgs* args)
{
	LIScrData* data;

	/* Append rows. */
	if (liscr_args_geti_data (args, 0, LIEXT_SCRIPT_WIDGET, &data))
	{
		liwdg_widget_detach (liscr_data_get_data (data));
		liwdg_widget_add_child (args->self, liscr_data_get_data (data));
	}
}
Exemple #2
0
static void ImageMerger_blit_rect (LIScrArgs* args)
{
	LIImgAsyncMerger* self;
	LIImgImage* image;
	LIScrData* data;
	LIMatRectInt dst_rect;
	LIMatRectInt src_rect;

	/* Get arguments. */
	self = args->self;
	if (!liscr_args_geti_data (args, 0, LIEXT_SCRIPT_IMAGE, &data))
		return;
	image = liscr_data_get_data (data);
	if (!liscr_args_geti_int (args, 1, &dst_rect.x))
		return;
	if (!liscr_args_geti_int (args, 2, &dst_rect.y))
		return;
	if (!liscr_args_geti_int (args, 3, &dst_rect.width))
		return;
	if (!liscr_args_geti_int (args, 4, &dst_rect.height))
		return;
	if (!liscr_args_geti_int (args, 5, &src_rect.x))
		return;
	if (!liscr_args_geti_int (args, 6, &src_rect.y))
		return;
	src_rect.width = dst_rect.width;
	src_rect.height = dst_rect.height;

	/* Add the task. */
	liimg_async_merger_blit (self, image, &dst_rect, &src_rect);
}
Exemple #3
0
static void ImageMerger_blit_hsv_add_weightv (LIScrArgs* args)
{
	float val_range;
	LIImgAsyncMerger* self;
	LIImgColorHSV hsv;
	LIImgImage* image;
	LIScrData* data;

	/* Get arguments. */
	self = args->self;
	if (!liscr_args_geti_data (args, 0, LIEXT_SCRIPT_IMAGE, &data))
		return;
	if (!liscr_args_geti_float (args, 1, &hsv.h))
		hsv.h = 0.0f;
	if (!liscr_args_geti_float (args, 2, &hsv.s))
		hsv.s = 0.0f;
	if (!liscr_args_geti_float (args, 3, &hsv.v))
		hsv.v = 0.0f;
	if (!liscr_args_geti_float (args, 4, &val_range))
		val_range = 0.2f;
	image = liscr_data_get_data (data);

	/* Add the task. */
	liimg_async_merger_blit_hsv_add_weightv (self, image, NULL, NULL, &hsv, val_range);
}
Exemple #4
0
static void Animation_copy (LIScrArgs* args)
{
	LIMdlAnimation* self;
	LIMdlAnimation* copy;
	LIScrData* data;

	/* Get arguments. */
	if (!liscr_args_geti_data (args, 0, LIEXT_SCRIPT_ANIMATION, &data))
		return;
	copy = liscr_data_get_data (data);

	/* Allocate the animation. */
	self = limdl_animation_new_copy (copy);
	if (self == NULL)
		return;

	/* Allocate the userdata. */
	data = liscr_data_new (args->script, args->lua, self, LIEXT_SCRIPT_ANIMATION, limdl_animation_free);
	if (data == NULL)
	{
		limdl_animation_free (self);
		return;
	}
	liscr_args_seti_stack (args);
}
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);
	}
}
Exemple #6
0
static void Heightmap_new (LIScrArgs* args)
{
	int i;
	int size;
	float spacing;
	float scaling;
	LIExtHeightmap* heightmap;
	LIExtHeightmapModule* module;
	LIImgImage* image;
	LIMatVector position;
	LIScrData* data;

	/* Get arguments. */
	module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_HEIGHTMAP);
	if (!liscr_args_geti_vector (args, 0, &position))
		position = limat_vector_init (0.0f, 0.0f, 0.0f);
	if (!liscr_args_geti_int (args, 1, &size))
		size = 33;
	else if (size < 0)
		size = 0;
	if (!liscr_args_geti_float (args, 2, &spacing))
		spacing = 1.0f;
	else if (spacing <= 0.0f)
		spacing = 1.0f;
	if (!liscr_args_geti_float (args, 3, &scaling))
		scaling = 1.0f;
	else if (scaling <= 0.0f)
		scaling = 1.0f;
	if (liscr_args_geti_data (args, 4, LIEXT_SCRIPT_IMAGE, &data))
		image = liscr_data_get_data (data);
	else
		image = NULL;

	/* Ensure that the size is valid. */
	for (i = 32 ; i < 65536 ; i *= 2)
	{
		if (size == i + 1)
			break;
	}
	if (size != i + 1)
	{
		lisys_error_set (EINVAL, "invalid heightmap size");
		lisys_error_report ();
		return;
	}

	/* Allocate the heightmap. */
	heightmap = liext_heightmap_new (module, image, &position, size, spacing, scaling);
	if (heightmap == NULL)
		return;

	/* Allocate the userdata. */
	data = liscr_data_new (args->script, args->lua, heightmap, LIEXT_SCRIPT_HEIGHTMAP, liext_heightmap_free);
	if (data == NULL)
	{
		liext_heightmap_free (heightmap);
		return;
	}
	liscr_args_seti_stack (args);
}
Exemple #7
0
static void Widget_append_row (LIScrArgs* args)
{
	int i;
	int w;
	int h;
	LIScrData* data;

	/* Append row. */
	liwdg_widget_get_size (args->self, &w, &h);
	if (!liwdg_widget_append_row (args->self))
		return;

	/* Append columns. */
	for (i = 0 ; i < w && liscr_args_geti_data (args, i, LIEXT_SCRIPT_WIDGET, &data) ; i++)
	{
		liwdg_widget_detach (liscr_data_get_data (data));
		liwdg_widget_set_child (args->self, i, h, liscr_data_get_data (data));
	}
}
Exemple #8
0
static void Widget_canvas_image (LIScrArgs* args)
{
	float color[4];
	int dest_clip[4];
	int dest_position[2];
	int dest_size[2];
	int source_position[2];
	int source_tiling[6];
	float* color_ptr = NULL;
	int* dest_position_ptr = NULL;
	int* dest_size_ptr = NULL;
	int* dest_clip_ptr = NULL;
	int* source_position_ptr = NULL;
	int* source_tiling_ptr = NULL;
	const char* source_image;
	float rotation = 0.0f;
	LIScrData* vector = NULL;
	LIMatVector* rotation_center_ptr = NULL;
	LIWdgWidget* widget;

	/* Process arguments. */
	widget = args->self;
	if (!liscr_args_gets_string (args, "source_image", &source_image))
		return;
	if (liscr_args_gets_floatv (args, "color", 4, color) == 4)
	{
		color_ptr = color;
		color[0] = LIMAT_CLAMP (color[0], 0.0f, 1.0f);
		color[1] = LIMAT_CLAMP (color[1], 0.0f, 1.0f);
		color[2] = LIMAT_CLAMP (color[2], 0.0f, 1.0f);
		color[3] = LIMAT_CLAMP (color[3], 0.0f, 1.0f);
	}
	if (liscr_args_gets_intv (args, "dest_clip", 4, dest_clip) == 4)
		dest_clip_ptr = dest_clip;
	if (liscr_args_gets_intv (args, "dest_position", 2, dest_position) == 2)
		dest_position_ptr = dest_position;
	if (liscr_args_gets_intv (args, "dest_size", 2, dest_size) == 2)
		dest_size_ptr = dest_size;
	if (liscr_args_gets_intv (args, "source_position", 2, source_position) == 2)
		source_position_ptr = source_position;
	if (liscr_args_gets_intv (args, "source_tiling", 6, source_tiling) == 6)
		source_tiling_ptr = source_tiling;
	liscr_args_gets_float (args, "rotation", &rotation);
	if (liscr_args_gets_data (args, "rotation_center", LISCR_SCRIPT_VECTOR, &vector))
		rotation_center_ptr = liscr_data_get_data (vector);

	/* Create the canvas element. */
	liwdg_widget_canvas_insert_image (widget, source_image, color_ptr, dest_clip_ptr, dest_position_ptr,
		dest_size_ptr, source_position_ptr, source_tiling_ptr, rotation, rotation_center_ptr);
}
Exemple #9
0
static void ImageMerger_blit (LIScrArgs* args)
{
	LIImgAsyncMerger* self;
	LIImgImage* image;
	LIScrData* data;

	/* Get arguments. */
	self = args->self;
	if (!liscr_args_geti_data (args, 0, LIEXT_SCRIPT_IMAGE, &data))
		return;
	image = liscr_data_get_data (data);

	/* Add the task. */
	liimg_async_merger_blit (self, image, NULL, NULL);
}
static void Model_merge (LIScrArgs* args)
{
	LIScrData* data;
	LIEngModel* model1;
	LIEngModel* model2;

	if (liscr_args_geti_data (args, 0, LISCR_SCRIPT_MODEL, &data) ||
	    liscr_args_gets_data (args, "model", LISCR_SCRIPT_MODEL, &data))
	{
		model1 = args->self;
		model2 = liscr_data_get_data (data);
		if (!limdl_model_merge (model1->model, model2->model))
			lisys_error_report ();
	}
}
Exemple #11
0
static void Widget_canvas_text (LIScrArgs* args)
{
	int dest_clip[4];
	int dest_position[2];
	int dest_size[2];
	float text_align[2];
	float text_color[6];
	int* dest_position_ptr = NULL;
	int* dest_size_ptr = NULL;
	int* dest_clip_ptr = NULL;
	float* text_align_ptr = NULL;
	float* text_color_ptr = NULL;
	const char* text;
	const char* text_font = "default";
	float rotation = 0.0f;
	LIScrData* vector = NULL;
	LIMatVector* rotation_center_ptr = NULL;
	LIWdgWidget* widget;

	/* Process arguments. */
	widget = args->self;
	if (!liscr_args_gets_string (args, "text", &text))
		return;
	liscr_args_gets_string (args, "text_font", &text_font);
	if (liscr_args_gets_intv (args, "dest_clip", 4, dest_clip) == 4)
		dest_clip_ptr = dest_clip;
	if (liscr_args_gets_intv (args, "dest_position", 2, dest_position) == 2)
		dest_position_ptr = dest_position;
	if (liscr_args_gets_intv (args, "dest_size", 2, dest_size) == 2)
		dest_size_ptr = dest_size;
	if (liscr_args_gets_floatv (args, "text_alignment", 2, text_align) == 2)
		text_align_ptr = text_align;
	if (liscr_args_gets_floatv (args, "text_color", 4, text_color) == 4)
	{
		text_color_ptr = text_color;
		text_color[0] = LIMAT_CLAMP (text_color[0], 0.0f, 1.0f);
		text_color[1] = LIMAT_CLAMP (text_color[1], 0.0f, 1.0f);
		text_color[2] = LIMAT_CLAMP (text_color[2], 0.0f, 1.0f);
		text_color[3] = LIMAT_CLAMP (text_color[3], 0.0f, 1.0f);
	}
	liscr_args_gets_float (args, "rotation", &rotation);
	if (liscr_args_gets_data (args, "rotation_center", LISCR_SCRIPT_VECTOR, &vector))
		rotation_center_ptr = liscr_data_get_data (vector);

	/* Create the canvas element. */
	liwdg_widget_canvas_insert_text (widget, text_font, text, dest_clip_ptr, dest_position_ptr,
		dest_size_ptr, text_align_ptr, text_color_ptr, rotation, rotation_center_ptr);
}
Exemple #12
0
static void ImageMerger_blit_rect_hsv_add_weightv (LIScrArgs* args)
{
	float val_range;
	LIImgAsyncMerger* self;
	LIImgColorHSV hsv;
	LIImgImage* image;
	LIScrData* data;
	LIMatRectInt dst_rect;
	LIMatRectInt src_rect;

	/* Get arguments. */
	self = args->self;
	if (!liscr_args_geti_data (args, 0, LIEXT_SCRIPT_IMAGE, &data))
		return;
	if (!liscr_args_geti_int (args, 1, &dst_rect.x))
		return;
	if (!liscr_args_geti_int (args, 2, &dst_rect.y))
		return;
	if (!liscr_args_geti_int (args, 3, &dst_rect.width))
		return;
	if (!liscr_args_geti_int (args, 4, &dst_rect.height))
		return;
	if (!liscr_args_geti_int (args, 5, &src_rect.x))
		return;
	if (!liscr_args_geti_int (args, 6, &src_rect.y))
		return;
	src_rect.width = dst_rect.width;
	src_rect.height = dst_rect.height;
	if (!liscr_args_geti_float (args, 7, &hsv.h))
		hsv.h = 0.0f;
	if (!liscr_args_geti_float (args, 8, &hsv.s))
		hsv.s = 0.0f;
	if (!liscr_args_geti_float (args, 9, &hsv.v))
		hsv.v = 0.0f;
	if (!liscr_args_geti_float (args, 10, &val_range))
		val_range = 0.2f;
	image = liscr_data_get_data (data);

	/* Add the task. */
	liimg_async_merger_blit_hsv_add_weightv (self, image, &dst_rect, &src_rect, &hsv, val_range);
}
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));
}
Exemple #14
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));
}
static void Sound_effect (LIScrArgs* args)
{
#ifndef LI_DISABLE_SOUND
	int tmp;
	int flags = 0;
	float pitch;
	float volume;
	const char* effect;
	LIEngObject* object;
	LIExtModule* module;
	LIMatVector velocity;
	LIScrData* data;
	LISndSource* source;

	if (liscr_args_gets_string (args, "effect", &effect) &&
	    liscr_args_gets_data (args, "object", LISCR_SCRIPT_OBJECT, &data))
	{
		if (liscr_args_gets_bool (args, "positional", &tmp) && !tmp)
			flags |= LIEXT_SOUND_FLAG_NONPOSITIONAL;
		if (liscr_args_gets_bool (args, "repeating", &tmp) && tmp)
			flags |= LIEXT_SOUND_FLAG_REPEAT;
		object = liscr_data_get_data (data);
		module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_SOUND);
		source = liext_sound_set_effect (module, object->id, effect, flags);
		if (source != NULL)
		{
			if (liscr_args_gets_float (args, "pitch", &pitch))
				lisnd_source_set_pitch (source, pitch);
			if (liscr_args_gets_float (args, "volume", &volume))
				lisnd_source_set_volume (source, volume);
			if (liscr_args_gets_vector (args, "velocity", &velocity))
				lisnd_source_set_velocity (source, &velocity);
		}
	}
#endif
}
Exemple #16
0
static void Database_query (LIScrArgs* args)
{
	int i;
	int col;
	int row;
	int ret;
	int size;
	const char* query;
	const char* str;
	sqlite3* self;
	LIArcPacket* packet;
	LIScrData* data;
	sqlite3_stmt* statement;

	self = args->self;
	if (!liscr_args_geti_string (args, 0, &query) &&
	    !liscr_args_gets_string (args, "query", &query))
		return;

	/* Create a statement. */
	if (sqlite3_prepare_v2 (self, query, -1, &statement, NULL) != SQLITE_OK)
	{
		lisys_error_set (EINVAL, "SQL prepare: %s", sqlite3_errmsg (self));
		lisys_error_report ();
		return;
	}

	/* Bind variables. */
	if (liscr_args_geti_table (args, 1) || liscr_args_gets_table (args, "bind"))
	{
		for (i = 1 ; i < sqlite3_bind_parameter_count (statement) + 1 ; i++)
		{
			/* We got a table that has the bound variables in fields matching
			   the indices of the bound variables. We can simply loop through
			   the table and use the binding index as the key. */
			lua_pushnumber (args->lua, i);
			lua_gettable (args->lua, -2);
			switch (lua_type (args->lua, -1))
			{
				/* Bind numbers as doubles. */
				case LUA_TNUMBER:
					if (sqlite3_bind_double (statement, i, lua_tonumber (args->lua, -1)) != SQLITE_OK)
					{
						lisys_error_set (EINVAL, "SQL bind: %s", sqlite3_errmsg (self));
						lisys_error_report ();
						sqlite3_finalize (statement);
						return;
					}
					break;

				/* Bind strings as text. */
				case LUA_TSTRING:
					if (sqlite3_bind_text (statement, i, lua_tostring (args->lua, -1), -1, SQLITE_TRANSIENT) != SQLITE_OK)
					{
						lisys_error_set (EINVAL, "SQL bind: %s", sqlite3_errmsg (self));
						lisys_error_report ();
						sqlite3_finalize (statement);
						return;
					}
					break;

				/* Bind packets as blobs. */
				case LUA_TUSERDATA:
					data = liscr_isdata (args->lua, -1, LISCR_SCRIPT_PACKET);
					if (data == NULL)
						break;
					packet = liscr_data_get_data (data);
					if (packet->writer != NULL)
					{
						if (sqlite3_bind_blob (statement, i, packet->writer->memory.buffer,
							packet->writer->memory.length, SQLITE_TRANSIENT) != SQLITE_OK)
						{
							lisys_error_set (EINVAL, "SQL bind: %s", sqlite3_errmsg (self));
							lisys_error_report ();
							sqlite3_finalize (statement);
							return;
						}
					}
					else
					{
						if (sqlite3_bind_blob (statement, i, packet->reader->buffer,
							packet->reader->length, SQLITE_TRANSIENT) != SQLITE_OK)
						{
							lisys_error_set (EINVAL, "SQL bind: %s", sqlite3_errmsg (self));
							lisys_error_report ();
							sqlite3_finalize (statement);
							return;
						}
					}
					break;

				/* Bind any other values as NULL. */
				default:
					if (sqlite3_bind_null (statement, i) != SQLITE_OK)
					{
						lisys_error_set (EINVAL, "SQL bind: %s", sqlite3_errmsg (self));
						lisys_error_report ();
						sqlite3_finalize (statement);
						return;
					}
					break;
			}
			lua_pop (args->lua, 1);
		}
		lua_pop (args->lua, 1);
	}

	/* Execute the statement and process results. */
	for (row = 0, ret = sqlite3_step (statement) ; ret != SQLITE_DONE ; ret = sqlite3_step (statement), row++)
	{
		/* Check for errors. */
		if (ret != SQLITE_ROW)
		{
			lisys_error_set (EINVAL, "SQL step: %s", sqlite3_errmsg (self));
			lisys_error_report ();
			sqlite3_finalize (statement);
			return;
		}
		if (!row)
			liscr_args_set_output (args, LISCR_ARGS_OUTPUT_TABLE_FORCE);

		/* Create a row table. */
		lua_newtable (args->lua);

		/* Push the columns to the table. */
		for (col = 0 ; col < sqlite3_column_count (statement) ; col++)
		{
			switch (sqlite3_column_type (statement, col))
			{
				case SQLITE_INTEGER:
					lua_pushnumber (args->lua, col + 1);
					lua_pushnumber (args->lua, sqlite3_column_int (statement, col));
					lua_settable (args->lua, -3);
					break;
				case SQLITE_FLOAT:
					lua_pushnumber (args->lua, col + 1);
					lua_pushnumber (args->lua, sqlite3_column_double (statement, col));
					lua_settable (args->lua, -3);
					break;
				case SQLITE_TEXT:
					str = (const char*) sqlite3_column_text (statement, col);
					size = sqlite3_column_bytes (statement, col);
					lua_pushnumber (args->lua, col + 1);
					if (size > 0 && str != NULL)
						lua_pushstring (args->lua, str);
					else
						lua_pushstring (args->lua, str);
					lua_settable (args->lua, -3);
					break;
				case SQLITE_BLOB:
					str = sqlite3_column_blob (statement, col);
					size = sqlite3_column_bytes (statement, col);
					packet = liarc_packet_new_readable (str, size);
					if (packet != NULL)
					{
						lua_pushnumber (args->lua, col + 1);
						data = liscr_data_new (args->script, args->lua, packet, LISCR_SCRIPT_PACKET, liarc_packet_free);
						if (data != NULL)
							lua_settable (args->lua, -3);
						else
						{
							lua_pop (args->lua, 1);
							liarc_packet_free (packet);
						}
					}
					break;
				case SQLITE_NULL:
					break;
				default:
					lisys_assert (0 && "invalid column type");
					break;
			}
		}

		/* Add the row to the return values. */
		liscr_args_seti_stack (args);
	}
	if (!row)
		liscr_args_set_output (args, LISCR_ARGS_OUTPUT_TABLE_FORCE);
	sqlite3_finalize (statement);
}