~ubuntu-branches/ubuntu/maverick/glbsp/maverick

« back to all changes in this revision

Viewing changes to nodeview/main.cc

  • Committer: Bazaar Package Importer
  • Author(s): Darren Salt
  • Date: 2008-01-30 13:33:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080130133349-kgojg33vyiu8xbvp
Tags: 2.24-1
* New upstream release.
* Bumped the lib soname and the library package name due to one silly
  little binary incompatibility caused by changes in an exported struct.
  (Safe; nothing else currently in the archive has ever used libglbsp2.)
* Removed my patches since they're all applied upstream.
* Updated the list of documentation files.
* Build-time changes:
  - Switched from dh_movefiles to dh_install.
  - Updated my makefile to cope with upstream changes.
  - Corrected for debian-rules-ignores-make-clean-error.
  - Corrected for substvar-source-version-is-deprecated.
  - Link libglbsp, rather than glbsp, with libm and libz.
* Fixed shlibdeps. (Closes: #460387)
* Bumped standards version to 3.7.3 (no other changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//------------------------------------------------------------------------
 
2
//  MAIN Program
 
3
//------------------------------------------------------------------------
 
4
//
 
5
//  GL-Node Viewer (C) 2004-2007 Andrew Apted
 
6
//
 
7
//  This program is free software; you can redistribute it and/or
 
8
//  modify it under the terms of the GNU General Public License
 
9
//  as published by the Free Software Foundation; either version 2
 
10
//  of the License, or (at your option) any later version.
 
11
//
 
12
//  This program is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
//  GNU General Public License for more details.
 
16
//
 
17
//------------------------------------------------------------------------
 
18
 
 
19
// this includes everything we need
 
20
#include "defs.h"
 
21
 
 
22
 
 
23
#define GUI_PrintMsg  printf
 
24
 
 
25
 
 
26
static bool inited_FLTK = false;
 
27
 
 
28
static int main_result = 0;
 
29
 
 
30
 
 
31
static void ShowTitle(void)
 
32
{
 
33
  GUI_PrintMsg(
 
34
    "\n"
 
35
    "**** " PROG_NAME "  (C) 2007 Andrew Apted ****\n\n"
 
36
  );
 
37
}
 
38
 
 
39
static void ShowInfo(void)
 
40
{
 
41
  GUI_PrintMsg(
 
42
    "Info...\n\n"
 
43
  );
 
44
}
 
45
 
 
46
 
 
47
void MainSetDefaults(void)
 
48
{
 
49
}
 
50
 
 
51
void InitFLTK(void)
 
52
{
 
53
  Fl::scheme(NULL);
 
54
 
 
55
  fl_message_font(FL_HELVETICA, 16);
 
56
 
 
57
  Fl_File_Icon::load_system_icons();
 
58
 
 
59
  inited_FLTK = true;
 
60
}
 
61
 
 
62
static void DisplayError(const char *str, ...)
 
63
{
 
64
  va_list args;
 
65
 
 
66
  if (inited_FLTK)
 
67
  {
 
68
    char buffer[1024];
 
69
 
 
70
    va_start(args, str);
 
71
    vsprintf(buffer, str, args);
 
72
    va_end(args);
 
73
 
 
74
    fl_alert("%s", buffer);
 
75
  }
 
76
  else
 
77
  {
 
78
    va_start(args, str);
 
79
    vfprintf(stderr, str, args);
 
80
    va_end(args);
 
81
 
 
82
    fprintf(stderr, "\n");
 
83
  }
 
84
 
 
85
  main_result = 9;
 
86
}
 
87
 
 
88
//------------------------------------------------------------------------
 
89
//  MAIN PROGRAM
 
90
//------------------------------------------------------------------------
 
91
 
 
92
int main(int argc, char **argv)
 
93
{
 
94
  try
 
95
  {
 
96
    // skip program name
 
97
    argv++, argc--;
 
98
 
 
99
    ArgvInit(argc, (const char **)argv);
 
100
 
 
101
    InitDebug(ArgvFind(0, "debug") >= 0);
 
102
    InitEndian();
 
103
 
 
104
    if (ArgvFind('?', NULL) >= 0 || ArgvFind('h', "help") >= 0)
 
105
    {
 
106
      ShowTitle();
 
107
      ShowInfo();
 
108
      exit(1);
 
109
    }
 
110
 
 
111
    InitFLTK();
 
112
 
 
113
    // set defaults, also initializes the nodebuildxxxx stuff
 
114
    MainSetDefaults();
 
115
 
 
116
    const char *filename = "data/doom2.wad";
 
117
 
 
118
    if (arg_count > 0 && ! ArgvIsOption(0))
 
119
      filename = arg_list[0];
 
120
    else
 
121
    {
 
122
      int params;
 
123
      int idx = ArgvFind(0, "file", &params);
 
124
 
 
125
      if (idx >= 0 && params >= 1)
 
126
        filename = arg_list[idx + 1];
 
127
    }
 
128
 
 
129
    if (CheckExtension(filename, "gwa"))
 
130
      FatalError("Main file must be a normal WAD (not GWA).\n");
 
131
 
 
132
    the_wad = wad_c::Load(filename);
 
133
    if (!the_wad)
 
134
      FatalError("Unable to read WAD file: %s\n", filename);
 
135
 
 
136
    const char *gwa_name = ReplaceExtension(filename, "gwa");
 
137
 
 
138
    if (FileExists(gwa_name))
 
139
    {
 
140
      the_gwa = wad_c::Load(gwa_name);
 
141
      if (!the_gwa)
 
142
        FatalError("Unable to read GWA file: %s\n", gwa_name);
 
143
    }
 
144
 
 
145
    const char *level_name = NULL;
 
146
    {
 
147
      int params;
 
148
      int idx = ArgvFind(0, "warp", &params);
 
149
 
 
150
      if (idx >= 0 && params >= 1)
 
151
        level_name = arg_list[idx + 1];
 
152
 
 
153
      if (! level_name)
 
154
      {
 
155
        level_name = the_wad->FirstLevelName();
 
156
 
 
157
        if (! level_name)
 
158
          FatalError("Unable to find ANY level in WAD.\n");
 
159
      }
 
160
    }
 
161
 
 
162
    path_c *path = NULL;
 
163
    {
 
164
      int params;
 
165
      int idx = ArgvFind(0, "path", &params);
 
166
 
 
167
      if (idx >= 0 && params >= 1)
 
168
        path = path_c::ReadFile(arg_list[idx + 1]);
 
169
    }
 
170
 
 
171
    LoadLevel(level_name);
 
172
 
 
173
    guix_win = new Guix_MainWin(PROG_NAME);
 
174
 
 
175
    if (path)
 
176
      guix_win->grid->SetPath(path);
 
177
 
 
178
    double lx, ly, hx, hy;
 
179
    LevelGetBounds(&lx, &ly, &hx, &hy);
 
180
    guix_win->grid->FitBBox(lx, ly, hx, hy);
 
181
 
 
182
    guix_win->info->SetMap(level_name);
 
183
    guix_win->info->SetNodes("GL");  // FIXME: node version
 
184
 
 
185
    guix_win->info->SetNodeIndex(lev_nodes.num - 1);
 
186
 
 
187
    // run the GUI until the user quits
 
188
    while (! guix_win->want_quit)
 
189
      Fl::wait();
 
190
  }
 
191
  catch (const char * err)
 
192
  {
 
193
    DisplayError("%s", err);
 
194
  }
 
195
  catch (assert_fail_c err)
 
196
  {
 
197
    DisplayError("Sorry, an internal error occurred:\n%s", err.GetMessage());
 
198
  }
 
199
  catch (...)
 
200
  {
 
201
    DisplayError("An unknown problem occurred (UI code)");
 
202
  }
 
203
 
 
204
  delete guix_win;
 
205
  delete the_wad;
 
206
  delete the_gwa;
 
207
 
 
208
  TermDebug();
 
209
 
 
210
  return main_result;
 
211
}
 
212