]> git.draconx.ca Git - upkg.git/commitdiff
engine: Start using GOB2 to generate GObject classes.
authorNick Bowler <nbowler@draconx.ca>
Fri, 25 Mar 2011 14:59:44 +0000 (10:59 -0400)
committerNick Bowler <nbowler@draconx.ca>
Mon, 28 Mar 2011 22:47:55 +0000 (18:47 -0400)
GOB2 allows us to eliminate a lot of boilerplate.  Unfortunately,
current versions of GOB2 don't directly support dynamic types, so you
will need a patched version of GOB2 as of this writing.  For now, just
the Palette class is built using GOB2.

configure.ac
src/.gitignore [new file with mode: 0644]
src/Makefile.am
src/engine/.gitignore [new file with mode: 0644]
src/engine/Makefile.inc
src/engine/engine.c
src/engine/palette.c [deleted file]
src/engine/palette.gob [new file with mode: 0644]
src/engine/palette.h [deleted file]
src/engine/texture.c

index 5de7569569d2b24d1b6166f172bfeb279bfbf237..951c546afa5a03bd7b30aafbd2ecbd672e002212 100644 (file)
@@ -59,6 +59,8 @@ AC_MSG_RESULT([$use_modlib])
 AM_CONDITIONAL([USE_LIBMODPLUG], [test x$use_modlib = xmodplug])
 AM_CONDITIONAL([USE_DUMMYMOD],   [test x$use_modlib = xnone])
 
+GOB2_CHECK([2.0.0])
+
 AC_CONFIG_FILES([
        Makefile
        libltdl/Makefile
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644 (file)
index 0000000..92636b9
--- /dev/null
@@ -0,0 +1 @@
+*.gobstamp
index c2019c3add50d8deb2b4b47ba8cc57bc46f86894..8d37ea89a91d25c50a4785e2ad558a6f6f2122c4 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Nick Bowler
+# Copyright (C) 2009-2011 Nick Bowler
 # Copying and distribution of this file, with or without modification,
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.  This file is offered as-is,
@@ -7,12 +7,19 @@
 AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
 AM_LDFLAGS  = -L$(top_builddir)/lib
 
+EXTRA_DIST =
+MAINTAINERCLEANFILES =
+
 lib_LTLIBRARIES = libupkg.la
 pkglib_LTLIBRARIES =
 
 include_HEADERS = upkg.h
 noinst_HEADERS  = pack.h
 
+# This trick should define orderonly to | iff we're using GNU make.
+have_orderonly = $(findstring order-only,$(.FEATURES))
+orderonly = $(have_orderonly:order-only=|)
+
 include uobject/Makefile.inc
 include engine/Makefile.inc
 
@@ -23,3 +30,24 @@ upkg_SOURCES  = upkg.c
 upkg_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS)
 upkg_LDFLAGS  = $(AM_LDFLAGS) -export-dynamic
 upkg_LDADD    = libuobject.la libupkg.la $(GLIB_LIBS) -lgnu
+
+GOB_V   = $(GOB_V_$(V))
+GOB_V_  = $(GOB_V_$(AM_DEFAULT_VERBOSITY))
+GOB_V_0 = @echo "  GOB   " $<;
+
+.gob.gobstamp:
+       $(AM_V_at) touch $@.tmp
+       $(GOB_V) $(GOB2) --file-sep=/ --no-private-header $<
+       $(AM_V_at) mv -f $@.tmp $@
+
+.gobstamp.c:
+       @if test -f $@; then :; else \
+               rm -f $<; \
+               $(MAKE) $(AM_MAKEFLAGS) $<; \
+       fi
+
+.gobstamp.h:
+       @if test -f $@; then :; else \
+               rm -f $<; \
+               $(MAKE) $(AM_MAKEFLAGS) $<; \
+       fi
diff --git a/src/engine/.gitignore b/src/engine/.gitignore
new file mode 100644 (file)
index 0000000..eb6ec49
--- /dev/null
@@ -0,0 +1 @@
+palette.[ch]
index 8df920bc715ac1a0fdb12bb1eab007186c39632a..35c913878277829f643a96922b5bfb2f95601891 100644 (file)
@@ -1,19 +1,28 @@
-# Copyright (C) 2009 Nick Bowler
+# Copyright 2009-2011 Nick Bowler
 # Copying and distribution of this file, with or without modification,
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.  This file is offered as-is,
 # without any warranty.
 
-noinst_HEADERS += engine/texture.h engine/palette.h \
-       engine/music.h engine/music-module.h
+noinst_HEADERS += engine/texture.h engine/music.h engine/music-module.h
+
+engine_GOBS = engine/palette.gob
+
+EXTRA_DIST += $(engine_GOBS) $(engine_GOBS:.gob=.gobstamp)
+noinst_HEADERS += $(engine_GOBS:.gob=.h)
+MAINTAINERCLEANFILES += $(engine_GOBS:.gob=.gobstamp) \
+       $(engine_GOBS:.gob=.c) $(engine_GOBS:.gob=.h)
 
 pkglib_LTLIBRARIES += engine.la
 engine_la_SOURCES   = engine/engine.c engine/music.c engine/texture.c \
-       engine/palette.c
+       $(engine_GOBS:.gob=.c)
 engine_la_CFLAGS    = $(GLIB_CFLAGS)
 engine_la_LIBADD    = $(GLIB_LIBS)
 engine_la_LDFLAGS   = -module -avoid-version -export-symbols-regex _LTX_
 
+# Force all GOB objects to be generated before building anything.
+$(engine_la_OBJECTS): $(orderonly) $(engine_GOBS:.gob=.gobstamp)
+
 if USE_DUMMYMOD
 engine_la_SOURCES += engine/music-dummymod.c
 endif
index a22691c02ce049fc015c9e2b864971e4c96cd420..7077f6e59b1255ba7d7028f6c866edcfde4d8e9c 100644 (file)
@@ -30,7 +30,7 @@ int init(GTypeModule *m)
 {
        music_register(m);
        texture_register(m);
-       palette_register(m);
+       engine_palette_register_type(m);
        return 0;
 }
 
diff --git a/src/engine/palette.c b/src/engine/palette.c
deleted file mode 100644 (file)
index 29725ec..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- *  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 <engine/palette.h>
-#include "upkg.h"
-
-G_DEFINE_DYNAMIC_TYPE(EnginePalette, engine_palette, U_TYPE_OBJECT);
-
-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;
-       }
-
-       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.gob b/src/engine/palette.gob
new file mode 100644 (file)
index 0000000..4c15c71
--- /dev/null
@@ -0,0 +1,69 @@
+%alltop{
+/*
+ *  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>
+%}
+
+%h{
+#include <uobject/uobject.h>
+
+/* Hack to work around broken type parsing in GOB2. */
+typedef unsigned char engine_palette_rgba[4];
+%}
+
+class Engine:Palette from U:Object (dynamic)
+{
+       public unsigned entries = 0;
+       public engine_palette_rgba *rgba = NULL;
+
+       override (U:Object) int deserialize(U:Object *uo)
+       {
+               struct upkg_file *f = uo->pkg_file;
+               Self *self = SELF(uo);
+               unsigned char buf[16];
+               size_t rc, buflen;
+               long entries;
+
+               PARENT_HANDLER(uo);
+
+               buflen = upkg_export_read(f, buf, sizeof buf);
+               rc = upkg_decode_index(&entries, buf, buflen);
+               if (rc == 0 || entries < 0)
+                       return -1;
+               self->entries = entries;
+
+               upkg_export_seek(f, rc, SEEK_SET);
+               buflen = entries * sizeof self->rgba[0];
+               self->rgba = malloc(buflen);
+               if (!self->rgba)
+                       return -1;
+
+               rc = upkg_export_read(f, self->rgba, buflen);
+               if (rc != buflen) {
+                       free(self->rgba);
+                       return -1;
+               }
+
+               printf("palette: %u entries\n", self->entries);
+               return 0;
+       }
+}
diff --git a/src/engine/palette.h b/src/engine/palette.h
deleted file mode 100644 (file)
index 45cbdd4..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *  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
index 90cca6e7444dae5874553820e95f9825ae5f5a90..7cf05faca2387109f1dd84657ceb872ea9de2ff9 100644 (file)
@@ -191,7 +191,7 @@ static void engine_texture_class_init(EngineTextureClass *class)
                g_param_spec_object("Palette",
                        "Palette",
                        "Palette reference for the texture.",
-                       ENGINE_PALETTE_TYPE,
+                       ENGINE_TYPE_PALETTE,
                        G_PARAM_READWRITE));
 }