test/testsprite2.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 04 Jan 2019 22:01:14 -0800
changeset 12503 806492103856
parent 12210 9f9dbcce30b3
child 12758 3c6a6dad3487
permissions -rw-r--r--
Updated copyright for 2019
slouken@5535
     1
/*
slouken@12503
     2
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     3
slouken@5535
     4
  This software is provided 'as-is', without any express or implied
slouken@5535
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     6
  arising from the use of this software.
slouken@5535
     7
slouken@5535
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
     9
  including commercial applications, and to alter it and redistribute it
slouken@5535
    10
  freely.
slouken@5535
    11
*/
slouken@1895
    12
/* Simple program:  Move N sprites around on the screen as fast as possible */
slouken@1895
    13
slouken@1895
    14
#include <stdlib.h>
slouken@1907
    15
#include <stdio.h>
slouken@1895
    16
#include <time.h>
slouken@1895
    17
icculus@9278
    18
#ifdef __EMSCRIPTEN__
icculus@9278
    19
#include <emscripten/emscripten.h>
icculus@9278
    20
#endif
icculus@9278
    21
aschiffler@7315
    22
#include "SDL_test.h"
slouken@6785
    23
#include "SDL_test_common.h"
slouken@1895
    24
slouken@5147
    25
#define NUM_SPRITES    100
slouken@5147
    26
#define MAX_SPEED     1
slouken@1895
    27
slouken@6785
    28
static SDLTest_CommonState *state;
slouken@1895
    29
static int num_sprites;
slouken@3685
    30
static SDL_Texture **sprites;
slouken@1985
    31
static SDL_bool cycle_color;
slouken@1985
    32
static SDL_bool cycle_alpha;
slouken@1985
    33
static int cycle_direction = 1;
slouken@1985
    34
static int current_alpha = 0;
slouken@1985
    35
static int current_color = 0;
slouken@1895
    36
static SDL_Rect *positions;
slouken@1895
    37
static SDL_Rect *velocities;
slouken@1895
    38
static int sprite_w, sprite_h;
slouken@5140
    39
static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
icculus@12210
    40
static Uint32 next_fps_check, frames;
icculus@12210
    41
static const Uint32 fps_check_delay = 5000;
slouken@1895
    42
aschiffler@7315
    43
/* Number of iterations to move sprites - used for visual tests. */
aschiffler@7315
    44
/* -1: infinite random moves (default); >=0: enables N deterministic moves */
aschiffler@7315
    45
static int iterations = -1;
aschiffler@7315
    46
icculus@9278
    47
int done;
icculus@9278
    48
slouken@1895
    49
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
slouken@1895
    50
static void
slouken@1895
    51
quit(int rc)
slouken@1895
    52
{
slouken@7719
    53
    SDL_free(sprites);
slouken@7719
    54
    SDL_free(positions);
slouken@7719
    55
    SDL_free(velocities);
slouken@6785
    56
    SDLTest_CommonQuit(state);
slouken@1895
    57
    exit(rc);
slouken@1895
    58
}
slouken@1895
    59
slouken@1895
    60
int
slouken@7502
    61
LoadSprite(const char *file)
slouken@1895
    62
{
slouken@1895
    63
    int i;
slouken@1895
    64
    SDL_Surface *temp;
slouken@1895
    65
slouken@1895
    66
    /* Load the sprite image */
slouken@1895
    67
    temp = SDL_LoadBMP(file);
slouken@1895
    68
    if (temp == NULL) {
aschiffler@7639
    69
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
slouken@1895
    70
        return (-1);
slouken@1895
    71
    }
slouken@1895
    72
    sprite_w = temp->w;
slouken@1895
    73
    sprite_h = temp->h;
slouken@1895
    74
slouken@1895
    75
    /* Set transparent pixel as the pixel at (0,0) */
slouken@1895
    76
    if (temp->format->palette) {
slouken@3560
    77
        SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
lestat@3183
    78
    } else {
lestat@3183
    79
        switch (temp->format->BitsPerPixel) {
lestat@3183
    80
        case 15:
slouken@3560
    81
            SDL_SetColorKey(temp, 1, (*(Uint16 *) temp->pixels) & 0x00007FFF);
lestat@3183
    82
            break;
lestat@3183
    83
        case 16:
slouken@3560
    84
            SDL_SetColorKey(temp, 1, *(Uint16 *) temp->pixels);
lestat@3183
    85
            break;
lestat@3183
    86
        case 24:
slouken@3560
    87
            SDL_SetColorKey(temp, 1, (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
lestat@3183
    88
            break;
lestat@3183
    89
        case 32:
slouken@3560
    90
            SDL_SetColorKey(temp, 1, *(Uint32 *) temp->pixels);
lestat@3183
    91
            break;
lestat@3183
    92
        }
slouken@1895
    93
    }
slouken@1895
    94
slouken@1895
    95
    /* Create textures from the image */
slouken@1914
    96
    for (i = 0; i < state->num_windows; ++i) {
slouken@5147
    97
        SDL_Renderer *renderer = state->renderers[i];
slouken@5158
    98
        sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
slouken@3285
    99
        if (!sprites[i]) {
aschiffler@7639
   100
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
slouken@1895
   101
            SDL_FreeSurface(temp);
slouken@1895
   102
            return (-1);
slouken@1895
   103
        }
slouken@11282
   104
        if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
slouken@11282
   105
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
slouken@11282
   106
            SDL_FreeSurface(temp);
slouken@11282
   107
            SDL_DestroyTexture(sprites[i]);
slouken@11282
   108
            return (-1);
slouken@11282
   109
        }
slouken@1895
   110
    }
slouken@1895
   111
    SDL_FreeSurface(temp);
slouken@1895
   112
slouken@1895
   113
    /* We're ready to roll. :) */
slouken@1895
   114
    return (0);
slouken@1895
   115
}
slouken@1895
   116
slouken@1895
   117
void
slouken@5297
   118
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
slouken@1895
   119
{
aschiffler@7315
   120
    int i;
slouken@5297
   121
    SDL_Rect viewport, temp;
slouken@2783
   122
    SDL_Rect *position, *velocity;
slouken@1895
   123
slouken@1895
   124
    /* Query the sizes */
slouken@5297
   125
    SDL_RenderGetViewport(renderer, &viewport);
slouken@1895
   126
slouken@1985
   127
    /* Cycle the color and alpha, if desired */
slouken@1985
   128
    if (cycle_color) {
slouken@1985
   129
        current_color += cycle_direction;
slouken@1985
   130
        if (current_color < 0) {
slouken@1985
   131
            current_color = 0;
slouken@1985
   132
            cycle_direction = -cycle_direction;
slouken@1985
   133
        }
slouken@1985
   134
        if (current_color > 255) {
slouken@1985
   135
            current_color = 255;
slouken@1985
   136
            cycle_direction = -cycle_direction;
slouken@1985
   137
        }
slouken@1985
   138
        SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
slouken@1985
   139
                               (Uint8) current_color);
slouken@1985
   140
    }
slouken@1985
   141
    if (cycle_alpha) {
slouken@1985
   142
        current_alpha += cycle_direction;
slouken@1985
   143
        if (current_alpha < 0) {
slouken@1985
   144
            current_alpha = 0;
slouken@1985
   145
            cycle_direction = -cycle_direction;
slouken@1985
   146
        }
slouken@1985
   147
        if (current_alpha > 255) {
slouken@1985
   148
            current_alpha = 255;
slouken@1985
   149
            cycle_direction = -cycle_direction;
slouken@1985
   150
        }
slouken@1985
   151
        SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
slouken@1985
   152
    }
slouken@1985
   153
slouken@3264
   154
    /* Draw a gray background */
slouken@5147
   155
    SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
slouken@5147
   156
    SDL_RenderClear(renderer);
slouken@3264
   157
slouken@3265
   158
    /* Test points */
slouken@5147
   159
    SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
slouken@5147
   160
    SDL_RenderDrawPoint(renderer, 0, 0);
slouken@5297
   161
    SDL_RenderDrawPoint(renderer, viewport.w-1, 0);
slouken@5297
   162
    SDL_RenderDrawPoint(renderer, 0, viewport.h-1);
slouken@5297
   163
    SDL_RenderDrawPoint(renderer, viewport.w-1, viewport.h-1);
slouken@3264
   164
slouken@3265
   165
    /* Test horizontal and vertical lines */
slouken@5147
   166
    SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
slouken@5297
   167
    SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
slouken@5297
   168
    SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
slouken@5297
   169
    SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
slouken@5297
   170
    SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
slouken@3265
   171
slouken@3266
   172
    /* Test fill and copy */
slouken@5147
   173
    SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
slouken@3266
   174
    temp.x = 1;
slouken@3266
   175
    temp.y = 1;
slouken@3266
   176
    temp.w = sprite_w;
slouken@3266
   177
    temp.h = sprite_h;
slouken@5147
   178
    SDL_RenderFillRect(renderer, &temp);
slouken@5147
   179
    SDL_RenderCopy(renderer, sprite, NULL, &temp);
slouken@5297
   180
    temp.x = viewport.w-sprite_w-1;
slouken@3265
   181
    temp.y = 1;
slouken@3265
   182
    temp.w = sprite_w;
slouken@3265
   183
    temp.h = sprite_h;
slouken@5147
   184
    SDL_RenderFillRect(renderer, &temp);
slouken@5147
   185
    SDL_RenderCopy(renderer, sprite, NULL, &temp);
slouken@3265
   186
    temp.x = 1;
slouken@5297
   187
    temp.y = viewport.h-sprite_h-1;
slouken@3265
   188
    temp.w = sprite_w;
slouken@3265
   189
    temp.h = sprite_h;
slouken@5147
   190
    SDL_RenderFillRect(renderer, &temp);
slouken@5147
   191
    SDL_RenderCopy(renderer, sprite, NULL, &temp);
slouken@5297
   192
    temp.x = viewport.w-sprite_w-1;
slouken@5297
   193
    temp.y = viewport.h-sprite_h-1;
slouken@3265
   194
    temp.w = sprite_w;
slouken@3265
   195
    temp.h = sprite_h;
slouken@5147
   196
    SDL_RenderFillRect(renderer, &temp);
slouken@5147
   197
    SDL_RenderCopy(renderer, sprite, NULL, &temp);
slouken@3265
   198
slouken@3265
   199
    /* Test diagonal lines */
slouken@5147
   200
    SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
slouken@5147
   201
    SDL_RenderDrawLine(renderer, sprite_w, sprite_h,
slouken@5297
   202
                       viewport.w-sprite_w-2, viewport.h-sprite_h-2);
slouken@5297
   203
    SDL_RenderDrawLine(renderer, viewport.w-sprite_w-2, sprite_h,
slouken@5297
   204
                       sprite_w, viewport.h-sprite_h-2);
slouken@3265
   205
aschiffler@7315
   206
    /* Conditionally move the sprites, bounce at the wall */
aschiffler@7315
   207
    if (iterations == -1 || iterations > 0) {
aschiffler@7315
   208
        for (i = 0; i < num_sprites; ++i) {
aschiffler@7315
   209
            position = &positions[i];
aschiffler@7315
   210
            velocity = &velocities[i];
aschiffler@7315
   211
            position->x += velocity->x;
aschiffler@7315
   212
            if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
philipp@9922
   213
                velocity->x = -velocity->x;
philipp@9922
   214
                position->x += velocity->x;
aschiffler@7315
   215
            }
aschiffler@7315
   216
            position->y += velocity->y;
aschiffler@7315
   217
            if ((position->y < 0) || (position->y >= (viewport.h - sprite_h))) {
philipp@9922
   218
                velocity->y = -velocity->y;
philipp@9922
   219
                position->y += velocity->y;
aschiffler@7315
   220
            }
aschiffler@7315
   221
aschiffler@7315
   222
        }
aschiffler@7315
   223
        
aschiffler@7315
   224
        /* Countdown sprite-move iterations and disable color changes at iteration end - used for visual tests. */
aschiffler@7315
   225
        if (iterations > 0) {
aschiffler@7315
   226
            iterations--;
aschiffler@7315
   227
            if (iterations == 0) {
aschiffler@7315
   228
                cycle_alpha = SDL_FALSE;
aschiffler@7315
   229
                cycle_color = SDL_FALSE;
aschiffler@7315
   230
            }
aschiffler@7315
   231
        }
aschiffler@7315
   232
    }
aschiffler@7315
   233
aschiffler@7315
   234
    /* Draw sprites */
slouken@1895
   235
    for (i = 0; i < num_sprites; ++i) {
slouken@1895
   236
        position = &positions[i];
philipp@9922
   237
slouken@1895
   238
        /* Blit the sprite onto the screen */
slouken@5147
   239
        SDL_RenderCopy(renderer, sprite, NULL, position);
slouken@1895
   240
    }
slouken@1895
   241
slouken@1895
   242
    /* Update the screen! */
slouken@5147
   243
    SDL_RenderPresent(renderer);
slouken@1895
   244
}
slouken@1895
   245
icculus@9278
   246
void
icculus@9278
   247
loop()
icculus@9278
   248
{
icculus@12210
   249
    Uint32 now;
icculus@9278
   250
    int i;
icculus@9278
   251
    SDL_Event event;
icculus@9278
   252
icculus@9278
   253
    /* Check for events */
icculus@9278
   254
    while (SDL_PollEvent(&event)) {
icculus@9278
   255
        SDLTest_CommonEvent(state, &event, &done);
icculus@9278
   256
    }
icculus@9278
   257
    for (i = 0; i < state->num_windows; ++i) {
icculus@9278
   258
        if (state->windows[i] == NULL)
icculus@9278
   259
            continue;
icculus@9278
   260
        MoveSprites(state->renderers[i], sprites[i]);
icculus@9278
   261
    }
philipp@9607
   262
#ifdef __EMSCRIPTEN__
philipp@9607
   263
    if (done) {
philipp@9607
   264
        emscripten_cancel_main_loop();
philipp@9607
   265
    }
philipp@9607
   266
#endif
icculus@12210
   267
icculus@12210
   268
    frames++;
icculus@12210
   269
    now = SDL_GetTicks();
icculus@12210
   270
    if (SDL_TICKS_PASSED(now, next_fps_check)) {
icculus@12210
   271
        /* Print out some timing information */
icculus@12210
   272
        const Uint32 then = next_fps_check - fps_check_delay;
icculus@12210
   273
        const double fps = ((double) frames * 1000) / (now - then);
icculus@12210
   274
        SDL_Log("%2.2f frames per second\n", fps);
icculus@12210
   275
        next_fps_check = now + fps_check_delay;
icculus@12210
   276
        frames = 0;
icculus@12210
   277
    }
icculus@12210
   278
icculus@9278
   279
}
icculus@9278
   280
slouken@1895
   281
int
slouken@1895
   282
main(int argc, char *argv[])
slouken@1895
   283
{
icculus@9278
   284
    int i;
philipp@9922
   285
    Uint64 seed;
slouken@7502
   286
    const char *icon = "icon.bmp";
slouken@1895
   287
slouken@1914
   288
    /* Initialize parameters */
slouken@1914
   289
    num_sprites = NUM_SPRITES;
slouken@1914
   290
slouken@1914
   291
    /* Initialize test framework */
slouken@6785
   292
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
slouken@1914
   293
    if (!state) {
slouken@1914
   294
        return 1;
slouken@1895
   295
    }
icculus@5520
   296
slouken@1914
   297
    for (i = 1; i < argc;) {
slouken@1914
   298
        int consumed;
slouken@1895
   299
slouken@6785
   300
        consumed = SDLTest_CommonArg(state, i);
slouken@1915
   301
        if (consumed == 0) {
slouken@1916
   302
            consumed = -1;
slouken@1916
   303
            if (SDL_strcasecmp(argv[i], "--blend") == 0) {
slouken@1916
   304
                if (argv[i + 1]) {
slouken@1916
   305
                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
slouken@2884
   306
                        blendMode = SDL_BLENDMODE_NONE;
slouken@1916
   307
                        consumed = 2;
slouken@1916
   308
                    } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
slouken@2884
   309
                        blendMode = SDL_BLENDMODE_BLEND;
slouken@1916
   310
                        consumed = 2;
slouken@1916
   311
                    } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
slouken@2884
   312
                        blendMode = SDL_BLENDMODE_ADD;
slouken@1916
   313
                        consumed = 2;
slouken@5184
   314
                    } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
slouken@5184
   315
                        blendMode = SDL_BLENDMODE_MOD;
slouken@5184
   316
                        consumed = 2;
slouken@11282
   317
                    } else if (SDL_strcasecmp(argv[i + 1], "sub") == 0) {
slouken@11282
   318
                        blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT, SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT);
slouken@11282
   319
                        consumed = 2;
slouken@1916
   320
                    }
slouken@1916
   321
                }
aschiffler@7315
   322
            } else if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
aschiffler@7315
   323
                if (argv[i + 1]) {
aschiffler@7315
   324
                    iterations = SDL_atoi(argv[i + 1]);
aschiffler@7315
   325
                    if (iterations < -1) iterations = -1;
aschiffler@7315
   326
                    consumed = 2;
aschiffler@7315
   327
                }
slouken@1985
   328
            } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
slouken@1985
   329
                cycle_color = SDL_TRUE;
slouken@1985
   330
                consumed = 1;
slouken@1985
   331
            } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
slouken@1985
   332
                cycle_alpha = SDL_TRUE;
slouken@1985
   333
                consumed = 1;
slouken@1916
   334
            } else if (SDL_isdigit(*argv[i])) {
slouken@1916
   335
                num_sprites = SDL_atoi(argv[i]);
slouken@1916
   336
                consumed = 1;
slouken@7502
   337
            } else if (argv[i][0] != '-') {
slouken@7502
   338
                icon = argv[i];
slouken@7502
   339
                consumed = 1;
slouken@1916
   340
            }
slouken@1915
   341
        }
slouken@1914
   342
        if (consumed < 0) {
aschiffler@7639
   343
            SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
slouken@6785
   344
                    argv[0], SDLTest_CommonUsage(state));
slouken@1895
   345
            quit(1);
slouken@1895
   346
        }
slouken@1914
   347
        i += consumed;
slouken@1895
   348
    }
slouken@6785
   349
    if (!SDLTest_CommonInit(state)) {
slouken@1914
   350
        quit(2);
slouken@1895
   351
    }
slouken@1895
   352
slouken@1895
   353
    /* Create the windows, initialize the renderers, and load the textures */
slouken@1914
   354
    sprites =
slouken@3685
   355
        (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
slouken@1914
   356
    if (!sprites) {
aschiffler@7639
   357
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
slouken@1895
   358
        quit(2);
slouken@1895
   359
    }
slouken@1914
   360
    for (i = 0; i < state->num_windows; ++i) {
slouken@5147
   361
        SDL_Renderer *renderer = state->renderers[i];
slouken@5147
   362
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
slouken@5147
   363
        SDL_RenderClear(renderer);
slouken@1895
   364
    }
slouken@7502
   365
    if (LoadSprite(icon) < 0) {
slouken@1895
   366
        quit(2);
slouken@1895
   367
    }
slouken@1895
   368
slouken@1895
   369
    /* Allocate memory for the sprite info */
slouken@1895
   370
    positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
slouken@1895
   371
    velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
slouken@1895
   372
    if (!positions || !velocities) {
aschiffler@7639
   373
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
slouken@1895
   374
        quit(2);
slouken@1895
   375
    }
aschiffler@7315
   376
aschiffler@7315
   377
    /* Position sprites and set their velocities using the fuzzer */ 
aschiffler@7315
   378
    if (iterations >= 0) {
aschiffler@7315
   379
        /* Deterministic seed - used for visual tests */
aschiffler@7315
   380
        seed = (Uint64)iterations;
aschiffler@7315
   381
    } else {
aschiffler@7315
   382
        /* Pseudo-random seed generated from the time */
aschiffler@7315
   383
        seed = (Uint64)time(NULL);
aschiffler@7315
   384
    }
aschiffler@7315
   385
    SDLTest_FuzzerInit(seed);
slouken@1895
   386
    for (i = 0; i < num_sprites; ++i) {
aschiffler@7315
   387
        positions[i].x = SDLTest_RandomIntegerInRange(0, state->window_w - sprite_w);
aschiffler@7315
   388
        positions[i].y = SDLTest_RandomIntegerInRange(0, state->window_h - sprite_h);
slouken@1895
   389
        positions[i].w = sprite_w;
slouken@1895
   390
        positions[i].h = sprite_h;
slouken@1895
   391
        velocities[i].x = 0;
slouken@1895
   392
        velocities[i].y = 0;
slouken@1895
   393
        while (!velocities[i].x && !velocities[i].y) {
aschiffler@7315
   394
            velocities[i].x = SDLTest_RandomIntegerInRange(-MAX_SPEED, MAX_SPEED);
aschiffler@7315
   395
            velocities[i].y = SDLTest_RandomIntegerInRange(-MAX_SPEED, MAX_SPEED);
slouken@1895
   396
        }
slouken@1895
   397
    }
slouken@1895
   398
slouken@1915
   399
    /* Main render loop */
slouken@1895
   400
    frames = 0;
icculus@12210
   401
    next_fps_check = SDL_GetTicks() + fps_check_delay;
slouken@1895
   402
    done = 0;
icculus@9278
   403
icculus@9278
   404
#ifdef __EMSCRIPTEN__
icculus@9278
   405
    emscripten_set_main_loop(loop, 0, 1);
icculus@9278
   406
#else
slouken@1895
   407
    while (!done) {
icculus@9278
   408
        loop();
slouken@1895
   409
    }
icculus@9278
   410
#endif
slouken@1895
   411
slouken@1895
   412
    quit(0);
slouken@5147
   413
    return 0;
slouken@1895
   414
}
slouken@1895
   415
slouken@1895
   416
/* vi: set ts=4 sw=4 expandtab: */