Example #1
0
static void Widget_popup (LIScrArgs* args)
{
	const char* dir;
	LIWdgRect rect;
	LIWdgSize screen;
	LIWdgSize size;
	LIWdgWidget* widget;

	widget = args->self;
	liwdg_widget_detach (widget);

	/* Calculate position. */
	liwdg_manager_get_size (widget->manager, &screen.width, &screen.height);
	liwdg_widget_get_request (widget, &size);
	rect.x = (screen.width - size.width) / 2;
	rect.y = (screen.height - size.height) / 2;
	rect.width = size.width;
	rect.height = size.height;
	liscr_args_gets_int (args, "x", &rect.x);
	liscr_args_gets_int (args, "y", &rect.y);
	liscr_args_gets_int (args, "width", &rect.width);
	liscr_args_gets_int (args, "height", &rect.height);
	if (liscr_args_gets_string (args, "dir", &dir))
	{
		if (!strcmp (dir, "left")) rect.x -= size.width;
		else if (!strcmp (dir, "right")) rect.x += rect.width;
		else if (!strcmp (dir, "up")) rect.y -= size.height;
		else if (!strcmp (dir, "down")) rect.y += rect.height;
	}

	/* Popup the widget. */
	liwdg_widget_set_visible (widget, 1);
	liwdg_manager_insert_window (widget->manager, widget);
	liwdg_widget_set_allocation (widget, rect.x, rect.y, rect.width, rect.height);
}
Example #2
0
static void Widget_set_request (LIScrArgs* args)
{
	int internal = 0;
	int paddings[4];
	const char* text;
	const char* font_name;
	LIMatVector vector;
	LIWdgSize size = { -1, -1 };
	LIWdgSize size_tmp;
	LIWdgWidget* widget;

	widget = args->self;
	liscr_args_gets_bool (args, "internal", &internal);
	if (liscr_args_geti_vector (args, 0, &vector))
	{
		size.width = (int) vector.x;
		size.height = (int) vector.y;
	}
	else
	{
		if (!liscr_args_geti_int (args, 0, &size.width))
			liscr_args_gets_int (args, "width", &size.width);
		if (!liscr_args_geti_int (args, 1, &size.width))
			liscr_args_gets_int (args, "height", &size.height);
	}

	/* Calculate from text if given. */
	if (liscr_args_gets_string (args, "font", &font_name) &&
	    liscr_args_gets_string (args, "text", &text))
	{
		if (liren_render_measure_text (widget->manager->render, font_name, text, size.width, &size_tmp.width, &size_tmp.height))
		{
			if (size.width == -1)
				size.width = size_tmp.width;
			if (size.height == -1)
				size.height = size_tmp.height;
		}
	}

	/* Add paddings if given. */
	if (liscr_args_gets_intv (args, "paddings", 4, paddings) == 4)
	{
		size.width += paddings[1] + paddings[2];
		size.height += paddings[0] + paddings[3];
	}

	/* Set the request. */
	if (internal)
		liwdg_widget_set_request (args->self, 1, size.width, size.height);
	else
		liwdg_widget_set_request (args->self, 2, size.width, size.height);
}
Example #3
0
static void Voxel_fill_region (LIScrArgs* args)
{
	int i;
	int count;
	int type = 0;
	LIExtModule* module;
	LIMatVector pos;
	LIMatVector size;
	LIVoxVoxel tile;
	LIVoxVoxel* tiles;

	/* Handle arguments. */
	if (!liscr_args_gets_vector (args, "point", &pos) ||
	    !liscr_args_gets_vector (args, "size", &size))
		return;
	if (size.x < 1.0f || size.y < 1.0f || size.z < 1.0f)
		return;
	liscr_args_gets_int (args, "tile", &type);
	livox_voxel_init (&tile, type);

	/* Allocate tiles. */
	count = (int) size.x * (int) size.y * (int) size.z;
	tiles = lisys_calloc (count, sizeof (LIVoxVoxel));
	if (tiles == NULL)
		return;
	for (i = 0 ; i < count ; i++)
		tiles[i] = tile;

	/* Paste tiles to the map. */
	module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_VOXEL);
	livox_manager_paste_voxels (module->voxels,
		(int) pos.x, (int) pos.y, (int) pos.z,
		(int) size.x, (int) size.y, (int) size.z, tiles);
	lisys_free (tiles);
}
Example #4
0
static void Lobby_upload_server_info (LIScrArgs* args)
{
#ifdef HAVE_CURL
	int port = 0;
	int players = 0;
	char* url;
	char* decoded;
	const char* desc = NULL;
	const char* master = NULL;
	const char* name = NULL;
	char error_buffer[CURL_ERROR_SIZE];
	CURL* curl;

	/* Get arguments. */
	if (!liscr_args_gets_string (args, "desc", &desc) ||
	    !liscr_args_gets_string (args, "master", &master) ||
	    !liscr_args_gets_string (args, "name", &name) ||
	    !liscr_args_gets_int (args, "players", &players) ||
	    !liscr_args_gets_int (args, "port", &port))
		return;
	players = LIMAT_CLAMP (players, 0, 256);
	port = LIMAT_CLAMP (port, 1, 65535);

	/* Format the script URL. */
	url = lisys_string_concat (master, "/lossrvapi.php");
	if (url == NULL)
		return;

	/* POST to the master server. */
	curl = curl_easy_init();
	if (curl != NULL)
	{
		decoded = lisys_string_format ("u=%d|%d|%s|%s", port, players, name, desc);
		curl_easy_setopt (curl, CURLOPT_URL, url);
		curl_easy_setopt (curl, CURLOPT_POSTFIELDS, decoded);
		curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, error_buffer);
		if (curl_easy_perform (curl))
		{
			lisys_error_set (EINVAL, "lobby: %s", error_buffer);
			lisys_error_report ();
		}
		curl_easy_cleanup (curl);
		lisys_free (decoded);
	}
	lisys_free (url);
#endif
}
Example #5
0
static void Widgets_add_font_style (LIScrArgs* args)
{
	int size = 16;
	const char* file;
	const char* name;
	LIExtModule* module;

	/* Arguments. */
	if (!liscr_args_geti_string (args, 0, &name) &&
	    !liscr_args_gets_string (args, "name", &name))
		return;
	if (!liscr_args_geti_string (args, 1, &file) &&
	    !liscr_args_gets_string (args, "file", &file))
		return;
	if (!liscr_args_geti_int (args, 2, &size))
	    liscr_args_gets_int (args, "size", &size);

	/* Load the font. */
	module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_WIDGETS);
	if (!liwdg_styles_load_font (module->widgets->styles, name, file, size))
		lisys_error_report ();
}
Example #6
0
static void Animation_set_transform (LIScrArgs* args)
{
	int frame = 0;
	float scale = 1.0f;
	const char* node = NULL;
	LIMatTransform transform;
	LIMdlAnimation* self;

	self = args->self;

	/* Get arguments. */
	if (liscr_args_gets_int (args, "frame", &frame))
	{
		frame--;
		if (frame < 0)
			return;
	}
	if (!liscr_args_gets_string (args, "node", &node))
		return;
	transform = limat_transform_identity ();
	liscr_args_gets_quaternion (args, "rotation", &transform.rotation);
	liscr_args_gets_vector (args, "position", &transform.position);
	liscr_args_gets_float (args, "scale", &scale);
	transform.rotation = limat_quaternion_normalize (transform.rotation);

	/* Create the channel and frame. */
	if (!limdl_animation_insert_channel (self, node))
		return;
	if (limdl_animation_get_length (self) <= frame)
	{
		if (!limdl_animation_set_length (self, frame + 1))
			return;
	}

	/* Set the node transformation of the frame. */
	limdl_animation_set_transform (self, node, frame, scale, &transform);
}
Example #7
0
static void Model_add_triangles (LIScrArgs* args)
{
	int i;
	int group = 1;
	int vertices_cap = 0;
	int vertices_num = 0;
	float* attrs[8];
	LIMdlIndex* indices = NULL;
	LIMatVector zero = { 0.0f, 0.0f, 0.0f };
	LIMdlBuilder* builder;
	LIMdlVertex* tmp;
	LIMdlVertex* vertex;
	LIMdlVertex* vertices = NULL;
	LIEngModel* model;

	/* Get the edited material group. */
	model = args->self;
	liscr_args_gets_int (args, "material", &group);
	if (group < 1 || group > model->model->materials.count)
		return;

	/* Read vertex data. */
	/* Vertices are stored to a sequential table. Each vertex is presented as
	   a sequential child table whose fields are presented in the order of
	   {x,y,z,nx,ny,nz,u,v}. */
	if (liscr_args_gets_table (args, "vertices"))
	{
		for (vertices_num = 0 ; ; vertices_num++)
		{
			/* Get the vertex table. */
			lua_pushnumber (args->lua, vertices_num + 1);
			lua_gettable (args->lua, -2);
			if (lua_type (args->lua, -1) != LUA_TTABLE)
			{
				lua_pop (args->lua, 1);
				break;
			}

			/* Allocate space for the vertex. */
			if (vertices_cap < vertices_num + 1)
			{
				if (!vertices_cap)
					vertices_cap = 32;
				else
					vertices_cap <<= 1;
				tmp = realloc (vertices, vertices_cap * sizeof (LIMdlVertex));
				if (tmp == NULL)
				{
					lisys_free (vertices);
					return;
				}
				vertices = tmp;
			}
			vertex = vertices + vertices_num;
			limdl_vertex_init (vertex, &zero, &zero, 0.0f, 0.0f);

			/* Read vertex attributes. */
			attrs[0] = &vertex->coord.x;
			attrs[1] = &vertex->coord.y;
			attrs[2] = &vertex->coord.z;
			attrs[3] = &vertex->normal.x;
			attrs[4] = &vertex->normal.y;
			attrs[5] = &vertex->normal.z;
			attrs[6] = vertex->texcoord + 0;
			attrs[7] = vertex->texcoord + 1;
			for (i = 0 ; i < 8 ; i++)
			{
				lua_pushnumber (args->lua, i + 1);
				lua_gettable (args->lua, -2);
				if (lua_type (args->lua, -1) == LUA_TNUMBER)
					*(attrs[i]) = lua_tonumber (args->lua, -1);
				else
					*(attrs[i]) = 0.0f;
				lua_pop (args->lua, 1);
			}
			lua_pop (args->lua, 1);
		}
		lua_pop (args->lua, 1);
	}

	/* Validate the vertex count. */
	if (!vertices_num)
		return;
	vertices_num -= vertices_num % 3;
	if (!vertices_num)
	{
		lisys_free (vertices);
		return;
	}

	/* Create the index buffer. */
	indices = calloc (vertices_num, sizeof (LIMdlIndex));
	if (indices == NULL)
	{
		lisys_free (vertices);
		return;
	}
	for (i = 0 ; i < vertices_num ; i++)
		indices[i] = model->model->vertices.count + i;

	/* Create a model builder. */
	builder = limdl_builder_new (model->model);
	if (builder == NULL)
	{
		lisys_free (vertices);
		lisys_free (indices);
		return;
	}

	/* Insert the vertices and indices. */
	limdl_builder_insert_vertices (builder, vertices, vertices_num, NULL);
	limdl_builder_insert_indices (builder, 0, group - 1, indices, vertices_num, 0);
	limdl_builder_finish (builder);

	/* Cleanup. */
	limdl_builder_free (builder);
	lisys_free (vertices);
	lisys_free (indices);
}
Example #8
0
static void Voxel_copy_region (LIScrArgs* args)
{
	int i;
	int length;
	int sector;
	int offset[3];
	LIArcPacket* packet;
	LIScrData* data;
	LIExtModule* module;
	LIMatVector point;
	LIMatVector size;
	LIVoxVoxel* result;

	/* Get region offset and size. */
	module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_VOXEL);
	if (liscr_args_gets_int (args, "sector", &sector))
	{
		lialg_sectors_index_to_offset (module->program->sectors, sector,
			offset + 0, offset + 1, offset + 2);
		point = limat_vector_init (offset[0], offset[1], offset[2]);
		point = limat_vector_multiply (point, module->voxels->tiles_per_line);
		size.x = size.y = size.z = module->voxels->tiles_per_line;
		length = module->voxels->tiles_per_sector;
	}
	else if (liscr_args_gets_vector (args, "point", &point) &&
	         liscr_args_gets_vector (args, "size", &size))
	{
		if (point.x < 0.0f || point.y < 0.0f || point.z < 0.0f ||
		    size.x < 1.0f || size.y < 1.0f || size.z < 1.0f)
			return;
		length = (int) size.x * (int) size.y * (int) size.z;
	}
	else
		return;

	/* Read voxel data. */
	result = lisys_calloc (length, sizeof (LIVoxVoxel));
	if (result == NULL)
		return;
	livox_manager_copy_voxels (module->voxels,
		(int) point.x, (int) point.y, (int) point.z,
		(int) size.x, (int) size.y, (int) size.z, result);

	/* Create a packet writer. */
	packet = liarc_packet_new_writable (0);
	if (packet == NULL)
	{
		lisys_free (result);
		return;
	}

	/* Write the dimensions. */
	if (!liarc_writer_append_uint32 (packet->writer, (int) size.x) ||
		!liarc_writer_append_uint32 (packet->writer, (int) size.y) ||
		!liarc_writer_append_uint32 (packet->writer, (int) size.z))
	{
		lisys_free (result);
		return;
	}

	/* Write voxel data. */
	for (i = 0 ; i < length ; i++)
	{
		if (!livox_voxel_write (result + i, packet->writer))
		{
			lisys_free (result);
			return;
		}
	}
	lisys_free (result);

	/* Return data. */
	data = liscr_data_new (args->script, args->lua, packet, LISCR_SCRIPT_PACKET, liarc_packet_free);
	if (data == NULL)
	{
		liarc_packet_free (packet);
		return;
	}
	liscr_args_seti_stack (args);
}