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"
18 #include "mape/cpp-handles/texture-handle.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
c4_texture_map_handle_new(void)28 C4TextureMapHandle* c4_texture_map_handle_new(void)
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
c4_texture_map_handle_free(C4TextureMapHandle * texture_map)40 void c4_texture_map_handle_free(C4TextureMapHandle* texture_map)
41 {
42 //delete HANDLE_TO_TEXTURE_MAP(texture_map);
43 }
44
c4_texture_map_handle_load_map(C4TextureMapHandle * texture_map,C4GroupHandle * group,const char * entry_name,gboolean * overload_materials,gboolean * overload_textures)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
c4_texture_map_handle_add_texture(C4TextureMapHandle * texture_map,const char * texture,guint32 avg_color)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
c4_texture_map_handle_get_texture(C4TextureMapHandle * texture_map,guint index)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
c4_texture_handle_get_average_texture_color(C4TextureMapHandle * texture_map,const char * name)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
c4_texture_handle_get_entry_material_name(C4TextureMapHandle * texture_map,guint index)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
c4_texture_handle_get_entry_texture_name(C4TextureMapHandle * texture_map,guint index)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" */
88