/* Starshatter: The Open Source Project Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors Copyright (c) 1997-2006, Destroyer Studios LLC. AUTHOR: John DiCamillo */ #ifndef Game_h #define Game_h #include "ApplicationDX9.h" #include "Types.h" #include "Screen.h" #include "Video.h" // +--------------------------------------------------------------------+ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void FlushKeys(); void BufferKey(int vkey); int GetKey(); int GetKeyPlus(int& key, int& shift); void ProcessKeyMessage(); // +--------------------------------------------------------------------+ class Universe; class Sound; class SoundCard; class Video; class VideoFactory; class VideoSettings; class Text; // +--------------------------------------------------------------------+ class Game : public ApplicationDX9 { public: static const char* TYPENAME() { return "Game"; } enum STATUS { OK, RUN, EXIT, PANIC, INIT_FAILED, TOO_MANY }; Game(); virtual ~Game(); // // MAIN GAME FUNCTIONALITY: // virtual bool Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow); virtual int Run(); virtual void Exit(); virtual bool OnPaint() { return false; } virtual bool OnHelp() { return false; } virtual void Activate(bool f); virtual void Pause(bool f); int Status() const { return status; } const RenderStats& GetPolyStats() { return stats; } // // GENERAL GAME CLASS UTILITY METHODS: // static Game* GetInstance(); static void Panic(const char* msg=0); static const char* GetPanicMessage() { return panicbuf; } bool DisplayModeSupported(int w, int h, int bpp); int MaxTexSize(); int MaxTexAspect(); int GammaLevel(); void SetGammaLevel(int g); void SetMaxTexSize(int n); DWORD RealTime(); DWORD GameTime(); DWORD TimeCompression(); void SetTimeCompression(DWORD comp); DWORD Frame(); void ResetGameTime(); void SkipGameTime(double seconds); double FrameRate(); double FrameTime(); double GUITime(); void SetMaxFrameLength(double seconds) { max_frame_length = seconds; } void SetMinFrameLength(double seconds) { min_frame_length = seconds; } double GetMaxFrameLength() { return max_frame_length; } double GetMinFrameLength() { return min_frame_length; } Video* GetVideo(); Color GetScreenColor(); void SetScreenColor(Color c); int GetScreenWidth(); int GetScreenHeight(); bool Active() { return active; } bool Paused() { return paused; } bool Server() { return server; } bool ShowMouse() { return show_mouse; } bool IsWindowed(); HINSTANCE GetHINST(); HWND GetHWND(); virtual bool GameLoop(); virtual void UpdateWorld(); virtual void GameState(); virtual void UpdateScreen(); virtual void CollectStats(); virtual bool InitApplication(HINSTANCE); virtual bool InitInstance(HINSTANCE, int); virtual bool InitGame(); virtual bool InitVideo(); virtual bool ResizeVideo(); virtual bool ResetVideo(); virtual bool ToggleFullscreen(); virtual bool AdjustWindowForChange(); virtual bool SetupPalette(); virtual bool LoadPalette(PALETTEENTRY* pal, BYTE* inv); virtual void ShowStats(); protected: friend LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM uParam, LPARAM lParam); Universe* world; VideoFactory* video_factory; Video* video; VideoSettings* video_settings; SoundCard* soundcard; Screen* screen; int gamma; int max_tex_size; RenderStats stats; DWORD totaltime; PALETTEENTRY standard_palette[256]; BYTE inverse_palette[32768]; HINSTANCE hInst; HWND hwnd; HMENU hmenu; DWORD winstyle; char* app_name; char* title_text; char* palette_name; // Internal variables for the state of the app bool is_windowed; bool is_active; bool is_device_lost; bool is_minimized; bool is_maximized; bool ignore_size_change; bool is_device_initialized; bool is_device_restored; DWORD window_style; // Saved window style for mode switches RECT bounds_rect; // Saved window bounds for mode switches RECT client_rect; // Saved client area size for mode switches double gui_seconds; double seconds; double frame_rate; int frame_count; int frame_count0; int frame_time; int frame_time0; int status; int exit_code; Color screen_color; bool active; bool paused; bool server; bool show_mouse; DWORD base_game_time; DWORD real_time; DWORD game_time; DWORD time_comp; DWORD frame_number; double max_frame_length; double min_frame_length; static char panicbuf[256]; }; // +--------------------------------------------------------------------+ #endif // Game_h