Add option to disable sound from cmdline
[attac-man.git] / main.c
blob4b799485d16fc22680551baafc595dbd5c120721
1 /*
2 Pacman Arena
3 Copyright (C) 2003 Nuno Subtil
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 static const char cvsid[] =
21 "$Id: main.c,v 1.60 2003/11/27 22:11:57 nsubtil Exp $";
23 #ifdef _WIN32
24 #include <windows.h>
25 #endif
27 #include <GL/gl.h>
28 #include <SDL.h>
29 #include <SDL_net.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
34 #include "audio.h"
35 #include "object.h"
36 #include "game.h"
37 #include "map.h"
38 #include "player.h"
39 #include "render.h"
40 #include "m_math.h"
41 #include "menu.h"
42 #include "screen.h"
43 #include "net.h"
45 int parse_resolution(char *res, int *w, int *h, int *bpp)
47 char res_copy[80];
48 char *p;
50 snprintf(res_copy, sizeof(res_copy)-1, "%s", res);
51 p = strtok(res_copy, "x");
52 if (!p)
53 goto out_err;
54 *w = atoi(p);
55 if (*w <= 0)
56 goto out_err;
58 p = strtok(NULL, "x");
59 if (!p)
60 goto out_err;
61 *h = atoi(p);
62 if (*h <= 0)
63 goto out_err;
65 p = strtok(NULL, "x");
66 if (!p)
67 goto out_ok;
68 *bpp = atoi(p);
69 if (*bpp <= 0)
70 goto out_err;
72 out_ok:
73 return 0;
74 out_err:
75 printf("Could not parse resolution '%s'\n", res);
76 return 1;
80 int main(int argc, char **argv)
82 int opt, ret = 0;
83 int width = 800, height = 600, bpp = 32, fullscreen = 0;
84 int enable_sound = 1;
86 while ((opt = getopt(argc, argv, "fwr:q")) != EOF) {
87 switch(opt) {
88 case 'f':
89 fullscreen = 1;
90 break;
91 case 'w':
92 fullscreen = 0;
93 break;
94 case 'q':
95 enable_sound = 0;
96 break;
97 case 'r':
98 if (parse_resolution(optarg, &width, &height,
99 &bpp) != 0)
100 return 1;
101 printf("Set resolution to %dx%dx%d\n",
102 width, height, bpp);
103 break;
104 default:
105 fprintf(stderr, "Invalid command line option: %c\n",
106 opt);
107 ret = 1;
108 case 'h':
109 /* fixme: help? */
110 return ret;
115 render_reshape_window(screen->w, screen->h);
118 srand(SDL_GetTicks());
120 screen_init(fullscreen, width, height, bpp);
121 audio_init(enable_sound);
123 /* preload */
125 object_read_file("gfx/pacman-moving.3d", &last_update);
126 object_read_file("gfx/pacman-dying.3d", &last_update);
127 object_read_file("gfx/pacman-stopped.3d", &last_update);
128 object_read_file("gfx/ghost-green-moving.3d", &last_update);
129 object_read_file("gfx/ghost-green-dying.3d", &last_update);
130 object_read_file("gfx/ghost-green-returning.3d", &last_update);
133 if(argc > 1 && strcmp(argv[1], "--server") == 0)
134 net_server_init();
136 if(argc > 1 && strcmp(argv[1], "--connect") == 0)
137 net_client_init(argv[2]);
139 for(;;)
140 menu_run();
142 return 0;