示例#1
0
/**
 * \brief Frees the paths object.
 *
 * \param self Paths object.
 */
void lipth_paths_free (
	LIPthPaths* self)
{
	LIAlgList* ptr;
	LIAlgStrdicIter iter;

	/* Free path names. */
	if (self->paths != NULL)
	{
		for (ptr = self->paths ; ptr != NULL ; ptr = ptr->next)
			lisys_free (ptr->data);
		lialg_list_free (self->paths);
	}

	/* Free file names. */
	if (self->files != NULL)
	{
		LIALG_STRDIC_FOREACH (iter, self->files)
			lisys_free (iter.value);
		lialg_strdic_free (self->files);
	}

	lisys_free (self->global_exts);
	lisys_free (self->global_data);
	lisys_free (self->module_name);
	lisys_free (self->module_config);
	lisys_free (self->module_data);
	lisys_free (self->module_data_save);
	lisys_free (self->root);
	lisys_free (self);
}
示例#2
0
/**
 * \brief Finds the data of a config file by a path relative to the data directory root.
 * \param self Paths.
 * \param path Path relative to the data directory root.
 * \param config Nonzero for a config file, zero for a data file.
 * \return Absolute path or NULL.
 */
char* lipth_paths_find_path (
	const LIPthPaths* self,
	const char*       path,
	int               config)
{
	char* path1;

	/* Try the config/save path. */
	if (config)
		path1 = lisys_path_concat (self->module_config, path, NULL);
	else
		path1 = lisys_path_concat (self->module_data_save, path, NULL);
	if (path1 == NULL)
		return NULL;
	if (lisys_filesystem_access (path1, LISYS_ACCESS_READ))
		return path1;
	lisys_free (path1);

	/* Try the data path. */
	path1 = lisys_path_concat (self->module_data, path, NULL);
	if (lisys_filesystem_access (path1, LISYS_ACCESS_READ))
		   return path1;
	lisys_free (path1);

	return NULL;
}
示例#3
0
/**
 * \brief Adds a data directory lookup path.
 * \param self Paths.
 * \param path Module root relative path.
 */
int lipth_paths_add_path (
	LIPthPaths* self,
	const char* path)
{
	int ret = 1;
	char* path1;

	/* Add the module directory. */
	path1 = lisys_path_concat (self->module_data, path, NULL);
	if (path1 != NULL)
	{
		if (!lipth_paths_add_path_abs (self, path1))
			ret = 0;
		lisys_free (path1);
	}
	else
		ret = 0;

	/* Add the override directory. */
	path1 = lisys_path_concat (self->module_data_save, path, NULL);
	if (path1 != NULL)
	{
		lipth_paths_add_path_abs (self, path1);
		lisys_free (path1);
	}
	else
		ret = 0;

	return ret;
}
示例#4
0
/**
 * \brief Gets the path to an SQL database.
 *
 * Calling this function will create the save directory if it doesn't exist
 * yet. If the creation fails or the function runs out of memory, NULL is
 * returned and the error message is set.
 *
 * \param self Paths object.
 * \param name File name.
 * \return Newly allocated absolute path or NULL.
 */
char* lipth_paths_get_sql (
	const LIPthPaths* self,
	const char*       name)
{
	char* path;

	/* Format the path. */
	path = lisys_path_concat (self->module_state, name, NULL);
	if (path == NULL)
		return NULL;

	/* Check if the save directory exists. */
	if (lisys_filesystem_access (self->module_state, LISYS_ACCESS_EXISTS))
	{
		if (!lisys_filesystem_access (self->module_state, LISYS_ACCESS_WRITE))
		{
			lisys_error_set (EINVAL, "save path `%s' is not writable", path);
			lisys_free (path);
			return NULL;
		}
		return path;
	}

	/* Create the save directory. */
	if (!lisys_filesystem_makepath (self->module_state))
	{
		lisys_free (path);
		return NULL;
	}

	return path;
}
示例#5
0
/**
 * \brief Gets the global data directory.
 *
 * Follows the XDG Base Directory Specification:
 * http://www.freedesktop.org/Standards/basedir-spec
 *
 * \param path Relative path being searched for.
 * \return New string or NULL.
 */
char* lisys_paths_get_data_global (
	const char* path)
{
#ifdef __WIN32__
	return NULL;
#else
	int last;
	char* dup;
	char* ptr;
	char* ret;
	char* start;
	const char* dirs;

	/* Get the list of global data directories. */
	dirs = getenv ("XDG_DATA_DIRS");
	if (dirs == NULL || dirs[0] == '\0')
		return NULL;
	dup = lisys_string_dup  (dirs);
	if (dup == NULL)
		return NULL;

	/* Loop through all directories. */
	ptr = start = dup;
	ret = NULL;
	last = 0;
	while (1)
	{
		/* Search for the delimiter. */
		last = (*ptr == '\0');
		if (*ptr != ':' && !last)
		{
			ptr++;
			continue;
		}
		*ptr = '\0';

		/* Test if the path is valid. */
		ret = lisys_path_concat (start, path, NULL);
		if (ret != NULL)
		{
			if (lisys_filesystem_access (ret, LISYS_ACCESS_READ))
				break;
			lisys_free (ret);
			ret = NULL;
		}

		/* Check if more candidates exist. */
		if (last)
			break;
		ptr++;
		start = ptr;
	}

	/* Return the result or NULL. */
	lisys_free (dup);
	return ret;
#endif
}
示例#6
0
/**
 * \brief Frees the image.
 * \param self Image.
 */
void liren_image21_free (
	LIRenImage21* self)
{
	if (self->texture != NULL)
		liimg_texture_free (self->texture);
	lisys_free (self->name);
	lisys_free (self->path);
	lisys_free (self);
}
示例#7
0
void liext_thread_inst_free (
	LIExtThread* self)
{
	liext_thread_inst_set_quit (self);
	if (self->thread != NULL)
		lisys_thread_free (self->thread);
	if (self->program != NULL)
		limai_program_free (self->program);
	lisys_free (self->file);
	lisys_free (self->code);
	lisys_free (self);
}
示例#8
0
void limdl_shape_clear (
	LIMdlShape*  self)
{
	int i;

	for (i = 0 ; i < self->parts.count ; i++)
	{
		lisys_free (self->parts.array[i].vertices.array);
	}
	lisys_free (self->parts.array);
	lisys_free (self->name);
}
示例#9
0
/**
 * \brief Frees the sample.
 * \param self Sample.
 */
void lisnd_sample_free (
	LISndSample* self)
{
	/* Stop the worker thread. */
	if (self->worker != NULL)
	{
		lisys_async_call_stop (self->worker);
		lisys_async_call_free (self->worker);
	}

	alDeleteBuffers (2, self->buffers);
	lisys_free (self->file);
	lisys_free (self);
}
示例#10
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);
}
示例#11
0
/**
 * \brief Frees the texture.
 * \param self Texture.
 */
void liimg_texture_free (
	LIImgTexture* self)
{
	if (self->texture)
		glDeleteTextures (1, &self->texture);
	lisys_free (self);
}
示例#12
0
LIExtSpeech* liext_speech_new (
	LIExtModule* module,
	const char*  font,
	const char*  text)
{
	LIExtSpeech* self;
	LIFntFont* font1;

	self = lisys_malloc (sizeof (LIExtSpeech));
	if (self == NULL)
		return NULL;
	self->diffuse[0] = 1.0f;
	self->diffuse[1] = 1.0f;
	self->diffuse[2] = 1.0f;
	self->diffuse[3] = 1.0f;
	self->timer = 0.0f;
	self->fade_exponent = 4;
	self->fade_time = 5;
	self->life_time = 10;
	self->text = lifnt_layout_new ();
	if (self->text == NULL)
	{
		lisys_free (self);
		return NULL;
	}
	lifnt_layout_set_width_limit (self->text, 150);
	font1 = liwdg_manager_find_font (module->widgets, font);
	if (font1 != NULL)
		lifnt_layout_append_string (self->text, font1, text);

	return self;
}
示例#13
0
/**
 * \brief Creates a new polygon.
 * \param ops Vertex access operations.
 * \param normal Normal vector.
 * \param vertices Array of vertices.
 * \param count Number of vertices in the array.
 * \return New polygon or NULL.
 */
LIMatPolygon* limat_polygon_new (
	const LIMatVtxops* ops,
	const LIMatVector* normal,
	const void*        vertices,
	int                count)
{
	LIMatPolygon* self;

	/* Allocate self. */
	self = (LIMatPolygon*) lisys_calloc (1, sizeof (LIMatPolygon));
	if (self == NULL)
		return NULL;
	self->ops = ops;
	self->normal = *normal;
	if (count == 0)
		return self;

	/* Allocate vertices. */
	self->vertices.capacity = count;
	self->vertices.vertices = lisys_malloc (count * ops->size);
	if (self->vertices.vertices == NULL)
	{
		lisys_free (self);
		return NULL;
	}

	/* Copy vertices. */
	memcpy (self->vertices.vertices, vertices, count * ops->size);
	self->vertices.count = count;

	return self;
}
示例#14
0
/**
 * \brief Creates a new file in the override directory.
 * \param self Paths.
 * \param name Filename.
 * \param config One for a config file, zero for a data file.
 * \return path Absolute path or NULL.
 */
const char* lipth_paths_create_file (
	LIPthPaths* self,
	const char* name,
	int         config)
{
	char* path;
	LIAlgStrdicNode* node;

	/* Format the path. */
	if (config)
		path = lisys_path_concat (self->module_config, name, NULL);
	else
		path = lisys_path_concat (self->module_data_save, name, NULL);
	if (path == NULL)
		return NULL;

	/* Register the file. */
	node = lialg_strdic_find_node (self->files, name);
	if (node != NULL)
	{
		lisys_free (node->value);
		node->value = path;
	}
	else
		lialg_strdic_insert (self->files, name, path);

	return path;
}
示例#15
0
static void Animation_new (LIScrArgs* args)
{
	const char* name;
	LIMdlAnimation* self;
	LIScrData* data;

	/* Get arguments. */
	if (!liscr_args_geti_string (args, 0, &name))
		return;

	/* Allocate the animation. */
	self = limdl_animation_new ();
	if (self == NULL)
		return;
	self->name = lisys_string_dup (name);
	if (self->name == NULL)
	{
		lisys_free (self);
		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);
}
示例#16
0
void liext_heightmap_free (
	LIExtModule* self)
{
    liext_heightmap_cleanup(self, self->data1);
    liext_heightmap_cleanup(self, self->data2);
	lisys_free (self);
}
示例#17
0
/**
 * \brief Gets the home data directory.
 *
 * Follows the XDG Base Directory Specification:
 * http://www.freedesktop.org/Standards/basedir-spec
 *
 * \return New string or NULL.
 */
char* lisys_paths_get_data_home ()
{
#ifdef __WIN32__
	int i;
	char tmp[MAX_PATH];

	if (!SHGetSpecialFolderPath (NULL, tmp, CSIDL_PERSONAL, TRUE))
		return NULL;
	for (i = 0 ; tmp[i] != '\0' ; i++)
	{
		if (tmp[i] == '\\')
			tmp[i] = '/';
	}
	return lisys_path_concat (tmp, "My Games", NULL);
#else
	char* ret;
	char* tmp;
	const char* dir;

	dir = getenv ("XDG_DATA_HOME");
	if (dir != NULL && dir[0] != '\0')
		return lisys_string_dup  (dir);
	tmp = lisys_paths_get_home ();
	if (tmp == NULL)
		return NULL;
	ret = lisys_path_concat (tmp, ".local/share", NULL);
	lisys_free (tmp);

	return ret;
#endif
}
示例#18
0
/**
 * \brief Removes data from the associative array.
 * \param self Associative array.
 * \param key Key of the removed node.
 * \return Nonzero if a node was removed.
 */
int lialg_u32dic_remove (
	LIAlgU32dic* self,
	uint32_t     key)
{
	LIAlgBstNode* tnode;
	LIAlgU32dicNode* anode;
	LIAlgU32dicNode tmp;
	
	/* Find node. */
	tmp.key = key;
	tnode = lialg_bst_find (self->tree, &tmp);
	if (tnode == NULL)
		return 1;
	anode = (LIAlgU32dicNode*) tnode->data;
	lisys_assert (&anode->node == tnode);

	/* Unlink from tree. */
	lialg_bst_unlink (self->tree, tnode);

	/* Remove from list. */
	if (anode->prev != NULL)
		anode->prev->next = anode->next;
	else
		self->list = anode->next;
	if (anode->next != NULL)
		anode->next->prev = anode->prev;
	lisys_free (anode);
	self->size--;
	return 0;
}
示例#19
0
/**
 * \brief Creates a new program instance.
 *
 * \param path Root data directory.
 * \param name Module name.
 * \param args Module arguments or NULL.
 * \return New program or NULL.
 */
LIMaiProgram* limai_program_new (
	const char* path,
	const char* name,
	const char* args)
{
	LIMaiProgram* self;

	/* Allocate self. */
	self = lisys_calloc (1, sizeof (LIMaiProgram));
	if (self == NULL)
		return NULL;
	self->args = lisys_string_dup ((args != NULL)? args : "");
	if (self->args == NULL)
	{
		lisys_free (self);
		return NULL;
	}

	/* Initialize subsystems. */
	if (!private_init (self, path, name, args))
	{
		limai_program_free (self);
		return NULL;
	}

	return self;
}
示例#20
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
}
示例#21
0
/**
 * \brief Frees the associative array.
 * \param self Associative array.
 */
void lialg_u32dic_free (
	LIAlgU32dic* self)
{
	lialg_bst_foreach (self->tree, (LIAlgBstForeach) lisys_free);
	self->tree->root = NULL;
	lialg_bst_free (self->tree);
	lisys_free (self);
}
示例#22
0
int lifnt_layout_get_vertices (
	LIFntLayout* self,
	LIMdlIndex** result_index,
	float**      result_vertex)
{
	int i;
	int j;
	float* vertices;
	LIMdlIndex* indices;
	LIFntLayoutGlyph* glyph;

	/* Layout glyphs. */
	private_layout (self);

	/* Allocate buffer data. */
	if (self->n_glyphs)
	{
		indices = lisys_calloc (6 * self->n_glyphs, sizeof (LIMdlIndex));
		if (indices == NULL)
			return 0;
		vertices = lisys_calloc (20 * self->n_glyphs, sizeof (float));
		if (vertices == NULL)
		{
			lisys_free (indices);
			return 0;
		}
	}
	else
	{
		indices = NULL;
		vertices = NULL;
	}

	/* Create vertices and indices. */
	for (i = 0 ; i < self->n_glyphs ; i++)
	{
		glyph = self->glyphs + i;
		indices[6 * i + 0] = 4 * i + 0;
		indices[6 * i + 1] = 4 * i + 1;
		indices[6 * i + 2] = 4 * i + 2;
		indices[6 * i + 3] = 4 * i + 1;
		indices[6 * i + 4] = 4 * i + 2;
		indices[6 * i + 5] = 4 * i + 3;
		lifnt_font_get_vertices (glyph->font, glyph->glyph, vertices + 20 * i);
		for (j = 2 ; j < 20 ; j += 5)
		{
			vertices[20 * i + j + 0] += glyph->x;
			vertices[20 * i + j + 1] += glyph->y;
		}
	}

	/* Return the buffers. */
	*result_index = indices;
	*result_vertex = vertices;

	return 1;
}
示例#23
0
static int private_load_vorbis (
	LISndSample* self,
	const char*  file)
{
	int bs = -1;
	int freq;
	long num;
	void* buffer;
	ogg_int64_t pos;
	ogg_int64_t len;
	vorbis_info* info;
	OggVorbis_File vorbis;

	/* Initialize the decoder. */
	num = ov_fopen ((char*) file, &vorbis);
	if (num != 0)
	{
		if (num == OV_EREAD)
			lisys_error_set (EIO, "cannot open `%s'", file);
		else
			lisys_error_set (EINVAL, "cannot read `%s'", file);
		return 0;
	}

	/* Get stream information. */
	info = ov_info (&vorbis, -1);
	freq = info->rate;
	len = 2 * info->channels * ov_pcm_total (&vorbis, -1);
	pos = 0;

	/* Allocate the output buffer. */
	buffer = lisys_malloc (len);
	if (buffer == NULL)
	{
		ov_clear (&vorbis);
		return 0;
	}

	/* Decode the stream. */
	while (1)
	{
		num = ov_read (&vorbis, buffer + pos, len - pos, lisys_endian_big (), 2, 1, &bs);
		if (num <= 0)
			break;
		pos += num;
	}

	/* Upload to OpenAL. */
	if (info->channels == 1)
		private_load_raw (self, AL_FORMAT_MONO16, buffer, len, freq);
	else
		private_load_raw (self, AL_FORMAT_STEREO16, buffer, len, freq);
	ov_clear (&vorbis);
	lisys_free (buffer);

	return 1;
}
示例#24
0
int
lifnt_layout_append_string (LIFntLayout* self,
                            LIFntFont*   font,
                            const char*  string)
{
	int i;
	int length;
	wchar_t* wstr;
	LIFntLayoutGlyph* glyph;

	/* Convert to wide characters. */
	wstr = lisys_utf8_to_wchar (string);
	if (wstr == NULL)
		return 0;
	length = wcslen (wstr);

	/* Allocate glyphs. */
	if (self->n_glyphs + length > self->c_glyphs)
	{
		glyph = lisys_realloc (self->glyphs, (self->n_glyphs + length) * sizeof (LIFntLayoutGlyph));
		if (glyph == NULL)
		{
			lisys_free (wstr);
			return 0;
		}
		self->glyphs = glyph;
		self->c_glyphs = self->n_glyphs + length;
	}

	/* Set character data. */
	for (i = 0 ; i < length ; i++)
	{
		glyph = self->glyphs + self->n_glyphs;
		glyph->font = font;
		glyph->glyph = wstr[i];
		glyph->advance = lifnt_font_get_advance (font, wstr[i]);
		self->n_glyphs++;
	}
	lisys_free (wstr);

	/* Needs relayouting. */
	self->dirty = 1;
	return 1;
}
示例#25
0
/**
 * \brief Frees the paths object.
 *
 * \param self Paths object.
 */
void lipth_paths_free (
	LIPthPaths* self)
{
#ifdef LI_RELATIVE_PATHS
	lisys_free (self->global_exts);
	lisys_free (self->global_data);
#endif
	lisys_free (self->global_state);
	lisys_free (self->module_data);
	lisys_free (self->module_name);
	lisys_free (self->module_state);
	lisys_free (self->override_data);
	lisys_free (self->root);
	lisys_free (self);
}
示例#26
0
/**
 * \brief Frees the widget.
 * \param self Widget.
 */
void liwdg_widget_free (LIWdgWidget* self)
{
	int x;
	int y;

	while (self->children != NULL)
		private_call_detach_manual (self, self->children);
	for (y = 0 ; y < self->height ; y++)
	for (x = 0 ; x < self->width ; x++)
		private_call_detach (self, x, y);
	liwdg_widget_canvas_clear (self);
	liwdg_widget_detach (self);
	lisys_free (self->cols);
	lisys_free (self->rows);
	lisys_free (self->cells);
	lialg_ptrdic_remove (self->manager->widgets.all, self);
	liren_render_overlay_free (self->manager->render, self->overlay);
	lisys_free (self);
}
/**
 * \brief Frees the framebuffer.
 * \param self Framebuffer.
 */
void liren_framebuffer32_free (
    LIRenFramebuffer32* self)
{
    lialg_ptrdic_remove (self->render->framebuffers, self);
    glDeleteFramebuffers (1, &self->render_framebuffer);
    glDeleteFramebuffers (2, self->postproc_framebuffers);
    glDeleteTextures (2, self->render_textures);
    glDeleteTextures (3, self->postproc_textures);
    lisys_free (self);
}
示例#28
0
/**
 * \brief Frees the collision shape.
 * \param self Collision shape.
 */
void liphy_shape_free (
	LIPhyShape* self)
{
	if (self->shape != NULL)
	{
		liphy_shape_clear (self);
		delete self->shape;
	}
	lisys_free (self);
}
void lisys_serial_worker_free (
	LISysSerialWorker* self)
{
	LISysSerialWorkerTask* ptr;
	LISysSerialWorkerTask* ptr_next;

	/* Terminate the thread. */
	self->quit = 1;
	if (self->thread != NULL)
	{
		lisys_semaphore_signal (self->tasks_semaphore);
		lisys_thread_join (self->thread);
		lisys_thread_free (self->thread);
	}

	/* Free remaining tasks. */
	for (ptr = self->tasks.pending ; ptr != NULL ; ptr = ptr_next)
	{
		ptr_next = ptr->next;
		self->task_free (ptr->data);
		lisys_free (ptr);
	}

	/* Free remaining results. */
	for (ptr = self->results.pending ; ptr != NULL ; ptr = ptr_next)
	{
		ptr_next = ptr->next;
		self->result_free (ptr->data);
		lisys_free (ptr);
	}

	/* Free the mutexes. */
	if (self->tasks.mutex != NULL)
		lisys_mutex_free (self->tasks.mutex);
	if (self->results.mutex != NULL)
		lisys_mutex_free (self->results.mutex);

	/* Free the semaphore. */
	if (self->tasks_semaphore != NULL)
		lisys_semaphore_free (self->tasks_semaphore);
	lisys_free (self);
}
示例#30
0
void licli_window_free (
	LICliWindow* self)
{
	if (self->joystick != NULL)
		SDL_JoystickClose (self->joystick);
	if (self->screen != NULL)
		SDL_FreeSurface (self->screen);
	if (TTF_WasInit ())
		TTF_Quit ();
	lisys_free (self);
}