view libmlk-core/mlk/core/drawable.c @ 645:83781cc87fca

core: rework game stack state mechanism The current model was fundamentally broken as the state could continue its execution when calling mlk_game_pop from itself (e.g. in update). The current model uses a sjlj mechanism with mlk_game_push/pop being disallowed in special state function like end, finish, suspend.
author David Demelier <markand@malikania.fr>
date Sun, 04 Feb 2024 15:24:00 +0100
parents f2f0e73ea9da
children
line wrap: on
line source

/*
 * drawable.c -- automatic drawable objects
 *
 * Copyright (c) 2020-2023 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <assert.h>

#include "drawable.h"

int
mlk_drawable_update(struct mlk_drawable *dw, unsigned int ticks)
{
	assert(dw);

	return dw->update(dw, ticks);
}

void
mlk_drawable_draw(struct mlk_drawable *dw)
{
	assert(dw);

	dw->draw(dw);
}

void
mlk_drawable_end(struct mlk_drawable *dw)
{
	assert(dw);

	if (dw->end)
		dw->end(dw);
}

void
mlk_drawable_finish(struct mlk_drawable *dw)
{
	assert(dw);

	if (dw->finish)
		dw->finish(dw);
}