Sun, 04 May 2025 21:50:13 +0200
use new UCX 3.2 cxListEmplace()
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * Copyright 2025 Mike Becker. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "ascension/behavior.h" #include "ascension/error.h" #include <cx/array_list.h> static void asc_behavior_destroy(void *b) { AscBehavior *behavior = b; if (behavior->destroy_func) { behavior->destroy_func(behavior); } } static CxList *asc_behavior_new_list(void) { // TODO: add comparator when we know how to identifier behaviors in order to remove them CxList *list = cxArrayListCreate(NULL, NULL, sizeof(AscBehavior), 4); cxDefineDestructor(list, asc_behavior_destroy); return list; } AscBehavior *asc_behavior_add_impl(AscSceneNode *node, struct asc_behavior_create_args args) { if (node->behaviors == NULL) { node->behaviors = asc_behavior_new_list(); } AscBehavior *behavior = cxListEmplace(node->behaviors); if (behavior == NULL) { // TODO: output ID of node once we have implemented that asc_error("Failed to add behavior to scene node."); return NULL; } behavior->node = node; behavior->func = args.func; behavior->destroy_func = args.destroy_func; behavior->data = args.data; return behavior; }