~rabbits/hiversaires

ref: 3e1627a4c505fa9109dd8d7d107a0b9946af8e5c hiversaires/src/delays.c -rw-r--r-- 1.7 KiB
3e1627a4Rezmason Implementing the credits as just a slower splash, with fading in mixed in, and click-through links to the logos' corresponding sites. Added Aliceffekt logo and the secret logo. Updated the credit trigger to only show the secret if the player has an extra fuse *and* didn't use the walkthrough. 1 year, 2 months ago
                                                                                
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
#include "delays.h"

#include <string.h>
#include <stdlib.h>

/*
Copyright (c) 2013-2021 Devine Lu Linvega
2018 web port by rezmason
2021 C89 port by rezmason

Permission to use, copy, modify, and 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.
*/

static Delay (*delays)[] = NULL;
static double _totalTime = 0;
static int _numDelays;

void
Delays_Init(int numDelays)
{
	int i;
	_numDelays = numDelays;
	delays = calloc(_numDelays, sizeof(Delay));
	for(i = 0; i < _numDelays; i++) {
		(*delays)[i].endTime = -1;
	}
}

void
Delays_Quit()
{
	free(delays);
	delays = NULL;
}

void
Delays_Add(int *uid, double duration, void (*onComplete)(void *data), void *data)
{
	int i;
	for(i = 0; i < _numDelays; i++) {
		if((*delays)[i].onComplete == NULL) {
			(*delays)[i].endTime = _totalTime + duration;
			(*delays)[i].onComplete = onComplete;
			(*delays)[i].data = data;
			*uid = i;
			return;
		}
	}
	*uid = -1;
}

void
Delays_Cancel(int *uid, int complete)
{
	Delay *delay;
	void (*onComplete)();
	void *data;

	if(*uid < 0 || *uid >= _numDelays) {
		return;
	}
	delay = &(*delays)[*uid];
	onComplete = delay->onComplete;
	data = delay->data;
	delay->onComplete = NULL;
	delay->data = NULL;
	delay->endTime = -1;
	*uid = -1;
	if(complete && onComplete != NULL) {
		onComplete(data);
	}
}

void
Delays_Update(double totalTime)
{
	int i, uid;
	_totalTime = totalTime;
	for(i = 0; i < _numDelays; i++) {
		if((*delays)[i].endTime > 0 && (*delays)[i].endTime < _totalTime) {
			uid = i;
			Delays_Cancel(&uid, 1);
		}
	}
}