Subversion Repositories eduke32

Rev

Rev 4859 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4859 Rev 4987
Line 30... Line 30...
30
30
31
#include "anim.h"
31
#include "anim.h"
32
32
33
#ifdef USE_LIBVPX
33
#ifdef USE_LIBVPX
34
# include "animvpx.h"
34
# include "animvpx.h"
35
-
 
36
uint16_t anim_hi_numsounds[NUM_HARDCODED_ANIMS], *anim_hi_sounds[NUM_HARDCODED_ANIMS];
-
 
37
#endif
35
#endif
38
36
39
static void endanimsounds(int32_t fr)
37
#include "animsounds.h"
40
{
-
 
41
    switch (ud.volume_number)
-
 
42
    {
-
 
43
    case 0:
-
 
44
        break;
-
 
45
    case 1:
-
 
46
        switch (fr)
-
 
47
        {
-
 
48
        case 1:
-
 
49
            S_PlaySound(WIND_AMBIENCE);
-
 
50
            break;
-
 
51
        case 26:
-
 
52
            S_PlaySound(ENDSEQVOL2SND1);
-
 
53
            break;
-
 
54
        case 36:
-
 
55
            S_PlaySound(ENDSEQVOL2SND2);
-
 
56
            break;
-
 
57
        case 54:
-
 
58
            S_PlaySound(THUD);
-
 
59
            break;
-
 
60
        case 62:
-
 
61
            S_PlaySound(ENDSEQVOL2SND3);
-
 
62
            break;
-
 
63
        case 75:
-
 
64
            S_PlaySound(ENDSEQVOL2SND4);
-
 
65
            break;
-
 
66
        case 81:
-
 
67
            S_PlaySound(ENDSEQVOL2SND5);
-
 
68
            break;
-
 
69
        case 115:
-
 
70
            S_PlaySound(ENDSEQVOL2SND6);
-
 
71
            break;
-
 
72
        case 124:
-
 
73
            S_PlaySound(ENDSEQVOL2SND7);
-
 
74
            break;
-
 
75
        }
-
 
76
        break;
-
 
77
    case 2:
-
 
78
        switch (fr)
-
 
79
        {
-
 
80
        case 1:
-
 
81
            S_PlaySound(WIND_REPEAT);
-
 
82
            break;
-
 
83
        case 98:
-
 
84
            S_PlaySound(DUKE_GRUNT);
-
 
85
            break;
-
 
86
        case 82+20:
-
 
87
            S_PlaySound(THUD);
-
 
88
            S_PlaySound(SQUISHED);
-
 
89
            break;
-
 
90
        case 104+20:
-
 
91
            S_PlaySound(ENDSEQVOL3SND3);
-
 
92
            break;
-
 
93
        case 114+20:
-
 
94
            S_PlaySound(ENDSEQVOL3SND2);
-
 
95
            break;
-
 
96
        case 158:
-
 
97
            S_PlaySound(PIPEBOMB_EXPLODE);
-
 
98
            break;
-
 
99
        }
-
 
100
        break;
-
 
101
    }
-
 
102
}
-
 
103
38
104
static void logoanimsounds(int32_t fr)
39
hashtable_t h_dukeanim = { 8, NULL };
105
{
-
 
106
    switch (fr)
40
dukeanim_t * g_animPtr;
107
    {
-
 
108
    case 1:
-
 
109
        S_PlaySound(FLY_BY);
-
 
110
        break;
-
 
111
    case 19:
-
 
112
        S_PlaySound(PIPEBOMB_EXPLODE);
-
 
113
        break;
-
 
114
    }
-
 
115
}
-
 
116
41
117
static void intro4animsounds(int32_t fr)
42
dukeanim_t *G_FindAnim(const char *s)
118
{
-
 
119
    switch (fr)
-
 
120
    {
43
{
121
    case 1:
-
 
122
        S_PlaySound(INTRO4_B);
44
    intptr_t ptr = hash_findcase(&h_dukeanim, s);
123
        break;
-
 
124
    case 12:
-
 
125
    case 34:
-
 
126
        S_PlaySound(SHORT_CIRCUIT);
45
    return (dukeanim_t *)(ptr == -1 ? NULL : (dukeanim_t *)ptr);
127
        break;
-
 
128
    case 18:
-
 
129
        S_PlaySound(INTRO4_5);
-
 
130
        break;
-
 
131
    }
-
 
132
}
46
}
133
47
134
static void first4animsounds(int32_t fr)
48
dukeanim_t * G_DefineAnim(const char *fn, uint8_t fdelay, void (*sound_func)(int32_t))
135
{
49
{
136
    switch (fr)
-
 
137
    {
-
 
138
    case 1:
-
 
139
        S_PlaySound(INTRO4_1);
-
 
140
        break;
-
 
141
    case 12:
-
 
142
        S_PlaySound(INTRO4_2);
50
    dukeanim_t * anim = G_FindAnim(fn);
143
        break;
-
 
144
    case 7:
-
 
145
        S_PlaySound(INTRO4_3);
-
 
146
        break;
-
 
147
    case 26:
-
 
148
        S_PlaySound(INTRO4_4);
-
 
149
        break;
-
 
150
    }
-
 
151
}
-
 
152
51
   
153
static void intro42animsounds(int32_t fr)
-
 
154
{
-
 
155
    switch (fr)
52
    if (!anim)
156
    {
-
 
157
    case 10:
-
 
158
        S_PlaySound(INTRO4_6);
53
        anim = (dukeanim_t *)Xcalloc(1, sizeof(dukeanim_t));
159
        break;
-
 
160
    }
-
 
161
}
-
 
162
54
163
static void endanimvol41(int32_t fr)
55
    hash_add(&h_dukeanim, fn, (intptr_t)anim, 0);
164
{
-
 
165
    switch (fr)
-
 
166
    {
-
 
167
    case 3:
-
 
168
        S_PlaySound(DUKE_UNDERWATER);
-
 
169
        break;
-
 
170
    case 35:
-
 
171
        S_PlaySound(VOL4ENDSND1);
-
 
172
        break;
-
 
173
    }
-
 
174
}
-
 
175
56
-
 
57
    if (sound_func)
176
static void endanimvol42(int32_t fr)
58
        anim->sound_func = sound_func;
177
{
59
178
    switch (fr)
60
    anim->framedelay = fdelay;
179
    {
61
180
    case 11:
-
 
181
        S_PlaySound(DUKE_UNDERWATER);
-
 
182
        break;
-
 
183
    case 20:
-
 
184
        S_PlaySound(VOL4ENDSND1);
-
 
185
        break;
-
 
186
    case 39:
-
 
187
        S_PlaySound(VOL4ENDSND2);
-
 
188
        break;
-
 
189
    case 50:
-
 
190
        FX_StopAllSounds();
-
 
191
        break;
62
    return anim;
192
    }
-
 
193
}
63
}
194
64
195
static void endanimvol43(int32_t fr)
65
void G_InitAnim(void)
196
{
66
{
197
    switch (fr)
67
    hash_init(&h_dukeanim);
198
    {
68
-
 
69
    G_DefineAnim("logo.anm", 9, logoanimsounds);
199
    case 1:
70
    G_DefineAnim("3dr.anm", 10, NULL);
200
        S_PlaySound(BOSS4_DEADSPEECH);
71
    G_DefineAnim("vol4e1.anm", 10, endanimvol41);
201
        break;
72
    G_DefineAnim("vol4e2.anm", 14, endanimvol42);
202
    case 40:
73
    G_DefineAnim("vol4e3.anm", 10, endanimvol43);
203
        S_PlaySound(VOL4ENDSND1);
74
    G_DefineAnim("vol41a.anm", 14, first4animsounds);
204
        S_PlaySound(DUKE_UNDERWATER);
75
    G_DefineAnim("vol42a.anm", 18, intro4animsounds);
205
        break;
76
    G_DefineAnim("vol43a.anm", 10, intro42animsounds);
206
    case 50:
77
    G_DefineAnim("duketeam.anm", 10, NULL);
207
        S_PlaySound(BIGBANG);
78
    G_DefineAnim("radlogo.anm", 10, NULL);
208
        break;
79
    G_DefineAnim("cineov2.anm", 18, endanimsounds);
209
    }
80
    G_DefineAnim("cineov3.anm", 10, endanimsounds);
210
}
81
}
211
82
212
static uint8_t* animbuf[NUM_HARDCODED_ANIMS];
83
int32_t G_PlayAnim(const char *fn)
-
 
84
{
213
static char animlock[NUM_HARDCODED_ANIMS];
85
    dukeanim_t *anim = G_FindAnim(fn);
214
86
215
int32_t G_PlayAnim(const char *fn, char t)
87
    if (!anim)
216
{
88
    {
217
    int32_t i, length=0, numframes=0;
89
        OSD_Printf("Animation %s is undefined!\n", fn);
218
#ifdef USE_OPENGL
90
        return 0;
219
    int32_t ogltexfiltermode=gltexfiltermode;
-
 
220
#endif
91
    }
221
    int32_t handle=-1;
-
 
222
    int32_t frametime = 0;
-
 
223
    int32_t running = 1;
-
 
224
92
225
    // t parameter:
93
    int32_t framenum = 0, soundidx = 0;  // custom anim sounds
226
    //
-
 
227
    // 1: cineov2
-
 
228
    // 2: cineov3
-
 
229
    // 3: RADLOGO
-
 
230
    // 4: DUKETEAM
-
 
231
    // 5: logo
-
 
232
    // 6: vol41a
-
 
233
    // 7: vol42a
-
 
234
    // 8: vol4e1
-
 
235
    // 9: vol43a
-
 
236
    // 10: vol4e2
-
 
237
    // 11: vol4e3
-
 
238
    // 12: 3drealms anim
94
    int32_t running = 1, i;
239
95
240
    I_ClearAllInput();
96
    I_ClearAllInput();
241
97
242
#ifdef USE_LIBVPX
98
#ifdef USE_LIBVPX
243
    while (getrendermode() >= REND_POLYMOST && glinfo.glsl)  // if, really
99
    while (getrendermode() >= REND_POLYMOST && glinfo.glsl)  // if, really
244
    {
100
    {
245
        char vpxfn[BMAX_PATH], *dot;
101
        char vpxfn[BMAX_PATH];
246
        animvpx_ivf_header_t info;
-
 
247
-
 
248
        animvpx_codec_ctx codec;
-
 
249
        uint8_t *pic;
-
 
250
        uint32_t msecsperframe, nextframetime;
-
 
251
        int32_t animidx, framenum=0, soundidx=0, numtotalsounds=0;  // custom anim sounds
-
 
252
-
 
253
        Bstrncpyz(vpxfn, fn, BMAX_PATH);
102
        Bstrncpyz(vpxfn, fn, BMAX_PATH);
254
103
255
        dot = Bstrrchr(vpxfn, '.');
104
        char *dot = Bstrrchr(vpxfn, '.');
256
        if (!dot || (dot-vpxfn)+4 >= BMAX_PATH)
105
        if (!dot || (dot - vpxfn) + 4 >= BMAX_PATH)
257
            break;
106
            break;
258
107
259
        dot[1] = 'i';
108
        dot[1] = 'i';
260
        dot[2] = 'v';
109
        dot[2] = 'v';
261
        dot[3] = 'f';
110
        dot[3] = 'f';
262
        dot[4] = 0;
111
        dot[4] = 0;
263
112
264
        handle = kopen4loadfrommod(vpxfn, 0);
113
        int32_t handle = kopen4loadfrommod(vpxfn, 0);
265
        if (handle == -1)
114
        if (handle == -1)
266
            break;
115
            break;
267
116
-
 
117
        animvpx_ivf_header_t info;
268
        i = animvpx_read_ivf_header(handle, &info);
118
        i = animvpx_read_ivf_header(handle, &info);
-
 
119
269
        if (i)
120
        if (i)
270
        {
121
        {
271
            OSD_Printf("Failed reading IVF file: %s\n",
122
            OSD_Printf("Failed reading IVF file: %s\n", animvpx_read_ivf_header_errmsg[i]);
272
                       animvpx_read_ivf_header_errmsg[i]);
-
 
273
            kclose(handle);
123
            kclose(handle);
274
            return 0;
124
            return 0;
275
        }
125
        }
276
126
277
        animvpx_setup_glstate();
127
        animvpx_setup_glstate();
-
 
128
-
 
129
        animvpx_codec_ctx codec;
-
 
130
278
        if (animvpx_init_codec(&info, handle, &codec))
131
        if (animvpx_init_codec(&info, handle, &codec))
279
        {
132
        {
280
            OSD_Printf("Error initializing VPX codec.\n");
133
            OSD_Printf("Error initializing VPX codec.\n");
281
            animvpx_restore_glstate();
134
            animvpx_restore_glstate();
282
            return 0;
135
            return 0;
283
        }
136
        }
284
137
285
        animidx = t-1;
-
 
286
        if ((unsigned)animidx < NUM_HARDCODED_ANIMS && anim_hi_sounds[animidx])
138
        uint32_t msecsperframe = ((uint64_t)info.fpsdenom * 1000) / info.fpsnumer;
287
            numtotalsounds = anim_hi_numsounds[animidx];
139
        uint32_t nextframetime = getticks();
-
 
140
        uint8_t *pic;
288
141
289
        msecsperframe = ((uint64_t)info.fpsdenom*1000)/info.fpsnumer;
-
 
290
//        OSD_Printf("msecs per frame: %d\n", msecsperframe);
142
        //        OSD_Printf("msecs per frame: %d\n", msecsperframe);
291
143
292
        nextframetime = getticks();
-
 
293
-
 
294
        while (running)
144
        do
295
        {
145
        {
296
            nextframetime += msecsperframe;
146
            nextframetime += msecsperframe;
297
147
298
            i = animvpx_nextpic(&codec, &pic);
148
            i = animvpx_nextpic(&codec, &pic);
299
            if (i)
149
            if (i)
300
            {
150
            {
301
                OSD_Printf("Failed getting next pic: %s\n",
151
                OSD_Printf("Failed getting next pic: %s\n", animvpx_nextpic_errmsg[i]);
302
                           animvpx_nextpic_errmsg[i]);
-
 
303
                if (codec.errmsg)
152
                if (codec.errmsg)
304
                {
153
                {
305
                    OSD_Printf("  %s\n", codec.errmsg);
154
                    OSD_Printf("  %s\n", codec.errmsg);
306
                    if (codec.errmsg_detail)
155
                    if (codec.errmsg_detail)
307
                        OSD_Printf("  detail: %s\n", codec.errmsg_detail);
156
                        OSD_Printf("  detail: %s\n", codec.errmsg_detail);
Line 314... Line 163...
314
163
315
            animvpx_render_frame(&codec);
164
            animvpx_render_frame(&codec);
316
165
317
            // after rendering the frame but before displaying: maybe play sound...
166
            // after rendering the frame but before displaying: maybe play sound...
318
            framenum++;
167
            framenum++;
319
            while (soundidx < numtotalsounds && anim_hi_sounds[animidx][2*soundidx] == framenum)
168
            while (soundidx < anim->numsounds && anim->sounds[soundidx << 1] == framenum)
320
            {
169
            {
321
                S_PlaySound(anim_hi_sounds[animidx][2*soundidx+1]);
170
                S_PlaySound(anim->sounds[(soundidx << 1) + 1]);
322
                soundidx++;
171
                soundidx++;
323
            }
172
            }
324
173
325
            // this and showframe() instead of nextpage() are so that
174
            // this and showframe() instead of nextpage() are so that
326
            // nobody tramples on our carefully set up GL state!
175
            // nobody tramples on our carefully set up GL state!
Line 336... Line 185...
336
                if (I_CheckAllInput())
185
                if (I_CheckAllInput())
337
                {
186
                {
338
                    running = 0;
187
                    running = 0;
339
                    break;
188
                    break;
340
                }
189
                }
341
            }
-
 
342
            while (getticks() < nextframetime);
190
            } while (getticks() < nextframetime);
343
        }
191
        } while (running);
344
192
345
        animvpx_print_stats(&codec);
193
        animvpx_print_stats(&codec);
346
194
347
        //
195
        //
348
        kclose(handle);
196
        kclose(handle);
Line 353... Line 201...
353
        return !running;  // done with playing VP8!
201
        return !running;  // done with playing VP8!
354
    }
202
    }
355
#endif
203
#endif
356
    // ANM playback --- v v v ---
204
// ANM playback --- v v v ---
357
205
-
 
206
#ifdef USE_OPENGL
-
 
207
    int32_t ogltexfiltermode = gltexfiltermode;
-
 
208
#endif
358
    handle = kopen4load(fn, 0);
209
    int32_t handle = kopen4load(fn, 0);
-
 
210
359
    if (handle == -1)
211
    if (handle == -1)
360
        return 0;
212
        return 0;
361
213
362
    length = kfilelength(handle);
214
    int32_t length = kfilelength(handle);
-
 
215
363
    if (length == 0)
216
    if (length == 0)
364
    {
217
    {
365
        OSD_Printf("Warning: skipping playback of empty ANM file \"%s\".\n", fn);
218
        OSD_Printf("Warning: skipping playback of empty ANM file \"%s\".\n", fn);
366
        goto end_anim;
219
        goto end_anim;
367
    }
220
    }
368
221
369
    walock[TILE_ANIM] = 219+t;
222
    walock[TILE_ANIM] = 219;
370
    animlock[t-1] = 1;
223
    anim->animlock = 1;
371
224
372
    if (!animbuf[t-1])
225
    if (!anim->animbuf)
373
        allocache((intptr_t *)&animbuf[t-1], length+1, &animlock[t-1]);
226
        allocache((intptr_t *)&anim->animbuf, length + 1, &anim->animlock);
374
227
375
    tilesiz[TILE_ANIM].x = 200;
228
    tilesiz[TILE_ANIM].x = 200;
376
    tilesiz[TILE_ANIM].y = 320;
229
    tilesiz[TILE_ANIM].y = 320;
377
230
378
    kread(handle, animbuf[t-1], length);
231
    kread(handle, anim->animbuf, length);
379
    kclose(handle);
232
    kclose(handle);
380
233
-
 
234
    int32_t numframes;
-
 
235
381
    if (ANIM_LoadAnim(animbuf[t-1], length) < 0 || (numframes = ANIM_NumFrames()) <= 0)
236
    if (ANIM_LoadAnim(anim->animbuf, length) < 0 || (numframes = ANIM_NumFrames()) <= 0)
382
    {
237
    {
383
        // XXX: ANM_LoadAnim() still checks less than the bare minimum,
238
        // XXX: ANM_LoadAnim() still checks less than the bare minimum,
384
        // e.g. ANM file could still be too small and not contain any frames.
239
        // e.g. ANM file could still be too small and not contain any frames.
385
        OSD_Printf("Error: malformed ANM file \"%s\".\n", fn);
240
        OSD_Printf("Error: malformed ANM file \"%s\".\n", fn);
386
        goto end_anim;
241
        goto end_anim;
Line 398... Line 253...
398
#endif
253
#endif
399
254
400
    ototalclock = totalclock + 10;
255
    ototalclock = totalclock + 10;
401
256
402
    i = 1;
257
    i = 1;
-
 
258
    int32_t frametime; frametime = 0;
403
259
404
    do
260
    do
405
    {
261
    {
406
        if (i > 4 && totalclock > frametime + 60)
262
        if (i > 4 && totalclock > frametime + 60)
407
        {
263
        {
Line 431... Line 287...
431
287
432
        frametime = totalclock;
288
        frametime = totalclock;
433
289
434
        clearallviews(0);
290
        clearallviews(0);
435
291
436
        rotatesprite_fs(0<<16, 0<<16, 65536L, 512, TILE_ANIM, 0, 0, 2+4+8+16+64+(ud.bgstretch ? 1024 : 0));
292
        rotatesprite_fs(0 << 16, 0 << 16, 65536L, 512, TILE_ANIM, 0, 0, 2 + 4 + 8 + 16 + 64 + BGSTRETCH);
-
 
293
-
 
294
        g_animPtr = anim;
-
 
295
        i = VM_OnEventWithReturn(EVENT_CUTSCENE, -1, myconnectindex, i);
-
 
296
        g_animPtr = NULL;
-
 
297
437
        nextpage();
298
        nextpage();
438
299
439
        I_ClearAllInput();
300
        I_ClearAllInput();
440
301
441
        if (t == 10) ototalclock += 14;
302
        ototalclock += anim->framedelay;
442
        else if (t == 9) ototalclock += 10;
-
 
443
        else if (t == 7) ototalclock += 18;
-
 
444
        else if (t == 6) ototalclock += 14;
-
 
445
        else if (t == 5) ototalclock += 9;
-
 
446
        else if (ud.volume_number == 3) ototalclock += 10;
-
 
447
        else if (ud.volume_number == 2) ototalclock += 10;
-
 
448
        else if (ud.volume_number == 1) ototalclock += 18;
-
 
449
        else                           ototalclock += 10;
-
 
450
303
451
        if (t == 8) endanimvol41(i);
304
        if (!anim->numsounds && anim->sound_func)
452
        else if (t == 10) endanimvol42(i);
305
            anim->sound_func(i);
-
 
306
453
        else if (t == 11) endanimvol43(i);
307
        framenum = i++;
-
 
308
454
        else if (t == 9) intro42animsounds(i);
309
        while (soundidx < anim->numsounds && anim->sounds[soundidx << 1] == framenum)
455
        else if (t == 7) intro4animsounds(i);
-
 
456
        else if (t == 6) first4animsounds(i);
310
        {
457
        else if (t == 5) logoanimsounds(i);
311
            S_PlaySound(anim->sounds[(soundidx << 1) + 1]);
458
        else if (t < 4) endanimsounds(i);
312
            soundidx++;
459
        i++;
313
        }
460
    } while (i < numframes);
314
    } while (i < numframes);
461
315
462
end_anim_restore_gl:
316
end_anim_restore_gl:
463
#ifdef USE_OPENGL
317
#ifdef USE_OPENGL
464
    gltexfiltermode = ogltexfiltermode;
318
    gltexfiltermode = ogltexfiltermode;
Line 466... Line 320...
466
#endif
320
#endif
467
end_anim:
321
end_anim:
468
    I_ClearAllInput();
322
    I_ClearAllInput();
469
    ANIM_FreeAnim();
323
    ANIM_FreeAnim();
470
    walock[TILE_ANIM] = 1;
324
    walock[TILE_ANIM] = 1;
471
    animlock[t-1] = 0;
325
    anim->animlock = 0;
472
326
473
    return !running;
327
    return !running;
474
}
328
}