Wed, 02 Jul 2025 23:21:17 +0200
resolve TODOs regarding input.h
a) mouse position must be integer, because it can be negative (though rarely)
b) we should not trade "access complexity" for space in the scancodes array
/* * 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/context.h" #include "ascension/scene.h" #include <cx/array_list.h> #include <cx/tree.h> #include <assert.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 identify 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_(AscSceneNode *node, struct asc_behavior_create_args args) { if (node->behaviors == NULL) { node->behaviors = asc_behavior_new_list(); } AscBehavior *behavior = cxListEmplace(node->behaviors); assert(behavior != NULL); behavior->enabled = true; behavior->node = node; behavior->func = args.func; behavior->destroy_func = args.destroy_func; behavior->data = args.data; behavior->interval = args.interval; behavior->last_execution = 0; return behavior; } void asc_behavior_trigger(AscBehavior *behavior) { if (!behavior->enabled) return; if (behavior->last_execution + behavior->interval > asc_context.total_nanos) return; behavior->func(behavior); behavior->last_execution = asc_context.total_nanos; }