-
Notifications
You must be signed in to change notification settings - Fork 1
/
sfx.c~
132 lines (104 loc) · 3.55 KB
/
sfx.c~
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
sfx.c
Copyright 2007 Sebastien Delestaing
This file is part of "the_cube".
"the_cube" is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
"the_cube" 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/>.
*/
/************************************ INCLUDES ***************************************/
/************************************* DEFINES ***************************************/
/************************************ TYPEDEFS ***************************************/
/********************************* EXTERNAL VARS *************************************/
/********************************** GLOBAL VARS **************************************/
/************************************* STATICS ***************************************/
/********************************* LOCAL FUNCTIONS ***********************************/
/******************************* EXPORTED FUNCTIONS **********************************/
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "sfx.h"
sfx_t *sfxFree (sfx_t *sfx)
{
free (sfx);
return NULL;
}
void sfxSet (sfx_t *sfx, float start, float stop, float nb_of_steps, SFX_FUNCTION_T function, void (*process_callback)(sfx_t *, float), void (*complete_callback)(sfx_t *), void *user_data)
{
sfx->start = start;
sfx->stop = stop;
sfx->nb_of_steps = nb_of_steps;
sfx->function = function;
sfx->user_data = user_data;
sfx->process_callback = process_callback;
sfx->complete_callback = complete_callback;
sfx->current_step = 0;
sfx->completed = 0;
}
sfx_t *sfxNew (void)
{
sfx_t *new;
new = (sfx_t *)malloc (sizeof (sfx_t));
new->completed = -1;
return new;
}
void sfxStop (sfx_t *sfx)
{
sfx->completed = -1;
}
void sfxProcess (sfx_t *sfx)
{
if (sfx->completed)
return;
switch (sfx->function)
{
case SFX_LINEAR:
if (sfx->process_callback)
sfx->process_callback (sfx, sfx->start + (float)(sfx->current_step) *
(float)((sfx->stop - sfx->start) /
(float)sfx->nb_of_steps));
break;
}
sfx->current_step++;
if (sfx->current_step > sfx->nb_of_steps)
{
sfx->completed = -1;
if (sfx->complete_callback)
sfx->complete_callback (sfx);
}
}
void sfxCompleteSetIntTrue (sfx_t *sfx)
{
int *p = (int *)sfx->user_data;
*p = -1;
}
void sfxProcessSetInt (sfx_t *sfx, float value)
{
int *p = (int *)sfx->user_data;
*p = (int)value;
}
void sfxProcessSetFloat (sfx_t *sfx, float value)
{
float *p = (float *)sfx->user_data;
*p = (float)value;
}
void sfxProcessFade (sfx_t *sfx, float value)
{
u32 color = 0xff - (int)value;
color <<= 24;
sceGuDisable (GU_TEXTURE_2D);
sceGuDisable (GU_DEPTH_TEST);
sceGuBlendFunc (GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
sceGuEnable(GU_BLEND);
drawRectangle (0, 0, SCR_WIDTH, SCR_HEIGHT, color);
sceGuEnable (GU_DEPTH_TEST);
sceGuDisable(GU_BLEND);
sceGuEnable (GU_TEXTURE_2D);
}