OpenClonk
material-handle.cpp
Go to the documentation of this file.
1 /*
2  * mape - C4 Landscape.txt editor
3  *
4  * Copyright (c) 2005-2009, Armin Burgmeier
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #include "C4Include.h"
17 #include "landscape/C4Material.h"
18 #include "landscape/C4Texture.h"
20 
21 #define MATERIAL_MAP_TO_HANDLE(material_map) (reinterpret_cast<C4MaterialMapHandle*>(material_map))
22 #define HANDLE_TO_MATERIAL_MAP(handle) (reinterpret_cast<C4MaterialMap*>(handle))
23 
24 #define MATERIAL_TO_HANDLE(material) (reinterpret_cast<C4MaterialHandle*>(material))
25 #define HANDLE_TO_MATERIAL(handle) (reinterpret_cast<C4Material*>(handle))
26 
27 #define HANDLE_TO_TEXTURE_MAP(handle) (reinterpret_cast<C4TextureMap*>(handle))
28 
29 #define GROUP_TO_HANDLE(group) (reinterpret_cast<C4GroupHandle*>(group))
30 #define HANDLE_TO_GROUP(handle) (reinterpret_cast<C4Group*>(handle))
31 
32 extern "C" {
33 
35 {
36  // Simply return a pointer to the global material map. This is a bit stupid,
37  // but when looking up a material-texture combination, C4TextureMap uses the
38  // global material map for the material lookup when the default texture is
39  // requested. This should be changed to get rid of the global variable, but yeah...
41  map->Clear();
42  return MATERIAL_MAP_TO_HANDLE(map); //new C4MaterialMap);
43 }
44 
46 {
47  //delete HANDLE_TO_MATERIAL_MAP(material_map);
48 }
49 
51 {
52  return HANDLE_TO_MATERIAL_MAP(material_map)->Load(*HANDLE_TO_GROUP(group));
53 }
54 
56 {
57  // Don't call the official crossmap function since it tries to load some surfaces.
58  // All we need is the default texture.
59  for(int i = 0; i < HANDLE_TO_MATERIAL_MAP(material_map)->Num; ++i)
60  {
61  C4Material* mat = &HANDLE_TO_MATERIAL_MAP(material_map)->Map[i];
62  const char* overlay = mat->sTextureOverlay.getData();
63  if(!overlay || *overlay == '\0')
64  {
65  int first_tex_map_entry = HANDLE_TO_TEXTURE_MAP(texture_map)->GetIndex(mat->Name, nullptr, false);
66  overlay = HANDLE_TO_TEXTURE_MAP(texture_map)->GetEntry(first_tex_map_entry)->GetTextureName();
67  }
68 
69  if(overlay)
70  mat->DefaultMatTex = HANDLE_TO_TEXTURE_MAP(texture_map)->GetIndex(mat->Name, overlay, true);
71  }
72 }
73 
75 {
76  return HANDLE_TO_MATERIAL_MAP(material_map)->Num;
77 }
78 
80 {
81  g_assert(index < (guint)(HANDLE_TO_MATERIAL_MAP(material_map)->Num));
82  return MATERIAL_TO_HANDLE(&HANDLE_TO_MATERIAL_MAP(material_map)->Map[index]);
83 }
84 
86 {
87  return HANDLE_TO_MATERIAL(material)->Name;
88 }
90 {
91  return HANDLE_TO_MATERIAL(material)->sTextureOverlay.getData();
92 }
93 
94 } /* extern "C" */
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
char Name[C4M_MaxName+1]
Definition: C4Material.h:89
StdCopyStrBuf sTextureOverlay
Definition: C4Material.h:114
int32_t DefaultMatTex
Definition: C4Material.h:155
const char * getData() const
Definition: StdBuf.h:442
typedefG_BEGIN_DECLS struct _C4GroupHandle C4GroupHandle
Definition: group-handle.h:23
const gchar * c4_material_handle_get_texture_overlay(C4MaterialHandle *material)
void c4_material_map_crossmap_materials(C4MaterialMapHandle *material_map, C4TextureMapHandle *texture_map)
C4MaterialMapHandle * c4_material_map_handle_new(void)
#define HANDLE_TO_MATERIAL_MAP(handle)
#define HANDLE_TO_MATERIAL(handle)
C4MaterialHandle * c4_material_map_handle_get_material(C4MaterialMapHandle *material_map, guint index)
void c4_material_map_handle_free(C4MaterialMapHandle *material_map)
guint c4_material_map_handle_get_num(C4MaterialMapHandle *material_map)
const gchar * c4_material_handle_get_name(C4MaterialHandle *material)
#define MATERIAL_MAP_TO_HANDLE(material_map)
#define HANDLE_TO_GROUP(handle)
#define HANDLE_TO_TEXTURE_MAP(handle)
#define MATERIAL_TO_HANDLE(material)
guint c4_material_map_handle_load(C4MaterialMapHandle *material_map, C4GroupHandle *group)
typedefG_BEGIN_DECLS struct _C4MaterialHandle C4MaterialHandle
struct _C4MaterialMapHandle C4MaterialMapHandle
typedefG_BEGIN_DECLS struct _C4TextureMapHandle C4TextureMapHandle