1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*
* Copyright (C) 2018 Vito Caputo - <vcaputo@pengaru.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <SDL.h>
#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;
}
|