2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
9 // PofView.cpp : Defines the class behaviors for the application.
17 #include "pofviewdoc.h"
18 #include "pofviewview.h"
32 #include "systemvars.h"
38 static char THIS_FILE[] = __FILE__;
41 int Pofview_running = 1;
43 /////////////////////////////////////////////////////////////////////////////
46 BEGIN_MESSAGE_MAP(CPofViewApp, CWinApp)
47 //{{AFX_MSG_MAP(CPofViewApp)
48 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
49 // NOTE - the ClassWizard will add and remove mapping macros here.
50 // DO NOT EDIT what you see in these blocks of generated code!
52 // Standard file based document commands
53 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
54 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
55 // Standard print setup command
56 ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
59 /////////////////////////////////////////////////////////////////////////////
60 // CPofViewApp construction
62 CPofViewApp::CPofViewApp()
64 // TODO: add construction code here,
65 // Place all significant initialization in InitInstance
68 /////////////////////////////////////////////////////////////////////////////
69 // The one and only CPofViewApp object
73 /////////////////////////////////////////////////////////////////////////////
74 // CPofViewApp initialization
76 BOOL CPofViewApp::InitInstance()
78 // Standard initialization
79 // If you are not using these features and wish to reduce the size
80 // of your final executable, you should remove from the following
81 // the specific initialization routines you do not need.
84 Enable3dControls(); // Call this when using MFC in a shared DLL
86 Enable3dControlsStatic(); // Call this when linking to MFC statically
89 LoadStdProfileSettings(); // Load standard INI file options (including MRU)
91 // Register the application's document templates. Document templates
92 // serve as the connection between documents, frame windows and views.
94 CMultiDocTemplate* pDocTemplate;
95 pDocTemplate = new CMultiDocTemplate(
97 RUNTIME_CLASS(CPofViewDoc),
98 RUNTIME_CLASS(CChildFrame), // custom MDI child frame
99 RUNTIME_CLASS(CPofViewView));
100 AddDocTemplate(pDocTemplate);
102 // create main MDI Frame window
103 CMainFrame* pMainFrame = new CMainFrame;
104 if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
106 m_pMainWnd = pMainFrame;
108 // Enable drag/drop open
109 m_pMainWnd->DragAcceptFiles();
111 // setup the fred exe directory so CFILE can init properly
113 char *c = GetCommandLine();
115 char *tok = strtok(c, " ");
121 cfile_init(__argv[0]);
122 palette_load_table( "gamepalette1-01" );
123 gr_init(GR_640, GR_SOFTWARE, 8, 640, 480);
127 gr_init_font( "font01.vf" );
128 m_timer = timer_get_milliseconds();
131 // Enable DDE Execute open
133 RegisterShellFileTypes(TRUE);
135 // Parse command line for standard shell commands, DDE, file open
136 CCommandLineInfo cmdInfo;
137 ParseCommandLine(cmdInfo);
139 // DON'T display a new MDI child window during startup!!!
140 if ( cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew ) {
141 cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
144 // Dispatch commands specified on the command line
145 if (!ProcessShellCommand(cmdInfo))
148 // The main window has been initialized, so show and update it.
149 pMainFrame->ShowWindow(m_nCmdShow);
150 pMainFrame->UpdateWindow();
155 /////////////////////////////////////////////////////////////////////////////
156 // CAboutDlg dialog used for App About
158 class CAboutDlg : public CDialog
164 //{{AFX_DATA(CAboutDlg)
165 enum { IDD = IDD_ABOUTBOX };
168 // ClassWizard generated virtual function overrides
169 //{{AFX_VIRTUAL(CAboutDlg)
171 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
176 //{{AFX_MSG(CAboutDlg)
177 // No message handlers
179 DECLARE_MESSAGE_MAP()
182 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
184 //{{AFX_DATA_INIT(CAboutDlg)
188 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
190 CDialog::DoDataExchange(pDX);
191 //{{AFX_DATA_MAP(CAboutDlg)
195 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
196 //{{AFX_MSG_MAP(CAboutDlg)
197 // No message handlers
201 // App command to run the dialog
202 void CPofViewApp::OnAppAbout()
208 /////////////////////////////////////////////////////////////////////////////
209 // CPofViewApp commands
212 CPofViewView * GetView()
214 CMDIChildWnd * pChild =
215 ((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActive();
220 CView * pView = pChild->GetActiveView();
225 // Fail if view is of wrong kind
226 // (this could occur with splitter windows, or additional
227 // views on a single document
228 if ( ! pView->IsKindOf( RUNTIME_CLASS(CPofViewView) ) )
231 return (CPofViewView *) pView;
235 // Stuff for showing ship thrusters.
236 typedef struct thrust_anim {
239 float time; // in seconds
242 #define NUM_THRUST_ANIMS 6
243 #define THRUST_ANIM_NORMAL 0
244 #define THRUST_ANIM_AFTERBURNER 1
245 #define THRUST_ANIM_GLOW_NORMAL 2
246 #define THRUST_ANIM_GLOW_AFTERBURNER 3
248 static thrust_anim Thrust_anims[NUM_THRUST_ANIMS];
249 extern char Thrust_anim_names[NUM_THRUST_ANIMS][MAX_FILENAME_LEN];
251 static int Thrust_anim_inited = 0;
253 int shipp_thruster_bitmap = -1; // What frame the current thruster bitmap is at for this ship
254 float shipp_thruster_frame = 0.0f; // Used to keep track of which frame the animation should be on.
256 int shipp_thruster_glow_bitmap = -1; // What frame the current thruster bitmap is at for this ship
257 float shipp_thruster_glow_frame = 0.0f; // Used to keep track of which frame the animation should be on.
258 float shipp_thruster_glow_noise = 1.0f;
260 // loads the animations for ship's afterburners
261 void init_thrusters()
266 if ( Thrust_anim_inited == 1 )
269 for ( i = 0; i < NUM_THRUST_ANIMS; i++ ) {
270 ta = &Thrust_anims[i];
272 ta->first_frame = bm_load_animation(Thrust_anim_names[i], &ta->num_frames, &fps);
273 if ( ta->first_frame == -1 ) {
274 Error(LOCATION,"Error loading animation file: %s\n",Thrust_anim_names[i]);
278 ta->time = i2fl(ta->num_frames)/fps;
280 // ta->first_frame = bm_load(Thrust_anim_names[i] );
281 // ta->num_frames = NOISE_NUM_FRAMES;
283 // if ( ta->first_frame == -1 ) {
284 // Error(LOCATION,"Error loading bitmap file: %s\n",Thrust_anim_names[i]);
288 // ta->time = i2fl(ta->num_frames)/fps;
292 Thrust_anim_inited = 1;
295 // JAS - figure out which thruster bitmap will get rendered next
296 // time around. ship_render needs to have shipp_thruster_bitmap set to
297 // a valid bitmap number, or -1 if we shouldn't render thrusters.
298 void do_thruster_frame( float thrust, int afterburner, float frametime )
302 thrust_anim *the_anim;
304 if ( !Thrust_anim_inited ) init_thrusters();
307 the_anim = &Thrust_anims[THRUST_ANIM_AFTERBURNER];
308 rate = 1.2f; // go at 1.2x faster when afterburners on
310 the_anim = &Thrust_anims[THRUST_ANIM_NORMAL];
311 // If thrust at 0, go at half as fast, full thrust; full framerate
312 // so set rate from 0.5 to 1.0, depending on thrust from 0 to 1
313 rate = 0.5f + thrust / 2.0f;
316 shipp_thruster_frame += frametime * rate;
319 if ( shipp_thruster_frame < 0.0f ) shipp_thruster_frame = 0.0f;
320 if ( shipp_thruster_frame > 100.0f ) shipp_thruster_frame = 0.0f;
322 if ( shipp_thruster_frame > the_anim->time ) {
323 shipp_thruster_frame -= the_anim->time;
325 framenum = fl2i( (shipp_thruster_frame*the_anim->num_frames) / the_anim->time );
326 if ( framenum < 0 ) framenum = 0;
327 if ( framenum >= the_anim->num_frames ) framenum = the_anim->num_frames-1;
329 // Get the bitmap for this frame
330 shipp_thruster_bitmap = the_anim->first_frame + framenum;
332 // mprintf(( "TF: %.2f\n", shipp_thruster_frame ));
338 the_anim = &Thrust_anims[THRUST_ANIM_GLOW_AFTERBURNER];
339 rate = 1.2f; // go at 1.2x faster when afterburners on
341 the_anim = &Thrust_anims[THRUST_ANIM_GLOW_NORMAL];
342 // If thrust at 0, go at half as fast, full thrust; full framerate
343 // so set rate from 0.5 to 1.0, depending on thrust from 0 to 1
344 rate = 0.5f + thrust / 2.0f;
347 shipp_thruster_glow_frame += frametime * rate;
350 if ( shipp_thruster_glow_frame < 0.0f ) shipp_thruster_glow_frame = 0.0f;
351 if ( shipp_thruster_glow_frame > 100.0f ) shipp_thruster_glow_frame = 0.0f;
353 if ( shipp_thruster_glow_frame > the_anim->time ) {
354 shipp_thruster_glow_frame -= the_anim->time;
356 framenum = fl2i( (shipp_thruster_glow_frame*the_anim->num_frames) / the_anim->time );
357 if ( framenum < 0 ) framenum = 0;
358 if ( framenum >= the_anim->num_frames ) framenum = the_anim->num_frames-1;
360 // Get the bitmap for this frame
361 shipp_thruster_glow_bitmap = the_anim->first_frame;
362 shipp_thruster_glow_noise = Noise[framenum];
364 // mprintf(( "TF: %.2f\n", shipp_thruster_frame ));
372 float model_thrust = 0.0f;
373 int model_afterburner = 0;
375 BOOL CPofViewApp::OnIdle(LONG lCount)
377 CWinApp::OnIdle(lCount);
379 CPofViewView* CurrentView;
381 int tmp_time = timer_get_milliseconds();
385 frame_time = ((float)(tmp_time-m_timer)) / 1000.0f;
386 flFrametime = frame_time;
390 if (pofview_focus<1) return FALSE;
392 CurrentView = GetView();
393 if ( !CurrentView ) return TRUE;
395 do_thruster_frame( model_thrust, model_afterburner, flFrametime );
397 CurrentView->MoveViewer(frame_time,TRUE,k);
399 pDC = CurrentView->GetDC();
400 if ( !pDC ) return TRUE;
402 CurrentView->OnDraw(pDC);
404 CurrentView->ReleaseDC(pDC);
409 int CPofViewApp::ExitInstance()
411 // TODO: Add your specialized code here and/or call the base class
413 return CWinApp::ExitInstance();