OpenClonk
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

◆ _MapeMaterialMapPrivate

struct _MapeMaterialMapPrivate

Definition at line 44 of file material.c.

Class Members
C4MaterialMapHandle * handle

Macro Definition Documentation

◆ MAPE_MATERIAL_MAP_PRIVATE

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

Definition at line 55 of file material.c.

Typedef Documentation

◆ MapeMaterialMapPrivate

Definition at line 41 of file material.c.

Enumeration Type Documentation

◆ anonymous enum

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 };
@ PROP_N_MATERIALS
Definition: material.c:52
@ PROP_0
Definition: material.c:49

Function Documentation

◆ _mape_group_get_handle()

C4GroupHandle* _mape_group_get_handle ( MapeGroup group)

SECTION:mape-material-map @title: MapeMaterialMap @short_description: C4MaterialMap interface mape/material.h @stability: 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 @title: MapeGroup @short_description: C4Group interface mape/group.h @stability: 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.

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

Referenced by mape_material_map_load().

Here is the caller graph for this function:

◆ _mape_material_map_get_handle()

C4MaterialMapHandle* _mape_material_map_get_handle ( MapeMaterialMap map)

Definition at line 396 of file material.c.

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

References MAPE_IS_MATERIAL_MAP, and MAPE_MATERIAL_MAP_PRIVATE.

Referenced by mape_mapgen_render().

Here is the caller graph for this function:

◆ _mape_texture_map_get_handle()

C4TextureMapHandle* _mape_texture_map_get_handle ( MapeTextureMap map)

Definition at line 591 of file texture.c.

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

Referenced by mape_material_map_set_default_textures().

Here is the caller graph for this function:

◆ mape_material_get_name()

const gchar* mape_material_get_name ( const MapeMaterial material)

mape_material_get_name: @material: 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.

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

References c4_material_handle_get_name().

Referenced by mape_mat_tex_view_reload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mape_material_get_texture_overlay()

const gchar* mape_material_get_texture_overlay ( const MapeMaterial material)

mape_material_get_texture_overlay: @material: 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.

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

References c4_material_handle_get_texture_overlay().

Here is the call graph for this function:

◆ mape_material_get_type()

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 }

◆ mape_material_map_get_material()

const MapeMaterial* mape_material_map_get_material ( MapeMaterialMap map,
guint  index 
)

mape_material_map_get_material: @map: A MapeMaterialMap. @index: 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.

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 }
guint c4_material_map_handle_get_num(C4MaterialMapHandle *material_map)
C4MaterialMapHandle * handle
Definition: material.c:45

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mape_material_map_get_material_by_name()

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

Definition at line 336 of file material.c.

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)

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.

Here is the call graph for this function:

◆ mape_material_map_get_material_count()

guint mape_material_map_get_material_count ( MapeMaterialMap map)

mape_material_map_get_material_count: @map: A MapeMaterialMap.

Returns the number of materials contained in @map.

Return Value: The number of materials in @map.

Definition at line 274 of file material.c.

275 {
276  g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), 0);
278  MAPE_MATERIAL_MAP_PRIVATE(map)->handle);
279 }

References c4_material_map_handle_get_num(), MAPE_IS_MATERIAL_MAP, and MAPE_MATERIAL_MAP_PRIVATE.

Referenced by mape_mat_tex_view_reload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mape_material_map_load()

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

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

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

Returns: TRUE on success, FALSE on failure.

Definition at line 242 of file material.c.

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 }
gboolean mape_group_is_open(MapeGroup *group)
Definition: group.c:220
guint c4_material_map_handle_load(C4MaterialMapHandle *material_map, C4GroupHandle *group)
C4GroupHandle * _mape_group_get_handle(MapeGroup *group)
Definition: group.c:682

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mape_material_map_new()

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.

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

References MAPE_MATERIAL_MAP, and MAPE_TYPE_MATERIAL_MAP.

Referenced by mape_mat_tex_view_reload().

Here is the caller graph for this function:

◆ mape_material_map_set_default_textures()

void mape_material_map_set_default_textures ( MapeMaterialMap matmap,
MapeTextureMap texmap 
)

mape_material_map_set_default_textures: @mapmap: A MapeMaterialMap. @texmap: A MapeTextureMap to load textures from.

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

Definition at line 290 of file material.c.

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

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

Referenced by mape_mat_tex_view_reload().

Here is the call graph for this function:
Here is the caller graph for this function: