Commit 4ae6eaff authored by Ban's avatar Ban
Browse files

Initial checkin.

parents
Makefile
Makefile.in
*.cache
configure
libtool
.libs/
.deps/
*.[ls]o
*.o
*.la
*.stamp
stamp-*
*~
config.h.in
*.log
*.status
# these may be useful one day if we complicates the build system
*.m4
build/
#!/bin/bash
mkdir -p build/aux || exit 1
mkdir -p build/m4 || exit 1
#gtkdocize --flavour no-tmpl || exit 1
autoreconf -vfi || exit 1
#~ ./configure "$@"
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.64])
AC_INIT([libovcc], [0.0], [dev@ovcc.tuxfamily.org])
AC_CONFIG_SRCDIR([src/ovcc.h])
AC_CONFIG_AUX_DIR([build/aux])
AC_CONFIG_MACRO_DIR([build/m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_CONFIG_HEADERS([config.h])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
# Checks for libraries.
GLIB_REQUIRE=2.0
GIO_REQUIRE=2.0
LIBXML_REQUIRE=2.0
PKG_CHECK_MODULES([LIBOVCC], [glib-2.0 >= ${GLIB_REQUIRE}
gio-2.0 >= ${GIO_REQUIRE}
libxml-2.0 >= ${LIBXML_REQUIRE}])
CFLAGS="${CFLAGS} ${LIBOVCC_CFLAGS} -Werror-implicit-function-declaration"
LIBS="${LIBS} ${LIBOVCC_LIBS}"
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile
src/Makefile
ovcc.pc])
AC_OUTPUT
prefix=@prefix@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: LibOVCC
Description: OpenVCC Core library
Version: @VERSION@
Requires: glib-2.0
Libs: -L${libdir} -lovcc
Libs.private:
Cflags: -I${includedir}/ovcc
lib_LTLIBRARIES = libovcc.la
bin_PROGRAMS = test
libovcc_la_SOURCES = tile.c \
tiles.c
test_LDADD = libovcc.la -lpthread
test_SOURCES = test.c
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef H_OVCC_BOARD
#define H_OVCC_BOARD
typedef struct s_OVCCBoard OVCCBoard;
/*ovcc_board_*/
#endif /* guard */
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef H_OVCC_OVCC
#define H_OVCC_OVCC
#endif /* guard */
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef H_OVCC_PLAYER
#define H_OVCC_PLAYER
#endif /* guard */
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <libxml/parser.h>
#include <gio/gio.h>
#include "tiles.h"
int
main (int argc,
char **argv)
{
GFile *file;
OVCCTileSet *tileset;
GError *err = NULL;
gboolean success = FALSE;
g_type_init ();
LIBXML_TEST_VERSION
if (argc >= 2) {
file = g_file_new_for_commandline_arg (argv[1]);
tileset = ovcc_tile_set_new ();
if (! ovcc_tile_set_load (tileset, file, NULL, &err)) {
g_critical ("Load error: %s", err ? err->message : "???");
g_clear_error (&err);
} else {
success = TRUE;
}
ovcc_tile_set_free (tileset);
g_object_unref (file);
}
return success ? 0 : 1;
}
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <glib.h>
#include <glib/gprintf.h>
#include "tile.h"
enum Sides
{
TOP,
BOTTOM,
LEFT,
RIGHT,
N_SIDES
};
struct s_OVCCTile
{
OVCCTileID id;
OVCCTileSide *sides[N_SIDES];
OVCCTileContentType center;
};
struct s_OVCCTileSide
{
OVCCTileContentType self;
OVCCTileSideRelation relations;
};
void
ovcc_tile_dump (OVCCTile *tile)
{
char tiles[OVCC_TILE_CONTENT_TYPE_MONASTERY + 1] = {
' ', 'f', 'p', 'c', 'm'
};
#define SIDE_VAL(s) \
(tile->sides[s] ? tiles[tile->sides[s]->self] : '?')
#define SIDE_REL(s, f) \
(tile->sides[s] \
? tile->sides[s]->relations & OVCC_TILE_SIDE_REL_##f##OF \
? SIDE_VAL (s) \
: ' ' \
: ' ')
g_printf ("ID: %d\n", tile->id);
g_printf (" %c \n", SIDE_VAL (TOP));
g_printf (" %c%c%c \n", SIDE_REL (TOP, RIGHT),
SIDE_REL (TOP, FRONT),
SIDE_REL (TOP, LEFT));
g_printf ("%c%c%c%c%c\n",
SIDE_VAL (LEFT),
SIDE_REL (LEFT, FRONT),
tiles[tile->center],
SIDE_REL (RIGHT, FRONT),
SIDE_VAL (RIGHT));
g_printf (" %c%c%c \n", SIDE_REL (BOTTOM, LEFT),
SIDE_REL (BOTTOM, FRONT),
SIDE_REL (BOTTOM, RIGHT));
g_printf (" %c \n", SIDE_VAL (BOTTOM));
}
/**
* @param id identifier of the tile, represenative of its content
* @param left content of the left side of the tile
* @param top content of the top side of the tile
* @param right content of the right side of the tile
* @param bottom content of the bottom side of the tile
* @param center type of the center of the tile (typically monastery)
* @returns A new tile that should be freed with ovcc_tile_free()
*
* Allocate and initialise a kind of tile
*/
OVCCTile *
ovcc_tile_new (OVCCTileID id,
OVCCTileSide *left,
OVCCTileSide *top,
OVCCTileSide *right,
OVCCTileSide *bottom,
OVCCTileContentType center)
{
OVCCTile *tile;
tile = g_malloc (sizeof *tile);
if (tile) {
tile->id = id;
tile->sides[LEFT] = left;
tile->sides[TOP] = top;
tile->sides[RIGHT] = right;
tile->sides[BOTTOM] = bottom;
tile->center = center;
}
return tile;
}
/**
* @brief Creates a new tile
* @param id The tile ID
* @param left The left side, or NULL
* @param top The top side, or NULL
* @param right The right side, or NULL
* @param bottom The bottom side, or NULL
* @param center The center type
* @returns A new tile or NULL on failure.
*
* This function creates a tile and computes the sides and their relations to
* fill everything not given.
* It allows to give less informations than the finally needed, e.g. letting
* sides being created through the relations others have to it.
*
* Every side not given will be created by computing relations and so.
* If it is not possible to create the tile from the given informations, NULL is
* returned.
* The sides itself may be modified if a relation must be added as another one
* defines it.
*
* If the given sides and relations results to an invalid or incomplete tile,
* the tile is not created and this function returns NULL.
*/
OVCCTile *
ovcc_tile_new_auto (OVCCTileID id,
OVCCTileSide *left,
OVCCTileSide *top,
OVCCTileSide *right,
OVCCTileSide *bottom,
OVCCTileContentType center)
{
/* à toi Jo :-° */
/* temporaire */
return ovcc_tile_new (id, left, top, right, bottom, center);
}
/**
* @param tile A tile to free
*
* Free a tile and its sides.
*/
void
ovcc_tile_free (OVCCTile *tile)
{
if (tile) {
size_t i;
for (i = 0; i < N_SIDES; i++) {
ovcc_tile_side_free (tile->sides[i]);
}
g_free (tile);
}
}
OVCCTileID
ovcc_tile_get_id (OVCCTile *tile)
{
return tile->id;
}
/**
* @param side_type Content Type of the new side
* @param rel_bits Bit field representing this side relation to the others
*
* Allocate and initialise a new tile side
*/
OVCCTileSide *
ovcc_tile_side_new (OVCCTileContentType side_type,
OVCCTileSideRelation rel_bits)
{
OVCCTileSide *side;
side = g_malloc (sizeof *side);
if (side) {
side->self = side_type;
side->relations = rel_bits;
}
return side;
}
/**
* @param side A tile side to free
*
* Free a tile side.
*/
void
ovcc_tile_side_free (OVCCTileSide *side)
{
if (side) {
g_free (side);
}
}
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef H_OVCC_TILE
#define H_OVCC_TILE
typedef unsigned int OVCCTileID;
typedef struct s_OVCCTile OVCCTile;
typedef struct s_OVCCTileSide OVCCTileSide;
typedef enum e_OVCCTileContentType OVCCTileContentType;
typedef enum e_OVCCTileSideRelation OVCCTileSideRelation;
/**
* Type of a tile content.
* It is used for the types at a tile side and center.
*/
enum e_OVCCTileContentType
{
OVCC_TILE_CONTENT_TYPE_NONE, /**< None type, no content */
OVCC_TILE_CONTENT_TYPE_FIELD, /**< Contains a field */
OVCC_TILE_CONTENT_TYPE_PATH, /**< Contains a path */
OVCC_TILE_CONTENT_TYPE_CITY, /**< Contains a city */
OVCC_TILE_CONTENT_TYPE_MONASTERY /**< Contains a monastery */
};
/**
* Flag saying whether a side content is linked over the tile to other side(s).
* A relation of course says that its members are of the same type.
*/
enum e_OVCCTileSideRelation
{
OVCC_TILE_SIDE_REL_NONE = 0, /**< No relations at all */
OVCC_TILE_SIDE_REL_LEFTOF = 1 << 0, /**< Relation to its left neighbour */
OVCC_TILE_SIDE_REL_FRONTOF = 1 << 2, /**< Relation to its opposed neighbour */
OVCC_TILE_SIDE_REL_RIGHTOF = 1 << 3 /**< Relation to its right neighbour */
};
OVCCTile *ovcc_tile_new (OVCCTileID id,
OVCCTileSide *left,
OVCCTileSide *top,
OVCCTileSide *right,
OVCCTileSide *bottom,
OVCCTileContentType center);
OVCCTile *ovcc_tile_new_auto (OVCCTileID id,
OVCCTileSide *left,
OVCCTileSide *top,
OVCCTileSide *right,
OVCCTileSide *bottom,
OVCCTileContentType center);
void ovcc_tile_free (OVCCTile *tile);
void ovcc_tile_dump (OVCCTile *tile);
OVCCTileID ovcc_tile_get_id (OVCCTile *tile);
OVCCTileSide *ovcc_tile_side_new (OVCCTileContentType side_type,
OVCCTileSideRelation rel_bits);
void ovcc_tile_side_free (OVCCTileSide *side);
#endif /* guard */
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <string.h>
#include "tiles.h"
#include "tile.h"
struct s_OVCCTileSet
{
GHashTable *tiles;
};
static void
free_tile (gpointer data)
{
OVCCTile *tile = data;
ovcc_tile_dump (tile);
ovcc_tile_free (tile);
}
/**
* @brief Creates a new TileSet
* @returns The newly created TileSet
*
*/
OVCCTileSet *
ovcc_tile_set_new (void)
{
OVCCTileSet *set;
set = g_malloc (sizeof *set);
if (set) {
set->tiles = g_hash_table_new_full (g_direct_hash, g_direct_equal,
NULL, /*ovcc_tile_free*/ free_tile);
}
return set;
}
/**
* @brief Frees a TileSet
* @param set The TileSet to free
*
*/
void
ovcc_tile_set_free (OVCCTileSet *set)
{
if (set) {
g_hash_table_destroy (set->tiles);
g_free (set);
}
}
/**
* @brief Clears a TileSet
* @param set The TileSet to clear.
*
* Removes all tiles in the given tile set.
*/
void
ovcc_tile_set_clear (OVCCTileSet *set)
{
g_hash_table_remove_all (set->tiles);
}
/**
* @brief Removes a tile from a set
* @param set A TileSet
* @param id The ID of the tile to remove from the set.
* @returns TRUE if the tile was remove, false if it wasn't found in the set.
*
*
*/
gboolean
ovcc_tile_set_remove (OVCCTileSet *set,
OVCCTileID id)
{
return g_hash_table_remove (set->tiles, GINT_TO_POINTER (id));
}
/**
* @brief Gets whether a tile is on a set
* @param set A TileSet
* @param id The ID of the tile to search for
* @returns TRUE if the tile is found on the set, FALSE otherwise.