| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #pragma once
- //========================================================================
- // GameCode.h : Defines the entry point for the application.
- //
- // Part of the GameCode4 Application
- //
- // GameCode4 is the sample application that encapsulates much of the source code
- // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
- // "Rez" Graham, published by Charles River Media.
- // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
- //
- // If this source code has found it's way to you, and you think it has helped you
- // in any way, do the authors a favor and buy a new copy of the book - there are
- // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
- // by clicking here:
- // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
- //
- // There's a companion web site at http://www.mcshaffry.com/GameCode/
- //
- // The source code is managed and maintained through Google Code:
- // http://code.google.com/p/gamecode4/
- //
- // (c) Copyright 2012 Michael L. McShaffry and David Graham
- //
- // This program is free software; you can redistribute it and/or
- // modify it under the terms of the GNU Lesser GPL v3
- // as published by the Free Software Foundation.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
- //
- // You should have received a copy of the GNU Lesser GPL v3
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- //
- //========================================================================
- #include "../Mainloop/Initialization.h"
- #include "../Debugging/Logger.h"
- #include "BaseGameLogic.h"
- #include <SDL3/SDL.h>
- class EventManager;
- //
- // class GameCodeApp - Chapter X, page Y
- //
- class GameCodeApp
- {
- friend class OpenGLRenderer46;
- friend class LogMgr;
- protected:
- SDL_Window *m_Window;
- SDL_Renderer *m_SdlRenderer;
- SDL_GLContext m_GlContext;
- bool m_bIsRunning; // true if everything is initialized and the game is in the main loop
- bool m_bQuitRequested; // true if the app should run the exit sequence
- bool m_bQuitting; // true if the app is running the exit sequence
- Point m_screenSize; // game screen size
- bool m_bIsEditorRunning; // true if the game editor is running
- public:
- const Point &GetScreenSize() { return m_screenSize; }
- protected:
- std::map<std::string,std::string> m_textResource;
- std::map<std::string,unsigned int> m_hotkeys;
- public:
- GameCodeApp();
- // Game Application Data
- // You must define these in an inherited
- // class - see TeapotWarsApp for an example
- // TODO(munnellg): uncomment and implement
- virtual std::string VGetGameTitle()=0;
- // virtual TCHAR *VGetGameAppDirectory()=0;
- // virtual SDL_Surface* VGetIcon()=0;
- SDL_Window* GetWindow() { return m_Window; }
- static int MsgProc(SDL_Event &e);
- // TODO(munnellg): uncomment and implement
- // int OnDisplayChange(int colorDepth, int width, int height);
- // int OnPowerBroadcast(int event);
- int OnSysCommand(SDL_Event const &e);
- // int OnClose();
- // TODO(munnellg): uncomment and implement
- // Game Application actions
- // int OnAltEnter();
- // int OnNcCreate(LPCREATESTRUCT cs);
- bool LoadStrings(std::string language);
- std::string GetString(std::string sID);
- virtual bool InitInstance(/*HINSTANCE hInstance, LPWSTR lpCmdLine, HWND hWnd = NULL, */int screenWidth = SCREEN_WIDTH, int screenHeight = SCREEN_HEIGHT);
- // FUTURE WORK - Seems like this class could be refactored, especailly the renderer !
- enum Renderer
- {
- Renderer_Unknown,
- Renderer_OpenGL46,
- };
- std::shared_ptr<IRenderer> m_Renderer;
- static Renderer GetRendererImpl();
- // OpenGL 4.6 Specific Stuff
- // static bool CALLBACK IsD3D11DeviceAcceptable( const CD3D11EnumAdapterInfo *AdapterInfo, UINT Output, const CD3D11EnumDeviceInfo *DeviceInfo, DXGI_FORMAT BackBufferFormat, bool bWindowed, void* pUserContext );
- // static HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext );
- // static HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext );
- // static void CALLBACK OnD3D11ReleasingSwapChain( void* pUserContext );
- // static void CALLBACK OnD3D11DestroyDevice( void* pUserContext );
- static void OnOpenGLFrameRender(double fTime, float fElapsedTime);
- static void OnUpdateGame(double fTime, float fElapsedTime);
- // GameCode Specific Stuff
- BaseGameLogic *m_pGame;
- struct GameOptions m_Options;
-
- // You must define these functions to initialize your game.
- // Look for them in TeapotWars.h and TeapotWars.cpp
- virtual BaseGameLogic *VCreateGameAndView()=0;
- virtual bool VLoadGame(void);
- // HumanView* GetHumanView(); // Added post press - it was convenient to grab the HumanView attached to the game.
- // File and Resource System
- class ResCache *m_ResCache;
- // Event manager
- EventManager *m_pEventManager;
-
- public:
- // [gmunnelly] added for SDL/OpenGL compatibility. We must own the main loop
- void RunMainLoop();
- void Shutdown();
- void PumpSDLEvents();
-
- // Main loop processing
- void AbortGame() { m_bQuitting = true; }
- // TODO(munnellg): get proper exit code
- int GetExitCode() { return 0; }
- bool IsRunning() { return m_bIsRunning; }
- void SetQuitting(bool quitting) { m_bQuitting = quitting; }
- BaseGameLogic* GetGameLogic(void) const { return m_pGame; }
-
- };
- extern GameCodeApp *g_pApp;
|