]> git.draconx.ca Git - upkg.git/blob - src/engine/texture.c
uobject: Rename U_OBJECT_TYPE to U_TYPE_OBJECT.
[upkg.git] / src / engine / texture.c
1 /*
2  *  upkg: tool for manipulating Unreal Tournament packages.
3  *  Copyright © 2009-2011 Nick Bowler
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <glib-object.h>
22
23 #include <uobject/uobject.h>
24 #include <uobject/exportable.h>
25 #include "texture.h"
26 #include "palette.h"
27 #include "upkg.h"
28
29 #define TEXTURE_GET_PRIV(o) \
30         G_TYPE_INSTANCE_GET_PRIVATE(o, ENGINE_TEXTURE_TYPE, struct texture_priv)
31
32 enum {
33         PROP_0,
34         PROP_USIZE,
35         PROP_VSIZE,
36         PROP_UCLAMP,
37         PROP_VCLAMP,
38         PROP_UBITS,
39         PROP_VBITS,
40         PROP_PALETTE,
41 };
42
43 struct texture_priv {
44         unsigned type;
45
46         struct upkg_file *f;
47         size_t base, len;
48
49         unsigned char buf[2048];
50         unsigned long nbuf;
51 };
52
53 void exportable_init(UObjectExportable *e)
54 {
55 }
56
57 G_DEFINE_DYNAMIC_TYPE(EngineTexture, engine_texture, U_TYPE_OBJECT);
58
59 static int deserialize(UObject *uo)
60 {
61         struct texture_priv *priv = TEXTURE_GET_PRIV(uo);
62         EngineTexture *t = ENGINE_TEXTURE(uo);
63
64         U_OBJECT_CLASS(engine_texture_parent_class)->deserialize(uo);
65
66         return 0;
67 }
68
69 void texture_register(GTypeModule *m)
70 {
71         engine_texture_register_type(m);
72 }
73
74 static void
75 set_property(GObject *o, guint id, const GValue *val, GParamSpec *spec)
76 {
77         EngineTexture *t = ENGINE_TEXTURE(o);
78
79         switch (id) {
80         case PROP_USIZE:
81                 t->usize = g_value_get_uint(val);
82                 break;
83         case PROP_VSIZE:
84                 t->vsize = g_value_get_uint(val);
85                 break;
86         case PROP_UCLAMP:
87                 t->uclamp = g_value_get_uint(val);
88                 break;
89         case PROP_VCLAMP:
90                 t->vclamp = g_value_get_uint(val);
91                 break;
92         case PROP_UBITS:
93                 t->ubits = g_value_get_uint(val);
94                 break;
95         case PROP_VBITS:
96                 t->vbits = g_value_get_uint(val);
97                 break;
98         case PROP_PALETTE:
99                 t->palette = g_value_get_object(val);
100                 break;
101         default:
102                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
103         }
104 }
105
106 static void
107 get_property(GObject *o, guint id, GValue *val, GParamSpec *spec)
108 {
109         EngineTexture *t = ENGINE_TEXTURE(o);
110
111         switch (id) {
112         case PROP_USIZE:
113                 g_value_set_uint(val, t->usize);
114                 break;
115         case PROP_VSIZE:
116                 g_value_set_uint(val, t->vsize);
117                 break;
118         case PROP_UCLAMP:
119                 g_value_set_uint(val, t->uclamp);
120                 break;
121         case PROP_VCLAMP:
122                 g_value_set_uint(val, t->vclamp);
123                 break;
124         case PROP_UBITS:
125                 g_value_set_uint(val, t->ubits);
126                 break;
127         case PROP_VBITS:
128                 g_value_set_uint(val, t->vbits);
129                 break;
130         case PROP_PALETTE:
131                 g_value_set_object(val, t->palette);
132                 break;
133         default:
134                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
135         }
136 }
137
138 static void engine_texture_init(EngineTexture *t)
139 {
140         t->usize = t->vsize = 0;
141 }
142
143 static void engine_texture_class_init(EngineTextureClass *class)
144 {
145         UObjectClass *uo = U_OBJECT_CLASS(class);
146         GObjectClass *go = G_OBJECT_CLASS(class);
147
148         g_type_class_add_private(class, sizeof (struct texture_priv));
149
150         uo->deserialize = deserialize;
151         go->set_property = set_property;
152         go->get_property = get_property;
153
154         g_object_class_install_property(go, PROP_USIZE,
155                 g_param_spec_uint("USize",
156                         "USize",
157                         "Width of the texture.",
158                         0, 2048, 0,
159                         G_PARAM_READWRITE));
160         g_object_class_install_property(go, PROP_VSIZE,
161                 g_param_spec_uint("VSize",
162                         "VSize",
163                         "Height of the texture.",
164                         0, 2048, 0,
165                         G_PARAM_READWRITE));
166         g_object_class_install_property(go, PROP_UCLAMP,
167                 g_param_spec_uint("UClamp",
168                         "UClamp",
169                         "???",
170                         0, 2048, 0,
171                         G_PARAM_READWRITE));
172         g_object_class_install_property(go, PROP_VCLAMP,
173                 g_param_spec_uint("VClamp",
174                         "VClamp",
175                         "???",
176                         0, 2048, 0,
177                         G_PARAM_READWRITE));
178         g_object_class_install_property(go, PROP_UBITS,
179                 g_param_spec_uint("UBits",
180                         "UBits",
181                         "???",
182                         0, 64, 0,
183                         G_PARAM_READWRITE));
184         g_object_class_install_property(go, PROP_VBITS,
185                 g_param_spec_uint("VBits",
186                         "VBits",
187                         "???",
188                         0, 64, 0,
189                         G_PARAM_READWRITE));
190         g_object_class_install_property(go, PROP_PALETTE,
191                 g_param_spec_object("Palette",
192                         "Palette",
193                         "Palette reference for the texture.",
194                         ENGINE_PALETTE_TYPE,
195                         G_PARAM_READWRITE));
196 }
197
198 static void engine_texture_class_finalize(EngineTextureClass *class)
199 {
200 }