OpenClonk
texture-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/C4Texture.h"
19 
20 #define TEXTURE_MAP_TO_HANDLE(texture_map) (reinterpret_cast<C4TextureMapHandle*>(texture_map))
21 #define HANDLE_TO_TEXTURE_MAP(handle) (reinterpret_cast<C4TextureMap*>(handle))
22 
23 #define GROUP_TO_HANDLE(group) (reinterpret_cast<C4GroupHandle*>(group))
24 #define HANDLE_TO_GROUP(handle) (reinterpret_cast<C4Group*>(handle))
25 
26 extern "C" {
27 
29 {
30  // Simply return a pointer to the global texture map. This is a bit stupid,
31  // but some functions in C4Landscape use the global texture map when looking
32  // up textures. This should be changed to get rid of the global variable,
33  //but yeah...
34  C4TextureMap* map = &::TextureMap;
35  map->Clear();
36  map->Init();
37  return TEXTURE_MAP_TO_HANDLE(map); //new C4TextureMap);
38 }
39 
41 {
42  //delete HANDLE_TO_TEXTURE_MAP(texture_map);
43 }
44 
45 guint c4_texture_map_handle_load_map(C4TextureMapHandle* texture_map, C4GroupHandle* group, const char* entry_name, gboolean* overload_materials, gboolean* overload_textures)
46 {
47  bool fOverloadMaterials = false;
48  bool fOverloadTextures = false;
49  guint32 retval = HANDLE_TO_TEXTURE_MAP(texture_map)->LoadMap(*HANDLE_TO_GROUP(group), entry_name, &fOverloadMaterials, &fOverloadTextures);
50  if(overload_materials) *overload_materials = fOverloadMaterials;
51  if(overload_textures) *overload_textures = fOverloadTextures;
52  return retval;
53 }
54 
55 gboolean c4_texture_map_handle_add_texture(C4TextureMapHandle* texture_map, const char* texture, guint32 avg_color)
56 {
57  gboolean result = HANDLE_TO_TEXTURE_MAP(texture_map)->AddTexture(texture, nullptr);
58  if(!result) return FALSE;
59  HANDLE_TO_TEXTURE_MAP(texture_map)->GetTexture(texture)->SetAverageColor(avg_color);
60  return TRUE;
61 }
62 
63 const char* c4_texture_map_handle_get_texture(C4TextureMapHandle* texture_map, guint index)
64 {
65  return HANDLE_TO_TEXTURE_MAP(texture_map)->GetTexture(index);
66 }
67 
68 guint32 c4_texture_handle_get_average_texture_color(C4TextureMapHandle* texture_map, const char* name)
69 {
70  return HANDLE_TO_TEXTURE_MAP(texture_map)->GetTexture(name)->GetAverageColor();
71 }
72 
73 const char* c4_texture_handle_get_entry_material_name(C4TextureMapHandle* texture_map, guint index)
74 {
75  const C4TexMapEntry* entry = HANDLE_TO_TEXTURE_MAP(texture_map)->GetEntry(index);
76  if(!entry) return nullptr;
77  return entry->GetMaterialName();
78 }
79 
80 const char* c4_texture_handle_get_entry_texture_name(C4TextureMapHandle* texture_map, guint index)
81 {
82  const C4TexMapEntry* entry = HANDLE_TO_TEXTURE_MAP(texture_map)->GetEntry(index);
83  if(!entry) return nullptr;
84  return entry->GetTextureName();
85 }
86 
87 } /* extern "C" */
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
Definition: C4Texture.h:49
const char * GetTextureName() const
Definition: C4Texture.h:61
const char * GetMaterialName() const
Definition: C4Texture.h:60
int32_t Init()
Definition: C4Texture.cpp:292
void Clear()
Definition: C4Texture.cpp:168
typedefG_BEGIN_DECLS struct _C4GroupHandle C4GroupHandle
Definition: group-handle.h:23
guint32 c4_texture_handle_get_average_texture_color(C4TextureMapHandle *texture_map, const char *name)
const char * c4_texture_handle_get_entry_material_name(C4TextureMapHandle *texture_map, guint index)
#define TEXTURE_MAP_TO_HANDLE(texture_map)
const char * c4_texture_map_handle_get_texture(C4TextureMapHandle *texture_map, guint index)
const char * c4_texture_handle_get_entry_texture_name(C4TextureMapHandle *texture_map, guint index)
gboolean c4_texture_map_handle_add_texture(C4TextureMapHandle *texture_map, const char *texture, guint32 avg_color)
C4TextureMapHandle * c4_texture_map_handle_new(void)
#define HANDLE_TO_GROUP(handle)
#define HANDLE_TO_TEXTURE_MAP(handle)
void c4_texture_map_handle_free(C4TextureMapHandle *texture_map)
guint c4_texture_map_handle_load_map(C4TextureMapHandle *texture_map, C4GroupHandle *group, const char *entry_name, gboolean *overload_materials, gboolean *overload_textures)
typedefG_BEGIN_DECLS struct _C4TextureMapHandle C4TextureMapHandle