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

Go to the source code of this file.

Functions

C4GroupHandle_mape_group_get_handle (MapeGroup *group)
 
C4MaterialMapHandle_mape_material_map_get_handle (MapeMaterialMap *map)
 
gboolean mape_mapgen_init (GError **error)
 
void mape_mapgen_deinit ()
 
void mape_mapgen_set_root_group (MapeGroup *group)
 
GdkPixbuf * mape_mapgen_render (const gchar *filename, const gchar *source, MapeMapgenType type, const gchar *script_path, MapeMaterialMap *material_map, MapeTextureMap *texture_map, guint width, guint height, GError **error)
 
as a

32-bit integer.

C4TextureMapHandle_mape_texture_map_get_handle (MapeTextureMap *map)
 

Function Documentation

C4GroupHandle* _mape_group_get_handle ( MapeGroup group)

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

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.

Referenced by mape_mapgen_render().

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:

void mape_mapgen_deinit ( )

mape_mapgen_deinit():

Deinitializes the map generator.

Definition at line 156 of file mapgen.c.

References c4_mapgen_handle_deinit_script_engine().

Referenced by main().

157 {
159 }
void c4_mapgen_handle_deinit_script_engine()

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean mape_mapgen_init ( GError **  error)

mape_mapgen_init: : Location to store error information, if any.

Initializes the map generator.

Returns: TRUE on success or FALSE on error.

Definition at line 144 of file mapgen.c.

References c4_mapgen_handle_init_script_engine().

Referenced by main().

145 {
147  return TRUE;
148 }
void c4_mapgen_handle_init_script_engine()

Here is the call graph for this function:

Here is the caller graph for this function:

GdkPixbuf* mape_mapgen_render ( const gchar *  filename,
const gchar *  source,
MapeMapgenType  type,
const gchar *  script_path,
MapeMaterialMap material_map,
MapeTextureMap texture_map,
guint  width,
guint  height,
GError **  error 
)

mape_mapgen_render:

: The filename of the file that is being parsed. This is only used for display purposes. : The map generator source code for the map to generate. : Specifies how the text in should be interpreted. Must not be MAPE_MAPGEN_NONE. : Path to the script source for algo=script overlays, or NULL. : The material map containing the materials to be used during map generation. : The texture map containing the textures to be used during map generation. : The width of the map to generate. : The height of the map to generate. : Location to store error information, if any, or NULL.

Renders the map described by with the C4MapCreatorS2 into a pixbuf. The pixel color depends on the texture at the corresponding position and is determined by the average color of that texture.

If the source contains one or more algo=script overlays and is NULL, an error is generated. Otherwise, the file at is opened and used to look up the relevant script functions.

In case an error occurs, for example when the map generator source code is not valid, is set and the function returns NULL.

Return Value: A #GdkPixbuf with the generated map, or NULL. Free with g_object_unref().

Definition at line 227 of file mapgen.c.

References _mape_material_map_get_handle(), _mape_texture_map_get_handle(), c4_mapgen_handle_free(), c4_mapgen_handle_get_error(), c4_mapgen_handle_get_height(), c4_mapgen_handle_get_map(), c4_mapgen_handle_get_rowstride(), c4_mapgen_handle_get_width(), c4_mapgen_handle_new(), c4_mapgen_handle_new_script(), _C4MapgenHandle::error_message, MAPE_MAPGEN_ERROR_COMPILE, MAPE_MAPGEN_ERROR_MEMORY, MAPE_MAPGEN_LANDSCAPE_TXT, and MAPE_MAPGEN_MAP_C.

236 {
237  C4MapgenHandle* handle;
238  const char* error_message;
239  unsigned int out_width;
240  unsigned int out_height;
241  GdkPixbuf* pixbuf;
242  guint8* out_p;
243  const unsigned char* in_p;
244  guint out_rowstride;
245  unsigned int in_rowstride;
246  guint datawidth;
247  guint8 matclrs[256 * 4];
248  unsigned int x, y;
249  unsigned int matnum;
250 
251  switch(type)
252  {
254  handle = c4_mapgen_handle_new(
255  filename,
256  source,
257  script_path,
258  _mape_material_map_get_handle(material_map),
259  _mape_texture_map_get_handle(texture_map),
260  width,
261  height
262  );
263 
264  break;
265  case MAPE_MAPGEN_MAP_C:
267  filename,
268  source,
269  _mape_material_map_get_handle(material_map),
270  _mape_texture_map_get_handle(texture_map),
271  width,
272  height
273  );
274 
275  break;
276  default:
277  handle = NULL;
278  g_assert_not_reached();
279  break;
280  }
281 
282  error_message = c4_mapgen_handle_get_error(handle);
283  if(error_message)
284  {
285  g_set_error(
286  error,
287  mape_mapgen_error_quark(),
289  "%s",
290  error_message
291  );
292 
293  c4_mapgen_handle_free(handle);
294  return NULL;
295  }
296 
297  out_width = c4_mapgen_handle_get_width(handle);
298  out_height = c4_mapgen_handle_get_height(handle);
299 
300  pixbuf = gdk_pixbuf_new(
301  GDK_COLORSPACE_RGB,
302  FALSE,
303  8,
304  out_width,
305  out_height
306  );
307 
308  if(pixbuf == NULL)
309  {
310  g_set_error(
311  error,
312  mape_mapgen_error_quark(),
314  "Insufficient memory is available"
315  );
316 
317  c4_mapgen_handle_free(handle);
318  return NULL;
319  }
320 
321  out_p = gdk_pixbuf_get_pixels(pixbuf);
322  in_p = c4_mapgen_handle_get_map(handle);
323  out_rowstride = gdk_pixbuf_get_rowstride(pixbuf);
324  in_rowstride = c4_mapgen_handle_get_rowstride(handle);
325  datawidth = gdk_pixbuf_get_width(pixbuf) * 3;
326  memset(matclrs, 0, sizeof(matclrs) );
327 
328  for(y = 0; y < out_height; ++y)
329  {
330  for(x = 0; x < out_width; ++x)
331  {
332  matnum = *in_p;
333 
334  if(matclrs[matnum * 4] == 0)
335  {
336  mape_mapgen_read_color(
337  matclrs,
338  material_map,
339  texture_map,
340  matnum
341  );
342 
343  /* Color has been loaded */
344  matclrs[matnum * 4] = 1;
345  }
346 
347  out_p[0] = matclrs[matnum * 4 + 1];
348  out_p[1] = matclrs[matnum * 4 + 2];
349  out_p[2] = matclrs[matnum * 4 + 3];
350  ++in_p;
351  out_p += 3;
352  }
353 
354  in_p += in_rowstride - out_width;
355  out_p += out_rowstride - datawidth;
356  }
357 
358  c4_mapgen_handle_free(handle);
359  return pixbuf;
360 }
unsigned int c4_mapgen_handle_get_height(C4MapgenHandle *mapgen)
const char * c4_mapgen_handle_get_error(C4MapgenHandle *mapgen)
C4TextureMapHandle * _mape_texture_map_get_handle(MapeTextureMap *map)
Definition: texture.c:591
const unsigned char * c4_mapgen_handle_get_map(C4MapgenHandle *mapgen)
void c4_mapgen_handle_free(C4MapgenHandle *mapgen)
unsigned int c4_mapgen_handle_get_rowstride(C4MapgenHandle *mapgen)
C4MaterialMapHandle * _mape_material_map_get_handle(MapeMaterialMap *map)
Definition: material.c:396
unsigned int c4_mapgen_handle_get_width(C4MapgenHandle *mapgen)
typedefG_BEGIN_DECLS struct _C4MapgenHandle C4MapgenHandle
Definition: log-handle.h:23
C4MapgenHandle * c4_mapgen_handle_new(const char *filename, const char *source, const char *script_path, C4MaterialMapHandle *material_map, C4TextureMapHandle *texture_map, unsigned int map_width, unsigned int map_height)
C4MapgenHandle * c4_mapgen_handle_new_script(const char *filename, const char *source, C4MaterialMapHandle *material_map, C4TextureMapHandle *texture_map, unsigned int map_width, unsigned int map_height)

Here is the call graph for this function:

void mape_mapgen_set_root_group ( MapeGroup group)

mape_mapgen_set_root_group: : The root group.

Sets the root group for the map generator. This group is used to lookup the Library_Map definition.

Definition at line 169 of file mapgen.c.

References _mape_group_get_handle(), c4_mapgen_handle_set_map_library(), and mape_group_open_child().

170 {
171  MapeGroup* objects;
172  MapeGroup* libraries;
173  MapeGroup* map;
174  GError* error;
175 
176  error = NULL;
177  if(!error)
178  objects = mape_group_open_child(group, "Objects.ocd", &error);
179  if(!error)
180  libraries = mape_group_open_child(objects, "Libraries.ocd", &error);
181  if(!error)
182  map = mape_group_open_child(libraries, "Map.ocd", &error);
183 
184  /* TODO: Error reporting? */
185  if(error == NULL)
187 
188  if(error != NULL)
189  {
190  fprintf(stderr, "Failed to load Objects.ocd/Libraries.ocd/Map.ocd/Script.c: %s\n", error->message);
191  g_error_free(error);
192  }
193 }
C4GroupHandle * _mape_group_get_handle(MapeGroup *group)
Definition: group.c:682
MapeGroup * mape_group_open_child(MapeGroup *group, const gchar *entry, GError **error)
Definition: group.c:301
void c4_mapgen_handle_set_map_library(C4GroupHandle *group_handle)

Here is the call graph for this function: