]> git.draconx.ca Git - upkg.git/commitdiff
engine: Implement Engine.Palette.
authorNick Bowler <nbowler@draconx.ca>
Sun, 13 Mar 2011 20:37:42 +0000 (16:37 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 18 Mar 2011 22:12:38 +0000 (18:12 -0400)
src/engine/Makefile.inc
src/engine/engine.c
src/engine/palette.c [new file with mode: 0644]
src/engine/palette.h [new file with mode: 0644]

index 8930030b58b96aa392498e1bdc5cf3d821fcf6ed..8df920bc715ac1a0fdb12bb1eab007186c39632a 100644 (file)
@@ -4,10 +4,12 @@
 # notice and this notice are preserved.  This file is offered as-is,
 # without any warranty.
 
-noinst_HEADERS += engine/music.h engine/texture.h engine/music-module.h
+noinst_HEADERS += engine/texture.h engine/palette.h \
+       engine/music.h engine/music-module.h
 
 pkglib_LTLIBRARIES += engine.la
-engine_la_SOURCES   = engine/music.c engine/texture.c engine/engine.c
+engine_la_SOURCES   = engine/engine.c engine/music.c engine/texture.c \
+       engine/palette.c
 engine_la_CFLAGS    = $(GLIB_CFLAGS)
 engine_la_LIBADD    = $(GLIB_LIBS)
 engine_la_LDFLAGS   = -module -avoid-version -export-symbols-regex _LTX_
index 618634c3ca7b6e156b143b57caa027e33a96d28a..b6e7e14a7a2c2ae6a1f3ffc3d6e04ff4618285f4 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "music.h"
 #include "texture.h"
+#include "palette.h"
 
 #define init engine_LTX_init
 #define exit engine_LTX_exit
@@ -29,6 +30,7 @@ int init(GTypeModule *m)
 {
        music_register(m);
        texture_register(m);
+       palette_register(m);
        return 0;
 }
 
diff --git a/src/engine/palette.c b/src/engine/palette.c
new file mode 100644 (file)
index 0000000..65b3e31
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ *  upkg: tool for manipulating Unreal Tournament packages.
+ *  Copyright © 2011 Nick Bowler
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "palette.h"
+#include "upkg.h"
+
+G_DEFINE_DYNAMIC_TYPE(EnginePalette, engine_palette, U_OBJECT_TYPE);
+
+static int deserialize(UObject *uo)
+{
+       EnginePalette *p = ENGINE_PALETTE(uo);
+       struct upkg_file *f = uo->pkg_file;
+       unsigned char buf[16];
+       size_t rc, buflen;
+       long entries;
+
+       U_OBJECT_CLASS(engine_palette_parent_class)->deserialize(uo);
+
+       buflen = upkg_export_read(f, buf, sizeof buf);
+       rc = upkg_decode_index(&entries, buf, buflen);
+       if (rc == 0 || entries < 0)
+               return -1;
+
+       upkg_export_seek(f, rc, SEEK_SET);
+
+       p->entries = entries;
+       p->rgba = malloc(entries * sizeof p->rgba[0]);
+       if (!p->rgba)
+               return -1;
+
+       rc = upkg_export_read(f, p->rgba, entries * sizeof p->rgba[0]);
+       if (rc != entries * sizeof p->rgba[0]) {
+               free(p->rgba);
+               return -1;
+       }
+
+       printf("palette opened\n");
+       return 0;
+}
+
+void palette_register(GTypeModule *m)
+{
+       engine_palette_register_type(m);
+}
+
+static void engine_palette_init(EnginePalette *p)
+{
+       p->entries = 0;
+}
+
+static void engine_palette_class_init(EnginePaletteClass *class)
+{
+       UObjectClass *uo = U_OBJECT_CLASS(class);
+
+       uo->deserialize = deserialize;
+}
+
+static void engine_palette_class_finalize(EnginePaletteClass *class)
+{
+}
diff --git a/src/engine/palette.h b/src/engine/palette.h
new file mode 100644 (file)
index 0000000..45cbdd4
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  upkg: tool for manipulating Unreal Tournament packages.
+ *  Copyright © 2011 Nick Bowler
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ENGINE_PALETTE_H_
+#define ENGINE_PALETTE_H_
+
+#include <uobject/uobject.h>
+
+#define ENGINE_PALETTE_TYPE (engine_palette_get_type())
+#define ENGINE_PALETTE(obj) \
+       G_TYPE_CHECK_INSTANCE_CAST(obj, ENGINE_PALETTE_TYPE, EnginePalette)
+#define ENGINE_PALETTE_CLASS(class) \
+       G_TYPE_CHECK_CLASS_CAST(class, ENGINE_PALETTE_TYPE, EnginePaletteClass)
+#define ENGINE_IS_PALETTE(obj) \
+       G_TYPE_CHECK_INSTANCE_TYPE(obj, ENGINE_PALETTE_TYPE)
+#define ENGINE_IS_PALETTE_CLASS(class) \
+       G_TYPE_CHECK_CLASS_TYPE(class, ENGINE_PALETTE_TYPE, EnginePaletteClass)
+
+typedef struct EnginePalette      EnginePalette;
+typedef struct EnginePaletteClass EnginePaletteClass;
+
+struct EnginePalette {
+       UObject parent;
+
+       unsigned entries;
+       unsigned char (*rgba)[4];
+};
+
+struct EnginePaletteClass {
+       UObjectClass parent;
+};
+
+GType engine_palette_get_type(void);
+void palette_register(GTypeModule *m);
+
+#endif