OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
material.c File Reference
Include dependency graph for material.c:

Go to the source code of this file.

Classes

struct  _MapeMaterialMapPrivate
 

Macros

#define MAPE_MATERIAL_MAP_PRIVATE(obj)   (G_TYPE_INSTANCE_GET_PRIVATE((obj), MAPE_TYPE_MATERIAL_MAP, MapeMaterialMapPrivate))
 

Typedefs

typedef struct
_MapeMaterialMapPrivate 
MapeMaterialMapPrivate
 

Enumerations

enum  { PROP_0, PROP_N_MATERIALS }
 

Functions

C4GroupHandle_mape_group_get_handle (MapeGroup *group)
 
C4MaterialMapHandle_mape_material_map_get_handle (MapeMaterialMap *map)
 
C4TextureMapHandle_mape_texture_map_get_handle (MapeTextureMap *map)
 
GType mape_material_get_type (void)
 
MapeMaterialMapmape_material_map_new (void)
 
gboolean mape_material_map_load (MapeMaterialMap *map, MapeGroup *from, GError **error)
 
guint mape_material_map_get_material_count (MapeMaterialMap *map)
 
void mape_material_map_set_default_textures (MapeMaterialMap *matmap, MapeTextureMap *texmap)
 
const MapeMaterialmape_material_map_get_material (MapeMaterialMap *map, guint index)
 
MapeMaterialmape_material_map_get_material_by_name (MapeMaterialMap *map, const gchar *name)
 
const gchar * mape_material_get_name (const MapeMaterial *material)
 
const gchar * mape_material_get_texture_overlay (const MapeMaterial *material)
 

Class Documentation

struct _MapeMaterialMapPrivate

Definition at line 44 of file material.c.

Class Members
C4MaterialMapHandle * handle

Macro Definition Documentation

Typedef Documentation

Definition at line 43 of file material.c.

Enumeration Type Documentation

anonymous enum
Enumerator
PROP_0 
PROP_N_MATERIALS 

Definition at line 48 of file material.c.

48  {
49  PROP_0,
50 
51  /* read only */
53 };

Function Documentation

C4GroupHandle* _mape_group_get_handle ( MapeGroup group)

SECTION:mape-material-map : MapeMaterialMap : C4MaterialMap interface mape/material.h : Unstable

MapeMaterialMap is a simple GObject-based interface to C4MaterialMap. It supports loading a material map from a Material.ocg group file. It can load multiple files, with newer entries overloading previous ones in case of name clashes to support material overloading.

SECTION:mape-group : MapeGroup : C4Group interface mape/group.h : Unstable

MapeGroup is a simple GObject-based interface to C4Group. It currntly only supports a subset of the C4Group operations, it does not support writing groups for example. It is just enough for what Mape requires.

Definition at line 682 of file group.c.

Referenced by mape_material_map_load().

683 {
684  g_return_val_if_fail(MAPE_IS_GROUP(group), NULL);
685  return MAPE_GROUP_PRIVATE(group)->handle;
686 }
#define MAPE_GROUP_PRIVATE(obj)
Definition: group.c:63
#define MAPE_IS_GROUP(obj)
Definition: group.h:26

Here is the caller graph for this function:

C4MaterialMapHandle* _mape_material_map_get_handle ( MapeMaterialMap map)

Definition at line 396 of file material.c.

References MAPE_IS_MATERIAL_MAP, and MAPE_MATERIAL_MAP_PRIVATE.

Referenced by mape_mapgen_render().

397 {
398  g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), NULL);
399  return MAPE_MATERIAL_MAP_PRIVATE(map)->handle;
400 }
#define MAPE_IS_MATERIAL_MAP(obj)
Definition: material.h:29
#define MAPE_MATERIAL_MAP_PRIVATE(obj)
Definition: material.c:55

Here is the caller graph for this function:

C4TextureMapHandle* _mape_texture_map_get_handle ( MapeTextureMap map)

Definition at line 591 of file texture.c.

References MAPE_IS_TEXTURE_MAP, and MAPE_TEXTURE_MAP_PRIVATE.

Referenced by mape_material_map_set_default_textures().

592 {
593  g_return_val_if_fail(MAPE_IS_TEXTURE_MAP(map), NULL);
594  return MAPE_TEXTURE_MAP_PRIVATE(map)->handle;
595 }
#define MAPE_TEXTURE_MAP_PRIVATE(obj)
Definition: texture.c:46
#define MAPE_IS_TEXTURE_MAP(obj)
Definition: texture.h:29

Here is the caller graph for this function:

const gchar* mape_material_get_name ( const MapeMaterial material)

mape_material_get_name: : A MapeMaterial.

Returns the material's name.

Return Value: The name of the material. The string is owned by the MapeMaterial and must not be freed by the user.

Definition at line 371 of file material.c.

References c4_material_handle_get_name().

Referenced by mape_mat_tex_view_reload().

372 {
373  g_return_val_if_fail(material != NULL, NULL);
375 }
const gchar * c4_material_handle_get_name(C4MaterialHandle *material)
typedefG_BEGIN_DECLS struct _C4MaterialHandle C4MaterialHandle

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar* mape_material_get_texture_overlay ( const MapeMaterial material)

mape_material_get_texture_overlay: : A MapeMaterial.

Returns the material's texture overlay as a string. This can be used to make a texture lookup in a corresponding MapeTextureMap.

Return Value: The texture overlay of the material. The string is owned by the MapeMaterial and must not be freed by the user.

Definition at line 388 of file material.c.

References c4_material_handle_get_texture_overlay().

389 {
390  g_return_val_if_fail(material != NULL, NULL);
392 }
const gchar * c4_material_handle_get_texture_overlay(C4MaterialHandle *material)
typedefG_BEGIN_DECLS struct _C4MaterialHandle C4MaterialHandle

Here is the call graph for this function:

GType mape_material_get_type ( void  )

Definition at line 194 of file material.c.

195 {
196  static GType material_type = 0;
197 
198  if(material_type == 0)
199  {
200  material_type = g_boxed_type_register_static(
201  "MapeMaterial",
202  (GBoxedCopyFunc)mape_material_copy,
203  (GBoxedFreeFunc)mape_material_free);
204  }
205 
206  return material_type;
207 }
const MapeMaterial* mape_material_map_get_material ( MapeMaterialMap map,
guint  index 
)

mape_material_map_get_material: : A MapeMaterialMap. : A material index.

Returns the entry with the given index in the map.

Returns: A MapeMaterial representing the indexed material. It is owned by #map and must not be used anymore after the map is finalized.

Definition at line 310 of file material.c.

References c4_material_map_handle_get_num(), _MapeMaterialMapPrivate::handle, MAPE_IS_MATERIAL_MAP, and MAPE_MATERIAL_MAP_PRIVATE.

Referenced by mape_mat_tex_view_reload().

312 {
314 
315  g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), NULL);
316 
317  priv = MAPE_MATERIAL_MAP_PRIVATE(map);
318  g_return_val_if_fail(index < c4_material_map_handle_get_num(priv->handle),
319  NULL);
320 
321  return mape_material_new(map, index);
322 }
#define MAPE_IS_MATERIAL_MAP(obj)
Definition: material.h:29
C4MaterialMapHandle * handle
Definition: material.c:45
guint c4_material_map_handle_get_num(C4MaterialMapHandle *material_map)
#define MAPE_MATERIAL_MAP_PRIVATE(obj)
Definition: material.c:55

Here is the call graph for this function:

Here is the caller graph for this function:

MapeMaterial* mape_material_map_get_material_by_name ( MapeMaterialMap map,
const gchar *  name 
)

Definition at line 336 of file material.c.

References c4_material_handle_get_name(), c4_material_map_handle_get_material(), c4_material_map_handle_get_num(), _MapeMaterialMapPrivate::handle, MAPE_IS_MATERIAL_MAP, and MAPE_MATERIAL_MAP_PRIVATE.

338 {
340  const gchar* cur_name;
341  guint i;
342 
343  g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), NULL);
344  g_return_val_if_fail(name != NULL, NULL);
345 
346  priv = MAPE_MATERIAL_MAP_PRIVATE(map);
347 
348  for(i = 0; i < c4_material_map_handle_get_num(priv->handle); ++i)
349  {
350  cur_name = c4_material_handle_get_name(
352  );
353 
354  if(g_ascii_strcasecmp(cur_name, name) == 0)
355  return mape_material_new(map, i);
356  }
357 
358  return NULL;
359 }
C4MaterialHandle * c4_material_map_handle_get_material(C4MaterialMapHandle *material_map, guint index)
const gchar * c4_material_handle_get_name(C4MaterialHandle *material)
#define MAPE_IS_MATERIAL_MAP(obj)
Definition: material.h:29
C4MaterialMapHandle * handle
Definition: material.c:45
guint c4_material_map_handle_get_num(C4MaterialMapHandle *material_map)
#define MAPE_MATERIAL_MAP_PRIVATE(obj)
Definition: material.c:55

Here is the call graph for this function:

guint mape_material_map_get_material_count ( MapeMaterialMap map)

mape_material_map_get_material_count: : A MapeMaterialMap.

Returns the number of materials contained in .

Return Value: The number of materials in .

Definition at line 274 of file material.c.

References c4_material_map_handle_get_num(), MAPE_IS_MATERIAL_MAP, and MAPE_MATERIAL_MAP_PRIVATE.

Referenced by mape_mat_tex_view_reload().

275 {
276  g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), 0);
278  MAPE_MATERIAL_MAP_PRIVATE(map)->handle);
279 }
#define MAPE_IS_MATERIAL_MAP(obj)
Definition: material.h:29
guint c4_material_map_handle_get_num(C4MaterialMapHandle *material_map)
#define MAPE_MATERIAL_MAP_PRIVATE(obj)
Definition: material.c:55

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean mape_material_map_load ( MapeMaterialMap map,
MapeGroup from,
GError **  error 
)

mape_material_map_load: : A MapeMaterialMap. : An open MapeGroup to load materials from. : Location to store error information, if any.

Loads all the material files (*.c4m) from the group . If this includes materials with the same name as materials already contained in , then the new materials will not be loaded. If an error occurs while loading the material map the function returns FALSE and is set.

Returns: TRUE on success, FALSE on failure.

Definition at line 242 of file material.c.

References _mape_group_get_handle(), c4_material_map_handle_load(), _MapeMaterialMapPrivate::handle, mape_group_is_open(), MAPE_IS_GROUP, MAPE_IS_MATERIAL_MAP, and MAPE_MATERIAL_MAP_PRIVATE.

Referenced by mape_mat_tex_view_reload().

245 {
247  guint new_count;
248 
249  g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), FALSE);
250  g_return_val_if_fail(MAPE_IS_GROUP(from), FALSE);
251  g_return_val_if_fail(mape_group_is_open(from), FALSE);
252  g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
253 
254  priv = MAPE_MATERIAL_MAP_PRIVATE(map);
255 
256  new_count = c4_material_map_handle_load(
257  priv->handle, _mape_group_get_handle(from));
258 
259  if(new_count > 0)
260  g_object_notify(G_OBJECT(map), "n-materials");
261 
262  return TRUE;
263 }
guint c4_material_map_handle_load(C4MaterialMapHandle *material_map, C4GroupHandle *group)
C4GroupHandle * _mape_group_get_handle(MapeGroup *group)
Definition: group.c:682
#define MAPE_IS_MATERIAL_MAP(obj)
Definition: material.h:29
C4MaterialMapHandle * handle
Definition: material.c:45
gboolean mape_group_is_open(MapeGroup *group)
Definition: group.c:220
#define MAPE_MATERIAL_MAP_PRIVATE(obj)
Definition: material.c:55
#define MAPE_IS_GROUP(obj)
Definition: group.h:26

Here is the call graph for this function:

Here is the caller graph for this function:

MapeMaterialMap* mape_material_map_new ( void  )

mape_material_map_new:

Creates a new MapeMaterialMap. The map is initially empty. Use mape_material_map_load() to load materials from one or more Material.ocg group files.

Return Value: A new MapeMaterialMap. Free with g_object_unref().

Definition at line 223 of file material.c.

References MAPE_MATERIAL_MAP, and MAPE_TYPE_MATERIAL_MAP.

Referenced by mape_mat_tex_view_reload().

224 {
225  return MAPE_MATERIAL_MAP(g_object_new(MAPE_TYPE_MATERIAL_MAP, NULL));
226 }
#define MAPE_MATERIAL_MAP(obj)
Definition: material.h:27
#define MAPE_TYPE_MATERIAL_MAP
Definition: material.h:26

Here is the caller graph for this function:

void mape_material_map_set_default_textures ( MapeMaterialMap matmap,
MapeTextureMap texmap 
)

mape_material_map_set_default_textures: : A MapeMaterialMap. : A MapeTextureMap to load textures from.

Sets the default textures for the materials in by looking up the texture overlay specified in the material file in .

Definition at line 290 of file material.c.

References _mape_texture_map_get_handle(), c4_material_map_crossmap_materials(), and MAPE_MATERIAL_MAP_PRIVATE.

Referenced by mape_mat_tex_view_reload().

292 {
294  MAPE_MATERIAL_MAP_PRIVATE(matmap)->handle,
296  );
297 }
void c4_material_map_crossmap_materials(C4MaterialMapHandle *material_map, C4TextureMapHandle *texture_map)
C4TextureMapHandle * _mape_texture_map_get_handle(MapeTextureMap *map)
Definition: texture.c:591
#define MAPE_MATERIAL_MAP_PRIVATE(obj)
Definition: material.c:55

Here is the call graph for this function:

Here is the caller graph for this function: