src/ascension/scene.h

Mon, 06 Apr 2026 21:04:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 06 Apr 2026 21:04:10 +0200
changeset 303
21ff357e773c
parent 287
359eaf2a8bd2
permissions
-rw-r--r--

prepare node (/ entity) dictionary per scene

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * Copyright 2023 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.
 */

#ifndef ASCENSION_SCENE_H
#define ASCENSION_SCENE_H

#include "scene_node.h"

#include <cx/list.h>
#include <cx/string.h>

#include "camera.h"

// forward declare camera
typedef struct asc_camera_s AscCamera;

typedef struct asc_scene_s {
    AscCamera *camera;
    AscSceneNode *root;
    /**
     * Maps names to a list of nodes that share the same name.
     * Does not contain nodes with auto-generated names.
     */
    AscSceneNodeDict *nodes_dict;
    cxmutstr name;
    struct {
        CxList *render_groups[ASC_RENDER_GROUP_COUNT];
    } internal;
} AscScene;

/**
 * Initializes a scene graph.
 *
 * @param scene the scene graph
 * @param name optional name for the scene
 * @param camera a pointer to the main camera for this scene
 */
void asc_scene_init(AscScene *scene, const char *name, AscCamera *camera);

/**
 * Checks if a scene is active.
 *
 * @param scene the scene
 * @return true if the scene is active for rendering, false if the scene is uninitialized or destroyed
 */
#define asc_scene_active(scene) ((scene)->root != NULL)

/**
 * Destroys a scene graph.
 *
 * Does nothing when the scene was not initialized.
 *
 * @param scene the scene graph
 */
void asc_scene_destroy(AscScene *scene);

/**
 * Returns a pointer to the scene's camera.
 *
 * @param scene the scene graph
 */
static inline const AscCamera *asc_scene_camera(const AscScene *scene) {
    return scene->camera;
}

static inline asc_rect asc_scene_viewport(const AscScene *scene) {
    return scene->camera->viewport;
}

void asc_scene_execute_behaviors(AscScene *scene);

/**
 * Draws the scene with the specified root node.
 *
 * If @p scene is not initialized, drawing is skipped.
 *
 * @param scene the scene graph
 */
void asc_scene_draw(AscScene *scene);

void asc_scene_add_node(AscScene *scene, AscSceneNode *node);

void asc_scene_remove_node(AscSceneNode *node);

#endif // ASCENSION_SCENE_H

mercurial