aboutsummaryrefslogtreecommitdiff
path: root/source/main.c
blob: bc55b2daef8a0335503181fc956b76f09d6d3898 (plain) (blame)
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
#include "all.h"
#include <options.h>

#define arg if (++arguments, !--count) { goto help; } else
config_t Arguments(int count, char ** arguments) {
  config_t config = {0};
  while (++arguments, --count > 0) {
    while (**arguments == '-') { ++*arguments; }
    struct options * option = options_lookup(*arguments,strlen(*arguments));
    if (!option) {
      printf("Unknown option '%s', try 'help'\n", *arguments);
      goto abort;
    }
    switch (option->number) {
    case OPTION_HELP: {
      help:
      printf("help/h/?          --            -- This.\n"
             "resolution        -- <x>        -- The on-display resolution squared\n"
             "fps               -- <x>        -- Framerate\n"
             "ups               -- <x>        -- Updates\n"
             "font              -- </path/to> -- Glorious Font\n"
             "spritesheet       -- </path/to> -- The spritesheet for displaying all of reality\n"
             "spritesheet_scale -- <x>        -- The square scale of the above\n"
             "players           -- <x>        -- N players\n"
             "map/map_size      -- <x y>      -- the in-game map size\n"
        );
      exit(0); }
    case OPTION_RESOLUTION: {
      arg { config.resolution_x = atoi(*arguments); }
      break; }
    case OPTION_FPS: {
      arg { config.fps = atoi(*arguments); }
      break; }
    case OPTION_UPS: {
      arg { config.ups = atoi(*arguments); }
      break; }
    case OPTION_PLAYER_COUNT: {
      arg { config.player_count = atoi(*arguments); }
      break; }
    case OPTION_MAP_SIZE: {
      arg { config.map_x = atoi(*arguments); }
      arg { config.map_y = atoi(*arguments); }
      break; }
    case OPTION_SPRITESHEET: {
      arg { strlcpy(config.spritesheet, *arguments, CONFIG_STRING_LIMIT); }
      break; }
    case OPTION_SPRITESHEET_SCALE: {
      arg { config.spritesheet_scale = atoi(*arguments); }
      break; }
    case OPTION_FONT: {
      arg { strlcpy(config.font, *arguments, CONFIG_STRING_LIMIT); }
      break; }
    }
  }
  return config;
abort:
  exit(1);
}

int Main(int count, char ** arguments)
{
  char * window_name = arguments[0];
  config_t config = Arguments(count, arguments);
  char * p = strchr(window_name, '/');
  strlcpy(config.window_name, p ? p+1 : window_name, CONFIG_STRING_LIMIT);
  srand(time(NULL));
  Root(window_name);
  GameStart(config);
  return 0;
}

int main (int count, char ** arguments) __attribute__((alias("Main")));