summaryrefslogtreecommitdiffstats
path: root/libdimension/object.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-09 14:00:42 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-26 14:08:57 -0400
commit68be10f11be6098f5cb19bf373e2c6ff82f93c71 (patch)
tree50eb89713b23e0c011e8b37c854e640c05318629 /libdimension/object.c
parent21137f8eaae886c034f62e18e6039cc48f09993e (diff)
downloaddimension-68be10f11be6098f5cb19bf373e2c6ff82f93c71.tar.xz
object: Get rid of void *ptr field.
Instead, allow dmnsn_object to be embedded in a larger struct. This gives a consistent 1% speed boost.
Diffstat (limited to 'libdimension/object.c')
-rw-r--r--libdimension/object.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/libdimension/object.c b/libdimension/object.c
index b085cff..52b9558 100644
--- a/libdimension/object.c
+++ b/libdimension/object.c
@@ -26,11 +26,25 @@
#include "dimension-internal.h"
#include <stdlib.h>
+static void
+dmnsn_default_object_free_fn(dmnsn_object *object)
+{
+ dmnsn_free(object);
+}
+
/* Allocate a dummy object */
dmnsn_object *
dmnsn_new_object(void)
{
dmnsn_object *object = DMNSN_MALLOC(dmnsn_object);
+ dmnsn_init_object(object);
+ return object;
+}
+
+/* Initialize a dmnsn_object field */
+void
+dmnsn_init_object(dmnsn_object *object)
+{
object->texture = NULL;
object->interior = NULL;
object->trans = dmnsn_identity_matrix();
@@ -40,13 +54,12 @@ dmnsn_new_object(void)
object->intersection_fn = NULL;
object->inside_fn = NULL;
object->initialize_fn = NULL;
- object->free_fn = NULL;
+ object->free_fn = dmnsn_default_object_free_fn;
object->initialized = false;
DMNSN_REFCOUNT_INIT(object);
- return object;
}
-/* Free a dummy object */
+/* Free a dmnsn_object */
void
dmnsn_delete_object(dmnsn_object *object)
{
@@ -57,10 +70,7 @@ dmnsn_delete_object(dmnsn_object *object)
dmnsn_delete_array(object->children);
dmnsn_delete_interior(object->interior);
dmnsn_delete_texture(object->texture);
- if (object->free_fn) {
- object->free_fn(object->ptr);
- }
- dmnsn_free(object);
+ object->free_fn(object);
}
}