/* * Copyright (C) 2018 Vito Caputo - * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3 as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include "aabb.h" #include "whale.h" #include "macros.h" #include "v2f.h" #include "stage.h" typedef struct droplet_t { v2f_t trajectory; v2f_t coordinate; int dead:1; } droplet_t; typedef struct splash_t { Uint32 color; unsigned count; droplet_t droplets[]; int dead:1; } splash_t; static splash_t * splash_new(unsigned count) { splash_t *splash; unsigned i; splash = calloc(1, sizeof(splash_t) + count * sizeof(droplet_t)); fatal_if(!splash, "Unable to allocate splash_t"); splash->count = count; for (i = 0; i < count; i++) { splash->droplets[i].trajectory.y = 1.f; splash->droplets[i].trajectory.x = ((float)rand() * (1.0f / RAND_MAX) * .25f) - .125f; splash->droplets[i].coordinate.x = 0.f; splash->droplets[i].coordinate.y = -1.f; } return splash; } static void splash_render(splash_t *splash, SDL_Surface *surface) { unsigned i; /* TODO */ /* currently every time we render the splash we update it as well, they're * rolled into one */ for (i = 0; i < splash->count; i++) { } } static int splash_node_render(SDL_Renderer *renderer, void *object, int width, int height, SDL_Texture **texture) { splash_t *splash = object; SDL_Surface *surface; if (splash->dead) /* TODO: expand the stage node render api to support a "delete node" return from render */ return 0; if (*texture) { /* cached textures are useless to softwre rendered particles */ SDL_DestroyTexture(*texture); *texture = NULL; } splash_render(splash, surface); surface = whale_svg_render((whale_svg_t *)object, width, height); fatal_if(!surface, "Unable to render svg surface"); *texture = SDL_CreateTextureFromSurface(renderer, surface); fatal_if(!*texture, "Unable to create texture from svg surface"); SDL_FreeSurface(surface); return 1; } static void splash_node_free(void *object) { whale_svg_free(object); } stage_node_t * splash_node_new(stage_t *stage, const char *name, int layer, aabb_t aabb, unsigned count) { stage_node_t *node; splash_t *splash; splash = splash_new(count); node = stage_node_new(stage, layer, name, splash, splash_node_render, splash_node_free); fatal_if(!node, "Unable to create stage node for splash"); stage_node_set_aabb(stage, node, &aabb); return node; }