openal and fontft memleak fixes from keltar
[fegdk.git] / tools / fgp / main.cpp
blobce155d1a72a33821cd62f081adb09c53634f2d39
1 #include <fegdk/pch.h>
2 #include "fgp.h"
3 #include <fegdk/f_error.h>
4 #include <fegdk/f_engine.h>
5 #include <fegdk/f_application.h>
6 #include <fegdk/f_console.h>
7 #include "simplemodel.h"
8 #include "config.h"
10 // Log: main.cpp,v
12 // Revision 1.10 2004/11/10 01:22:32 waker
13 // newver
15 // Revision 1.9 2003/11/09 10:56:47 waker
16 // changed copyright message, added engine support (due to memleaks)
18 // Revision 1.8 2003/06/10 10:02:00 waker
19 // fixed fgp to recompile under new engine rev
21 // Revision 1.7 2002/12/02 17:10:45 waker
22 // help fixed a bit, played with tgs data
24 // Revision 1.6 2002/12/02 12:05:03 waker
25 // help updated, tiny code cleanup took place
28 void nextarg (int &i, int &argc)
30 i++;
31 if (i >= argc)
32 throw fe::genericError ("invalid command line");
35 void printCommandsHelp (void)
37 printf ("fgp commands are:\n");
38 printf ("\tmcvt\tconverts model from text .mdl format to binary .bmdl format\n");
39 printf ("\tsmd\tconverts model from text .mdl format to binary .smd format (simple model)\n");
40 printf ("\tnmap\tbuilds normalmap texture from pair of hi and low poly models\n");
41 printf (" (specify the --help global option for a list of other help options)\n");
44 void printOptionsHelp (void)
46 printf ("No options available.\n");
49 void printCommandHelp (const char *cmd)
51 if (!strcmp (cmd, "mcvt"))
53 printf ("Usage: fgp mcvt file.mdl\n");
55 else if (!strcmp (cmd, "nmap"))
57 printf ("Usage: fgp nmap texwidth texheight hipoly poly\n");
59 else if (!strcmp (cmd, "smd"))
61 printf ("Usage: fgp smd [-f [-be]] file.mdl\n");
62 printf (" -f fixed-point format\n");
63 printf (" -be big-endian byte order\n");
65 else
67 printCommandsHelp ();
71 void printUsage ()
73 printf ("usage: fgp.exe [options] command [command-options-and-arguments]\n");
74 printf (" where options are [...], etc.\n");
75 printf (" (specify --help-options for a list of options)\n");
76 printf (" where command are nmap, mcvt, etc.\n");
77 printf (" (specify --help-commands for a list of commands)\n");
78 printf (" where command-options-and-arguments depend on the specific command\n");
79 printf (" (specify --help followed by a command name for command-specific help)\n");
80 printf (" specify --help to recieve this message\n");
81 printf ("\nfgp-%s (FE Geometry Processor)\n"), VERSION;
82 printf ("written by waker (c) 2001-2005.\n");
83 printf ("licensed under the terms of GNU General Public License.\n");
86 int execute (int argc, char *argv[])
88 if (argc <= 1)
90 printUsage ();
91 return -1;
94 // options
96 // normalmap
97 bool normalmap = false;
98 int nmapw;
99 int nmaph;
100 fe::cStr hipolymdl;
101 fe::cStr lopolymdl;
103 // model conversion
104 bool convertmodel = false;
105 fe::cStr mdlname;
107 // smd conversion
108 bool convert_smd = false;
109 int smd_flags = 0;
111 // parse arguments
112 for (int i = 1; i < argc; i++)
114 if (!strcmp (argv[i], "nmap"))
116 // create normal map
117 nextarg (i, argc);
118 nmapw = atoi (argv[i]);
119 nextarg (i, argc);
120 nmaph = atoi (argv[i]);
121 nextarg (i, argc);
122 hipolymdl = argv[i];
123 nextarg (i, argc);
124 lopolymdl = argv[i];
126 normalmap = true;
128 else if (!strcmp (argv[i], "mcvt"))
130 // convert model to binary fmt
131 nextarg (i, argc);
132 printf ("setting mdlname to %s...\n", argv[i]);
133 mdlname = argv[i];
135 convertmodel = true;
137 else if (!strcmp (argv[i], "smd"))
139 // convert model to binary fmt
141 smd_flags = 0;
143 for (;;)
145 nextarg (i, argc);
147 if (!strcmp (argv[i], "-f"))
148 smd_flags |= SMF_FIXED;
149 else if (!strcmp (argv[i], "-be"))
150 smd_flags |= SMF_BIGENDIAN;
151 else
152 break;
155 mdlname = argv[i];
157 convert_smd = true;
159 else if (!strcmp (argv[i], "--help"))
161 // print help msg
162 if (i == argc-1)
163 printUsage ();
164 else
166 i++;
167 printCommandHelp (argv[i]);
170 else if (!strcmp (argv[i], "--help-commands"))
172 printCommandsHelp ();
174 else if (!strcmp (argv[i], "--help-options"))
176 printOptionsHelp ();
180 if (normalmap)
182 printf ("normalmap generation is temporarily disabled\n");
183 // ExportNormalMap (nmapw, nmaph, hipolymdl, lopolymdl);
186 if (convertmodel)
187 ConvertModel (mdlname);
189 if (convert_smd)
190 ConvertSimpleModel (mdlname, smd_flags);
192 // MakeLevelFile (argc, argv);
193 return 0;
196 class DummyApp : public fe::application
198 public:
199 DummyApp (void)
202 ~DummyApp (void)
205 void configure (void)
207 fe::g_engine->getConsole ()->command ("sys_int_mainloop 0");
208 fe::g_engine->getConsole ()->command ("sys_profile null");
210 void init (void)
213 void free (void)
216 const char* appName (void) const
218 return PACKAGE " " VERSION;
220 const char* dataPath (void) const
222 return "./";
227 int main (int argc, char *argv[])
229 fe::engine *eng = new fe::engine ();
230 DummyApp *app = new DummyApp ();
231 eng->run (app, argc, argv);
232 int res = execute (argc, argv);
233 eng->release ();
234 #if defined(_DEBUG) && defined(_WIN32)
235 _CrtDumpMemoryLeaks ();
236 #endif
237 return res;