forked from Mirrors/openclonk
GObject-ified MapeMaterialMap
parent
ba740c4296
commit
bc980ebc12
|
@ -382,6 +382,8 @@ set(OC_CLONK_SOURCES
|
||||||
set(MAPE_SOURCES
|
set(MAPE_SOURCES
|
||||||
src/mape/cpp-handles/group-handle.h
|
src/mape/cpp-handles/group-handle.h
|
||||||
src/mape/cpp-handles/group-handle.cpp
|
src/mape/cpp-handles/group-handle.cpp
|
||||||
|
src/mape/cpp-handles/material-handle.h
|
||||||
|
src/mape/cpp-handles/material-handle.cpp
|
||||||
src/mape/configfile.c
|
src/mape/configfile.c
|
||||||
src/mape/configfile.h
|
src/mape/configfile.h
|
||||||
src/mape/diskview.c
|
src/mape/diskview.c
|
||||||
|
@ -400,7 +402,7 @@ set(MAPE_SOURCES
|
||||||
src/mape/mape.c
|
src/mape/mape.c
|
||||||
src/mape/mapgen.cpp
|
src/mape/mapgen.cpp
|
||||||
src/mape/mapgen.h
|
src/mape/mapgen.h
|
||||||
src/mape/material.cpp
|
src/mape/material.c
|
||||||
src/mape/material.h
|
src/mape/material.h
|
||||||
src/mape/mattexview.c
|
src/mape/mattexview.c
|
||||||
src/mape/mattexview.h
|
src/mape/mattexview.h
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#define INC_MAPE_FORWARD_H
|
#define INC_MAPE_FORWARD_H
|
||||||
|
|
||||||
/*typedef struct MapeGroup_ MapeGroup;*/
|
/*typedef struct MapeGroup_ MapeGroup;*/
|
||||||
typedef struct MapeMaterialMap_ MapeMaterialMap;
|
/*typedef struct MapeMaterialMap_ MapeMaterialMap;*/
|
||||||
typedef struct MapeTextureMap_ MapeTextureMap;
|
typedef struct MapeTextureMap_ MapeTextureMap;
|
||||||
typedef struct MapeFileIcon_ MapeFileIcon;
|
typedef struct MapeFileIcon_ MapeFileIcon;
|
||||||
typedef struct MapeFileIconSet_ MapeFileIconSet;
|
typedef struct MapeFileIconSet_ MapeFileIconSet;
|
||||||
|
|
|
@ -1,289 +0,0 @@
|
||||||
/*
|
|
||||||
* mape - C4 Landscape.txt editor
|
|
||||||
*
|
|
||||||
* Copyright (c) 2005-2009 Armin Burgmeier
|
|
||||||
*
|
|
||||||
* Portions might be copyrighted by other authors who have contributed
|
|
||||||
* to OpenClonk.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
* See isc_license.txt for full license and disclaimer.
|
|
||||||
*
|
|
||||||
* "Clonk" is a registered trademark of Matthes Bender.
|
|
||||||
* See clonk_trademark_license.txt for full license.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MAPE_COMPILING_CPP
|
|
||||||
|
|
||||||
#include <C4Group.h>
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#include "group.h"
|
|
||||||
|
|
||||||
#define CPPGROUP(group) ((C4Group*)group->group_handle)
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
/* On Windows, / is interpreted as a directory containing the local drives
|
|
||||||
(C:\, D:\, etc.). group_handle will be NULL in this case. */
|
|
||||||
|
|
||||||
MapeGroup* mape_group_new(const gchar* path,
|
|
||||||
GError** error)
|
|
||||||
{
|
|
||||||
MapeGroup* group;
|
|
||||||
group = (MapeGroup*)malloc(sizeof(MapeGroup) );
|
|
||||||
|
|
||||||
group->group_handle = NULL;
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
group->drive_idtf = 0;
|
|
||||||
if(strcmp(path, "/") == 0)
|
|
||||||
{
|
|
||||||
//group->drive_idtf = TRUE;
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
group->group_handle = new C4Group;
|
|
||||||
if(CPPGROUP(group)->Open(path, FALSE) == FALSE)
|
|
||||||
{
|
|
||||||
g_set_error(
|
|
||||||
error,
|
|
||||||
g_quark_from_static_string("MAPE_GROUP_ERROR"),
|
|
||||||
MAPE_GROUP_ERROR_OPEN,
|
|
||||||
"Could not open '%s': %s",
|
|
||||||
path,
|
|
||||||
CPPGROUP(group)->GetError()
|
|
||||||
);
|
|
||||||
|
|
||||||
delete CPPGROUP(group);
|
|
||||||
free(group);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
MapeGroup* mape_group_new_from_parent(MapeGroup* parent,
|
|
||||||
const gchar* entry,
|
|
||||||
GError** error)
|
|
||||||
{
|
|
||||||
MapeGroup* group;
|
|
||||||
bool result;
|
|
||||||
|
|
||||||
group = (MapeGroup*)malloc(sizeof(MapeGroup) );
|
|
||||||
|
|
||||||
group->group_handle = new C4Group;
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
if(parent->group_handle == NULL)
|
|
||||||
{
|
|
||||||
result = CPPGROUP(group)->Open(entry, FALSE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
result = CPPGROUP(group)->OpenAsChild(
|
|
||||||
CPPGROUP(parent),
|
|
||||||
entry,
|
|
||||||
FALSE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result == FALSE)
|
|
||||||
{
|
|
||||||
g_set_error(
|
|
||||||
error,
|
|
||||||
g_quark_from_static_string("MAPE_GROUP_ERROR"),
|
|
||||||
MAPE_GROUP_ERROR_OPEN,
|
|
||||||
"%s",
|
|
||||||
CPPGROUP(group)->GetError()
|
|
||||||
);
|
|
||||||
|
|
||||||
delete CPPGROUP(group);
|
|
||||||
free(group);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mape_group_destroy(MapeGroup* group)
|
|
||||||
{
|
|
||||||
if(group->group_handle != NULL)
|
|
||||||
delete CPPGROUP(group);
|
|
||||||
|
|
||||||
free(group);
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar* mape_group_get_name(MapeGroup* group)
|
|
||||||
{
|
|
||||||
g_assert(group->group_handle != NULL);
|
|
||||||
return CPPGROUP(group)->GetName();
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar* mape_group_get_full_name(MapeGroup* group)
|
|
||||||
{
|
|
||||||
g_assert(group->group_handle != NULL);
|
|
||||||
// TODO: Might this corrupt memory? Should we return a copy?
|
|
||||||
return CPPGROUP(group)->GetFullName().getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean mape_group_has_entry(MapeGroup* group,
|
|
||||||
const gchar* entry)
|
|
||||||
{
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
DWORD chk_drv;
|
|
||||||
if(group->group_handle == NULL)
|
|
||||||
{
|
|
||||||
if(entry[0] == '\0') return FALSE;
|
|
||||||
if(entry[1] != ':') return FALSE;
|
|
||||||
|
|
||||||
chk_drv = 1 << (entry[0] - 'A');
|
|
||||||
if( (GetLogicalDrives() & chk_drv) != 0)
|
|
||||||
return TRUE;
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CPPGROUP(group)->ResetSearch();
|
|
||||||
return CPPGROUP(group)->FindEntry(entry) ? TRUE : FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mape_group_rewind(MapeGroup* group)
|
|
||||||
{
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
if(group->group_handle == NULL)
|
|
||||||
{
|
|
||||||
group->drive_idtf = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CPPGROUP(group)->ResetSearch();
|
|
||||||
}
|
|
||||||
|
|
||||||
gchar* mape_group_get_next_entry(MapeGroup* group)
|
|
||||||
{
|
|
||||||
gchar* buf;
|
|
||||||
bool result;
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
static const int DRV_C_SUPPORT = 26;
|
|
||||||
DWORD drv_c;
|
|
||||||
|
|
||||||
if(group->group_handle == NULL)
|
|
||||||
{
|
|
||||||
drv_c = GetLogicalDrives();
|
|
||||||
|
|
||||||
/* Find next available drive or wait for overflow */
|
|
||||||
while( (group->drive_idtf < DRV_C_SUPPORT) &&
|
|
||||||
(~drv_c & (1 << group->drive_idtf)) )
|
|
||||||
++ group->drive_idtf;
|
|
||||||
|
|
||||||
if(group->drive_idtf >= DRV_C_SUPPORT) return NULL;
|
|
||||||
|
|
||||||
buf = (char*)malloc(3 * sizeof(char) );
|
|
||||||
buf[0] = 'A' + group->drive_idtf;
|
|
||||||
buf[1] = ':'; buf[2] = '\0';
|
|
||||||
++ group->drive_idtf;
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
buf = (char*)g_malloc(_MAX_PATH);
|
|
||||||
result = CPPGROUP(group)->AccessNextEntry("*", NULL, buf, NULL);
|
|
||||||
|
|
||||||
if(result == false)
|
|
||||||
g_free(buf);
|
|
||||||
|
|
||||||
return result ? buf : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
guchar* mape_group_load_entry(MapeGroup* group,
|
|
||||||
gsize* size,
|
|
||||||
GError** error)
|
|
||||||
{
|
|
||||||
gsize s;
|
|
||||||
guchar* res;
|
|
||||||
|
|
||||||
s = CPPGROUP(group)->AccessedEntrySize();
|
|
||||||
res = (guchar*)g_malloc(s);
|
|
||||||
if(!CPPGROUP(group)->Read((char*)res, s))
|
|
||||||
{
|
|
||||||
g_set_error(
|
|
||||||
error,
|
|
||||||
g_quark_from_static_string("MAPE_GROUP_ERROR"),
|
|
||||||
MAPE_GROUP_ERROR_READ,
|
|
||||||
"%s",
|
|
||||||
CPPGROUP(group)->GetError()
|
|
||||||
);
|
|
||||||
|
|
||||||
g_free(res);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(size != NULL) *size = s;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean mape_group_is_folder(MapeGroup* group)
|
|
||||||
{
|
|
||||||
g_assert(group->group_handle != NULL);
|
|
||||||
int status = CPPGROUP(group)->GetStatus();
|
|
||||||
if(status == GRPF_Folder) return TRUE;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean mape_group_is_child_folder(MapeGroup* group,
|
|
||||||
const gchar* child)
|
|
||||||
{
|
|
||||||
gchar* filename;
|
|
||||||
const gchar* ext;
|
|
||||||
gboolean result;
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
/* Drives are always folders */
|
|
||||||
if(group->group_handle == NULL)
|
|
||||||
return TRUE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Check for C4? extension
|
|
||||||
ext = strrchr(child, '.');
|
|
||||||
if(ext != NULL)
|
|
||||||
{
|
|
||||||
if(stricmp(ext, ".c4s") == 0 ||
|
|
||||||
stricmp(ext, ".c4d") == 0 ||
|
|
||||||
stricmp(ext, ".c4f") == 0 ||
|
|
||||||
stricmp(ext, ".c4g") == 0)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Packed directories are not supported
|
|
||||||
if(CPPGROUP(group)->GetStatus() == GRPF_File)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
// No C4Group folder: Check for regular directory
|
|
||||||
filename = g_build_filename(
|
|
||||||
CPPGROUP(group)->GetName(),
|
|
||||||
child,
|
|
||||||
NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
result = g_file_test(
|
|
||||||
filename,
|
|
||||||
G_FILE_TEST_IS_DIR
|
|
||||||
);
|
|
||||||
|
|
||||||
g_free(filename);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -23,10 +23,15 @@
|
||||||
#include <C4Material.h>
|
#include <C4Material.h>
|
||||||
#include <C4MapCreatorS2.h>
|
#include <C4MapCreatorS2.h>
|
||||||
|
|
||||||
|
#include <gdk/gdk.h>
|
||||||
|
|
||||||
|
#include "mape/cpp-handles/material-handle.h"
|
||||||
#include "mape/mapgen.h"
|
#include "mape/mapgen.h"
|
||||||
|
|
||||||
|
extern "C" C4MaterialHandle* _mape_material_map_get_handle(MapeMaterialMap*);
|
||||||
|
|
||||||
#define CPPTEXMAP(map) ((C4TextureMap*)map->handle)
|
#define CPPTEXMAP(map) ((C4TextureMap*)map->handle)
|
||||||
#define CPPMATMAP(map) ((C4MaterialMap*)map->handle)
|
#define CPPMATMAP(map) (reinterpret_cast<C4MaterialMap*>(_mape_material_map_get_handle(map)))
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
@ -46,8 +51,19 @@ static void mape_mapgen_read_color(guint8* dest,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* TODO: matnum is actually texmap entry, so find matnum from
|
||||||
|
* it. Actually we don't need to know the material
|
||||||
|
* actually, just get color from texture + render... */
|
||||||
mat = mape_material_map_get_material(material_map, matnum - 1);
|
mat = mape_material_map_get_material(material_map, matnum - 1);
|
||||||
color = mape_material_get_color(mat);
|
|
||||||
|
/* TODO: Read color from texture, needs TexMap lookup */
|
||||||
|
color.red = 0xffff;
|
||||||
|
color.green = 0xffff;
|
||||||
|
color.blue = 0xffff;
|
||||||
|
|
||||||
|
/* TODO: Make this matmap-owned,
|
||||||
|
* we can't realloc mat for each pixel! */
|
||||||
|
mape_material_free(mat);
|
||||||
|
|
||||||
dest[matnum * 4 + 1] = color.red * 0xff / 0xffff;
|
dest[matnum * 4 + 1] = color.red * 0xff / 0xffff;
|
||||||
dest[matnum * 4 + 2] = color.green * 0xff / 0xffff;
|
dest[matnum * 4 + 2] = color.green * 0xff / 0xffff;
|
||||||
|
|
|
@ -0,0 +1,417 @@
|
||||||
|
/*
|
||||||
|
* mape - C4 Landscape.txt editor
|
||||||
|
*
|
||||||
|
* Copyright (c) 2005-2009 Armin Burgmeier
|
||||||
|
*
|
||||||
|
* Portions might be copyrighted by other authors who have contributed
|
||||||
|
* to OpenClonk.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
* See isc_license.txt for full license and disclaimer.
|
||||||
|
*
|
||||||
|
* "Clonk" is a registered trademark of Matthes Bender.
|
||||||
|
* See clonk_trademark_license.txt for full license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:mape-material-mape
|
||||||
|
* @title: MapeMaterialMap
|
||||||
|
* @short_description: C4MaterialMap interface
|
||||||
|
* @include: mape/material.h
|
||||||
|
* @stability: Unstable
|
||||||
|
*
|
||||||
|
* #MapeMaterialMap is a simple GObject-based interface to C4MaterialMap.
|
||||||
|
* It supports loading a material map from a Material.c4g material_map file. It can
|
||||||
|
* load multiple files, with newer entries overloading previous ones in case
|
||||||
|
* of name clashes to support material overloading.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "mape/cpp-handles/material-handle.h"
|
||||||
|
#include "mape/material.h"
|
||||||
|
|
||||||
|
/* Declare private API */
|
||||||
|
C4GroupHandle*
|
||||||
|
_mape_group_get_handle(MapeGroup* group);
|
||||||
|
|
||||||
|
C4MaterialHandle*
|
||||||
|
_mape_material_map_get_handle(MapeMaterialMap* map);
|
||||||
|
|
||||||
|
struct _MapeMaterial {
|
||||||
|
MapeMaterialMap* map;
|
||||||
|
unsigned int mat_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct _MapeMaterialMapPrivate MapeMaterialMapPrivate;
|
||||||
|
struct _MapeMaterialMapPrivate {
|
||||||
|
C4MaterialHandle* handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
PROP_0,
|
||||||
|
|
||||||
|
/* read only */
|
||||||
|
PROP_N_MATERIALS
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAPE_MATERIAL_MAP_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), MAPE_TYPE_MATERIAL_MAP, MapeMaterialMapPrivate))
|
||||||
|
|
||||||
|
static GQuark mape_material_map_error_quark;
|
||||||
|
|
||||||
|
G_DEFINE_TYPE(MapeMaterialMap, mape_material_map, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MapeMaterial
|
||||||
|
*/
|
||||||
|
|
||||||
|
static MapeMaterial*
|
||||||
|
mape_material_new(MapeMaterialMap* map,
|
||||||
|
guint mat_index)
|
||||||
|
{
|
||||||
|
MapeMaterial* material;
|
||||||
|
|
||||||
|
material = g_slice_new(MapeMaterial);
|
||||||
|
material->map = map;
|
||||||
|
material->mat_index = mat_index;
|
||||||
|
|
||||||
|
g_object_ref(map);
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GObject overrides.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void
|
||||||
|
mape_material_map_init(MapeMaterialMap* material_map)
|
||||||
|
{
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(material_map);
|
||||||
|
|
||||||
|
priv->handle = c4_material_handle_new();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mape_material_map_finalize(GObject* object)
|
||||||
|
{
|
||||||
|
MapeMaterialMap* material_map;
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
|
||||||
|
material_map = MAPE_MATERIAL_MAP(object);
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(material_map);
|
||||||
|
|
||||||
|
c4_material_handle_free(priv->handle);
|
||||||
|
G_OBJECT_CLASS(mape_material_map_parent_class)->finalize(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mape_material_map_set_property(GObject* object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue* value,
|
||||||
|
GParamSpec* pspec)
|
||||||
|
{
|
||||||
|
MapeMaterialMap* material_map;
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
|
||||||
|
material_map = MAPE_MATERIAL_MAP(object);
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(material_map);
|
||||||
|
|
||||||
|
switch(prop_id)
|
||||||
|
{
|
||||||
|
/* we have only readonly properties */
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(value, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mape_material_map_get_property(GObject* object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue* value,
|
||||||
|
GParamSpec* pspec)
|
||||||
|
{
|
||||||
|
MapeMaterialMap* material_map;
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
|
||||||
|
material_map = MAPE_MATERIAL_MAP(object);
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(material_map);
|
||||||
|
|
||||||
|
switch(prop_id)
|
||||||
|
{
|
||||||
|
case PROP_N_MATERIALS:
|
||||||
|
g_value_set_uint(value, c4_material_handle_get_num(priv->handle));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gype registration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void
|
||||||
|
mape_material_map_class_init(MapeMaterialMapClass *class)
|
||||||
|
{
|
||||||
|
GObjectClass* object_class;
|
||||||
|
|
||||||
|
object_class = G_OBJECT_CLASS(class);
|
||||||
|
mape_material_map_parent_class =
|
||||||
|
G_OBJECT_CLASS(g_type_class_peek_parent(class));
|
||||||
|
g_type_class_add_private(class, sizeof(MapeMaterialMapPrivate));
|
||||||
|
|
||||||
|
object_class->finalize = mape_material_map_finalize;
|
||||||
|
object_class->set_property = mape_material_map_set_property;
|
||||||
|
object_class->get_property = mape_material_map_get_property;
|
||||||
|
|
||||||
|
mape_material_map_error_quark =
|
||||||
|
g_quark_from_static_string("MAPE_MATERIAL_MAP_ERROR");
|
||||||
|
|
||||||
|
g_object_class_install_property(
|
||||||
|
object_class,
|
||||||
|
PROP_N_MATERIALS,
|
||||||
|
g_param_spec_uint(
|
||||||
|
"n-materials",
|
||||||
|
"Material count",
|
||||||
|
"The number of loaded materials",
|
||||||
|
0,
|
||||||
|
G_MAXUINT,
|
||||||
|
0,
|
||||||
|
G_PARAM_READABLE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
GType
|
||||||
|
mape_material_get_type(void)
|
||||||
|
{
|
||||||
|
static GType material_type = 0;
|
||||||
|
|
||||||
|
if(material_type == 0)
|
||||||
|
{
|
||||||
|
material_type = g_boxed_type_register_static(
|
||||||
|
"MapeMaterial",
|
||||||
|
(GBoxedCopyFunc)mape_material_copy,
|
||||||
|
(GBoxedFreeFunc)mape_material_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
return material_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Public API.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.c4g
|
||||||
|
* group files.
|
||||||
|
*
|
||||||
|
* Return Value: A new #MapeMaterialMap. Free with g_object_unref().
|
||||||
|
**/
|
||||||
|
MapeMaterialMap*
|
||||||
|
mape_material_map_new(void)
|
||||||
|
{
|
||||||
|
return MAPE_MATERIAL_MAP(g_object_new(MAPE_TYPE_MATERIAL_MAP, NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 materials in @map will be replaced by the new ones. If an error occurs
|
||||||
|
* while loading the material map the function returns %FALSE and @error is
|
||||||
|
* set.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE on success, %FALSE on failure.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
mape_material_map_load(MapeMaterialMap* map,
|
||||||
|
MapeGroup* from,
|
||||||
|
GError** error)
|
||||||
|
{
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
guint new_count;
|
||||||
|
|
||||||
|
g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), FALSE);
|
||||||
|
g_return_val_if_fail(MAPE_IS_GROUP(from), FALSE);
|
||||||
|
g_return_val_if_fail(mape_group_is_open(from), FALSE);
|
||||||
|
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(map);
|
||||||
|
|
||||||
|
new_count = c4_material_handle_load(
|
||||||
|
priv->handle, _mape_group_get_handle(from));
|
||||||
|
|
||||||
|
if(new_count > 0)
|
||||||
|
g_object_notify(G_OBJECT(map), "n-materials");
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
**/
|
||||||
|
guint
|
||||||
|
mape_material_map_get_material_count(MapeMaterialMap* map)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), 0);
|
||||||
|
return c4_material_handle_get_num(MAPE_MATERIAL_MAP_PRIVATE(map)->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mape_material_map_get_material:
|
||||||
|
* @material: A #MapeMaterialMap.
|
||||||
|
* @index: A material index.
|
||||||
|
*
|
||||||
|
* Returns the entry with the given index in the map.
|
||||||
|
*
|
||||||
|
* Returns: A new #MapeMaterial to be freed with mape_material_free() when
|
||||||
|
* no longer needed.
|
||||||
|
**/
|
||||||
|
MapeMaterial*
|
||||||
|
mape_material_map_get_material(MapeMaterialMap* map,
|
||||||
|
guint index)
|
||||||
|
{
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
|
||||||
|
g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), NULL);
|
||||||
|
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(map);
|
||||||
|
g_return_val_if_fail(index < c4_material_handle_get_num(priv->handle), NULL);
|
||||||
|
|
||||||
|
return mape_material_new(map, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/*
|
||||||
|
* mape_material_map_get_material_by_name:
|
||||||
|
* @map: A #MapeMaterialMap.
|
||||||
|
* @name: The name of the material to retrieve.
|
||||||
|
*
|
||||||
|
* Returns the material in the map which has the given name, if any. If there
|
||||||
|
* is no such material the function returns %NULL.
|
||||||
|
*
|
||||||
|
* Returns: A new #MapeMaterial to be freed with mape_material_free() when
|
||||||
|
* no longer needed, or %NULL.
|
||||||
|
*/
|
||||||
|
MapeMaterial*
|
||||||
|
mape_material_map_get_material_by_name(MapeMaterialMap* map,
|
||||||
|
const gchar* name)
|
||||||
|
{
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
const gchar* cur_name;
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), NULL);
|
||||||
|
g_return_val_if_fail(name != NULL, NULL);
|
||||||
|
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(map);
|
||||||
|
|
||||||
|
for(i = 0; i < c4_material_handle_get_num(priv->handle); ++i)
|
||||||
|
{
|
||||||
|
cur_name = c4_material_handle_get_name(priv->handle, i);
|
||||||
|
if(g_ascii_strcasecmp(cur_name, name) == 0)
|
||||||
|
return mape_material_new(map, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mape_material_copy:
|
||||||
|
* @material: A #MapeMaterial.
|
||||||
|
*
|
||||||
|
* Creates a copy of @material.
|
||||||
|
*
|
||||||
|
* Returns: A new #MapeMaterial to be freed with mape_material_free() when
|
||||||
|
* no longer needed.
|
||||||
|
*/
|
||||||
|
MapeMaterial*
|
||||||
|
mape_material_copy(const MapeMaterial* material)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(material != NULL, NULL);
|
||||||
|
return mape_material_new(material->map, material->mat_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mape_material_free:
|
||||||
|
* @material: A #MapeMaterial.
|
||||||
|
*
|
||||||
|
* Releases all ressources taken up by @material.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
mape_material_free(MapeMaterial* material)
|
||||||
|
{
|
||||||
|
g_return_if_fail(material != NULL);
|
||||||
|
|
||||||
|
g_object_unref(material->map);
|
||||||
|
g_slice_free(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.
|
||||||
|
*/
|
||||||
|
const gchar*
|
||||||
|
mape_material_get_name(const MapeMaterial* material)
|
||||||
|
{
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
|
||||||
|
g_return_val_if_fail(material != NULL, NULL);
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(material->map);
|
||||||
|
|
||||||
|
return c4_material_handle_get_name(priv->handle, material->mat_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
const gchar*
|
||||||
|
mape_material_get_texture_overlay(const MapeMaterial* material)
|
||||||
|
{
|
||||||
|
MapeMaterialMapPrivate* priv;
|
||||||
|
|
||||||
|
g_return_val_if_fail(material != NULL, NULL);
|
||||||
|
priv = MAPE_MATERIAL_MAP_PRIVATE(material->map);
|
||||||
|
|
||||||
|
return c4_material_handle_get_texture_overlay(
|
||||||
|
priv->handle, material->mat_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This function is for internal use only */
|
||||||
|
C4MaterialHandle*
|
||||||
|
_mape_material_map_get_handle(MapeMaterialMap* map)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(MAPE_IS_MATERIAL_MAP(map), NULL);
|
||||||
|
return MAPE_MATERIAL_MAP_PRIVATE(map)->handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set et sw=2 ts=2: */
|
|
@ -1,129 +0,0 @@
|
||||||
/*
|
|
||||||
* mape - C4 Landscape.txt editor
|
|
||||||
*
|
|
||||||
* Copyright (c) 2005-2009 Armin Burgmeier
|
|
||||||
*
|
|
||||||
* Portions might be copyrighted by other authors who have contributed
|
|
||||||
* to OpenClonk.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
* See isc_license.txt for full license and disclaimer.
|
|
||||||
*
|
|
||||||
* "Clonk" is a registered trademark of Matthes Bender.
|
|
||||||
* See clonk_trademark_license.txt for full license.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: Move this to an extra file:
|
|
||||||
|
|
||||||
#include <C4Application.h>
|
|
||||||
#include <C4Console.h>
|
|
||||||
#include <C4FullScreen.h>
|
|
||||||
#include <C4Game.h>
|
|
||||||
#include <C4Network2.h>
|
|
||||||
|
|
||||||
C4Application Application;
|
|
||||||
C4Console Console;
|
|
||||||
C4FullScreen FullScreen;
|
|
||||||
C4Game Game;
|
|
||||||
C4Network2 Network;
|
|
||||||
|
|
||||||
|
|
||||||
#define MAPE_COMPILING_CPP
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <C4Material.h>
|
|
||||||
|
|
||||||
#include "mape/cpp-handles/group-handle.h"
|
|
||||||
|
|
||||||
#include "mape/group.h"
|
|
||||||
#include "mape/material.h"
|
|
||||||
|
|
||||||
#define CPPMAT(mat) ( (C4Material*)mat)
|
|
||||||
#define CPPMATMAP(map) ( (C4MaterialMap*)map->handle)
|
|
||||||
|
|
||||||
extern "C" C4GroupHandle* _mape_group_get_handle(MapeGroup*);
|
|
||||||
#define CPPGROUP(group) (reinterpret_cast<C4Group*>(_mape_group_get_handle(group)))
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
MapeMaterialMap* mape_material_map_new(MapeGroup* base,
|
|
||||||
MapeGroup* overload_from,
|
|
||||||
GError** error)
|
|
||||||
{
|
|
||||||
MapeMaterialMap* map;
|
|
||||||
map = (MapeMaterialMap*)malloc(sizeof(MapeMaterialMap) );
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// TODO: Make sure overloading works as expected...
|
|
||||||
map->handle = new C4MaterialMap;
|
|
||||||
CPPMATMAP(map)->Load(*CPPGROUP(base));
|
|
||||||
if(overload_from != NULL)
|
|
||||||
CPPMATMAP(map)->Load(*CPPGROUP(overload_from));
|
|
||||||
}
|
|
||||||
catch(const std::exception& e)
|
|
||||||
{
|
|
||||||
g_set_error(
|
|
||||||
error,
|
|
||||||
g_quark_from_static_string("MAPE_MATERIAL_ERROR"),
|
|
||||||
MAPE_MATERIAL_ERROR_FAILED,
|
|
||||||
"%s",
|
|
||||||
e.what()
|
|
||||||
);
|
|
||||||
|
|
||||||
free(map);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mape_material_map_destroy(MapeMaterialMap* map)
|
|
||||||
{
|
|
||||||
delete CPPMATMAP(map);
|
|
||||||
free(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int mape_material_map_get_material_count(MapeMaterialMap* map)
|
|
||||||
{
|
|
||||||
return CPPMATMAP(map)->Num;
|
|
||||||
}
|
|
||||||
|
|
||||||
MapeMaterial* mape_material_map_get_material(MapeMaterialMap* map,
|
|
||||||
unsigned int index)
|
|
||||||
{
|
|
||||||
return (MapeMaterial*)&CPPMATMAP(map)->Map[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
MapeMaterial* mape_material_map_get_material_by_string(MapeMaterialMap* map,
|
|
||||||
const char* mat_name)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
for(i = 0; i < CPPMATMAP(map)->Num; ++ i)
|
|
||||||
if(stricmp(CPPMATMAP(map)->Map[i].Name, mat_name) == 0)
|
|
||||||
return (MapeMaterial*)&CPPMATMAP(map)->Map[i];
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* mape_material_get_name(MapeMaterial* material)
|
|
||||||
{
|
|
||||||
return CPPMAT(material)->Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
GdkColor mape_material_get_color(MapeMaterial* material)
|
|
||||||
{
|
|
||||||
// TODO: Color field in C4Material is gone. Read from texture?
|
|
||||||
GdkColor color = {
|
|
||||||
0,
|
|
||||||
/*CPPMAT(material)->Color[0]*/0xff * 0xffff / 0xff,
|
|
||||||
/*CPPMAT(material)->Color[1]*/0xff * 0xffff / 0xff,
|
|
||||||
/*CPPMAT(material)->Color[2]*/0xff * 0xffff / 0xff
|
|
||||||
};
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C"
|
|
|
@ -15,46 +15,102 @@
|
||||||
* See clonk_trademark_license.txt for full license.
|
* See clonk_trademark_license.txt for full license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef INC_MAPE_MATERIAL_H
|
#ifndef INC_MAPE_MATERIAL_MAP_H
|
||||||
#define INC_MAPE_MATERIAL_H
|
#define INC_MAPE_MATERIAL_MAP_H
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
#include "mape/forward.h"
|
|
||||||
#include "mape/group.h"
|
#include "mape/group.h"
|
||||||
|
|
||||||
/* Simple C-based interface to C4MaterialMap */
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#ifdef MAPE_COMPILING_CPP
|
#define MAPE_TYPE_MATERIAL_MAP (mape_material_map_get_type())
|
||||||
extern "C" {
|
#define MAPE_MATERIAL_MAP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MAPE_TYPE_MATERIAL_MAP, MapeMaterialMap))
|
||||||
#endif
|
#define MAPE_MATERIAL_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), MAPE_TYPE_MATERIAL_MAP, MapeMaterialMapClass))
|
||||||
|
#define MAPE_IS_MATERIAL_MAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MAPE_TYPE_MATERIAL_MAP))
|
||||||
|
#define MAPE_IS_MATERIAL_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MAPE_TYPE_MATERIAL_MAP))
|
||||||
|
#define MAPE_MATERIAL_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MAPE_TYPE_MATERIAL_MAP, MapeMaterialMapClass))
|
||||||
|
|
||||||
typedef enum MapeMaterialError_ {
|
#define MAPE_TYPE_MATERIAL (mape_material_get_type())
|
||||||
MAPE_MATERIAL_ERROR_FAILED
|
|
||||||
} MapeMaterialError;
|
|
||||||
|
|
||||||
typedef void MapeMaterial;
|
typedef struct _MapeMaterial MapeMaterial;
|
||||||
|
|
||||||
struct MapeMaterialMap_ {
|
typedef struct _MapeMaterialMap MapeMaterialMap;
|
||||||
void* handle;
|
typedef struct _MapeMaterialMapClass MapeMaterialMapClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MapeMaterialMapError:
|
||||||
|
* @MAPE_MATERIAL_MAP_ERROR_LOAD: An error occured when loading a material map.
|
||||||
|
*
|
||||||
|
* These errors are from the MAPE_MATERIAL_MAP_ERROR error domain. They can
|
||||||
|
* occur when operating on material maps.
|
||||||
|
*/
|
||||||
|
typedef enum _MapeMaterialMapError {
|
||||||
|
MAPE_MATERIAL_MAP_ERROR_LOAD
|
||||||
|
} MapeMaterialMapError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MapeMaterialMapClass:
|
||||||
|
*
|
||||||
|
* This structure does not contain any public fields.
|
||||||
|
*/
|
||||||
|
struct _MapeMaterialMapClass {
|
||||||
|
/*< private >*/
|
||||||
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
MapeMaterialMap* mape_material_map_new(MapeGroup* base,
|
/**
|
||||||
MapeGroup* overload_from,
|
* MapeMaterialMap:
|
||||||
GError** error);
|
*
|
||||||
void mape_material_map_destroy(MapeMaterialMap* map);
|
* #MapeMaterialMap is an opaque data type. You should only access it via the
|
||||||
|
* public API functions.
|
||||||
|
*/
|
||||||
|
struct _MapeMaterialMap {
|
||||||
|
/*< private >*/
|
||||||
|
GObject parent;
|
||||||
|
};
|
||||||
|
|
||||||
unsigned int mape_material_map_get_material_count(MapeMaterialMap* map);
|
GType
|
||||||
MapeMaterial* mape_material_map_get_material(MapeMaterialMap* map,
|
mape_material_get_type(void) G_GNUC_CONST;
|
||||||
unsigned int index);
|
|
||||||
MapeMaterial* mape_material_map_get_material_by_string(MapeMaterialMap* map,
|
|
||||||
const char* mat_name);
|
|
||||||
|
|
||||||
const char* mape_material_get_name(MapeMaterial* material);
|
GType
|
||||||
GdkColor mape_material_get_color(MapeMaterial* material);
|
mape_material_map_get_type(void) G_GNUC_CONST;
|
||||||
|
|
||||||
#ifdef MAPE_COMPILING_CPP
|
MapeMaterialMap*
|
||||||
} /* extern "C" */
|
mape_material_map_new(void);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mape_material_map_load(MapeMaterialMap* map,
|
||||||
|
MapeGroup* from,
|
||||||
|
GError** error);
|
||||||
|
|
||||||
|
guint
|
||||||
|
mape_material_map_get_material_count(MapeMaterialMap* map);
|
||||||
|
|
||||||
|
MapeMaterial*
|
||||||
|
mape_material_map_get_material(MapeMaterialMap* map,
|
||||||
|
guint index);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
MapeMaterial*
|
||||||
|
mape_material_map_get_material_by_name(MapeMaterialMap* map,
|
||||||
|
const gchar* name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* INC_MAPE_MATERIAL_H */
|
MapeMaterial*
|
||||||
|
mape_material_copy(const MapeMaterial* material);
|
||||||
|
|
||||||
|
void
|
||||||
|
mape_material_free(MapeMaterial* material);
|
||||||
|
|
||||||
|
const gchar*
|
||||||
|
mape_material_get_name(const MapeMaterial* material);
|
||||||
|
|
||||||
|
const gchar*
|
||||||
|
mape_material_get_texture_overlay(const MapeMaterial* material);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* INC_MAPE_MATERIAL_MAP_H */
|
||||||
|
|
||||||
|
/* vim:set et sw=2 ts=2: */
|
||||||
|
|
|
@ -82,7 +82,7 @@ MapeMatTexView* mape_mat_tex_view_new(MapeFileIconSet* icon_set,
|
||||||
void mape_mat_tex_view_destroy(MapeMatTexView* view)
|
void mape_mat_tex_view_destroy(MapeMatTexView* view)
|
||||||
{
|
{
|
||||||
if(view->mat_map != NULL)
|
if(view->mat_map != NULL)
|
||||||
mape_material_map_destroy(view->mat_map);
|
g_object_unref(view->mat_map);
|
||||||
if(view->tex_map != NULL)
|
if(view->tex_map != NULL)
|
||||||
mape_texture_map_destroy(view->tex_map);
|
mape_texture_map_destroy(view->tex_map);
|
||||||
|
|
||||||
|
@ -103,17 +103,30 @@ gboolean mape_mat_tex_view_reload(MapeMatTexView* view,
|
||||||
MapeMaterial* mat;
|
MapeMaterial* mat;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
new_mat_map = mape_material_map_new(base_group, overload_from, error);
|
new_mat_map = mape_material_map_new();
|
||||||
if(new_mat_map == NULL) return FALSE;
|
if(!mape_material_map_load(new_mat_map, base_group, error))
|
||||||
|
{
|
||||||
|
g_object_unref(new_mat_map);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(overload_from)
|
||||||
|
{
|
||||||
|
if(!mape_material_map_load(new_mat_map, overload_from, error))
|
||||||
|
{
|
||||||
|
g_object_unref(new_mat_map);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
new_tex_map = mape_texture_map_new(base_group, overload_from, error);
|
new_tex_map = mape_texture_map_new(base_group, overload_from, error);
|
||||||
if(new_tex_map == NULL)
|
if(new_tex_map == NULL)
|
||||||
{
|
{
|
||||||
mape_material_map_destroy(new_mat_map);
|
g_object_unref(new_mat_map);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(view->mat_map != NULL) mape_material_map_destroy(view->mat_map);
|
if(view->mat_map != NULL) g_object_unref(view->mat_map);
|
||||||
if(view->tex_map != NULL) mape_texture_map_destroy(view->tex_map);
|
if(view->tex_map != NULL) mape_texture_map_destroy(view->tex_map);
|
||||||
view->mat_map = new_mat_map; view->tex_map = new_tex_map;
|
view->mat_map = new_mat_map; view->tex_map = new_tex_map;
|
||||||
|
|
||||||
|
@ -132,6 +145,8 @@ gboolean mape_mat_tex_view_reload(MapeMatTexView* view,
|
||||||
mape_file_icon_get(icon),
|
mape_file_icon_get(icon),
|
||||||
mape_material_get_name(mat)
|
mape_material_get_name(mat)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
mape_material_free(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
mape_icon_view_clear(view->view_tex);
|
mape_icon_view_clear(view->view_tex);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "mape/forward.h"
|
#include "mape/forward.h"
|
||||||
#include "mape/group.h"
|
#include "mape/group.h"
|
||||||
|
#include "mape/material.h"
|
||||||
|
|
||||||
struct MapeMatTexView_ {
|
struct MapeMatTexView_ {
|
||||||
GtkWidget* notebook;
|
GtkWidget* notebook;
|
||||||
|
|
|
@ -17,6 +17,21 @@
|
||||||
|
|
||||||
#define MAPE_COMPILING_CPP
|
#define MAPE_COMPILING_CPP
|
||||||
|
|
||||||
|
// TODO: Move this to an extra file:
|
||||||
|
|
||||||
|
#include <C4Application.h>
|
||||||
|
#include <C4Console.h>
|
||||||
|
#include <C4FullScreen.h>
|
||||||
|
#include <C4Game.h>
|
||||||
|
#include <C4Network2.h>
|
||||||
|
|
||||||
|
C4Application Application;
|
||||||
|
C4Console Console;
|
||||||
|
C4FullScreen FullScreen;
|
||||||
|
C4Game Game;
|
||||||
|
C4Network2 Network;
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <C4Include.h>
|
#include <C4Include.h>
|
||||||
#include <C4Random.h>
|
#include <C4Random.h>
|
||||||
|
|
Loading…
Reference in New Issue