From 2e7f3b24cac8fa067bae2e5384c4c362ba0d5ad9 Mon Sep 17 00:00:00 2001 From: Fatbag Date: Wed, 21 Mar 2012 20:00:22 -0500 Subject: [PATCH] New Scene class definition. Also fixed a compile error for some users involving the definition of IID_IXAudio2 --- CMakeLists.txt | 6 ++-- Client/Audio/windows/xaudio2.cpp | 5 +++ Client/Audio/windows/xaudio2.hpp | 2 +- Client/CMakeLists.txt | 1 + Client/Client.cpp | 5 +++ Client/EngineInterface.hpp | 4 ++- Client/Scene/Scene.hpp | 58 +++++++++++++++++++++++++++++++ Client/System/System.hpp | 4 +++ Libraries/libvitaboy/Renderer.cpp | 10 +++--- 9 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 Client/Audio/windows/xaudio2.cpp create mode 100644 Client/Scene/Scene.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9065322..d62fca0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) set(ASMFLAGS "-O3 -F win32") set(CFLAGS_LANG_C "-ansi") - set(CFLAGS_LANG_CPP "-fno-exceptions -fno-rtti") + set(CFLAGS_LANG_CPP "-fno-exceptions -fno-rtti -fno-threadsafe-statics") #### @@ -40,10 +40,10 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) # Size set(CFLAGS_SIZE "${CFLAGS} -Os -g0 -fomit-frame-pointer -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure") - set(LDFLAGS_SIZE "${LDFLAGS} -s") + set(LDFLAGS_SIZE "${LDFLAGS} -s -fwhole-program") # Speed - set(CFLAGS_SPEED "${CFLAGS} -O3 -g0 -fomit-frame-pointer -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -fgcse-sm -fgcse-las -fsched-spec-load -fsched-spec-load-dangerous -fsched-stalled-insns=0 -fsched-stalled-insns-dep -fsched2-use-superblocks -fipa-pta -fipa-matrix-reorg -ftree-loop-linear -floop-interchange -floop-strip-mine -floop-block -fgraphite-identity -floop-parallelize-all -ftree-loop-distribution -ftree-loop-im -ftree-loop-ivcanon -fivopts -fvect-cost-model -fvariable-expansion-in-unroller -fbranch-target-load-optimize -maccumulate-outgoing-args -fwhole-program -flto") + set(CFLAGS_SPEED "${CFLAGS} -O3 -g0 -fomit-frame-pointer -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -fgcse-sm -fgcse-las -fsched-spec-load -fsched-spec-load-dangerous -fsched-stalled-insns=0 -fsched-stalled-insns-dep -fsched2-use-superblocks -fipa-pta -fipa-matrix-reorg -ftree-loop-linear -floop-interchange -floop-strip-mine -floop-block -fgraphite-identity -floop-parallelize-all -ftree-loop-distribution -ftree-loop-im -ftree-loop-ivcanon -fivopts -fvect-cost-model -fvariable-expansion-in-unroller -fbranch-target-load-optimize -maccumulate-outgoing-args -flto") set(LDFLAGS_SPEED "${LDFLAGS} -s -fwhole-program -flto") else() # Debug diff --git a/Client/Audio/windows/xaudio2.cpp b/Client/Audio/windows/xaudio2.cpp new file mode 100644 index 0000000..c92decc --- /dev/null +++ b/Client/Audio/windows/xaudio2.cpp @@ -0,0 +1,5 @@ +#include + +DEFINE_GUID(CLSID_XAudio2, 0xe21a7345, 0xeb21, 0x468e, 0xbe, 0x50, 0x80, 0x4d, 0xb9, 0x7c, 0xf7, 0x08); +DEFINE_GUID(CLSID_XAudio2_Debug, 0xf7a76c21, 0x53d4, 0x46bb, 0xac, 0x53, 0x8b, 0x45, 0x9c, 0xae, 0x46, 0xbd); +DEFINE_GUID(IID_IXAudio2, 0x8bcf1f58, 0x9fe7, 0x4583, 0x8a, 0xc6, 0xe2, 0xad, 0xc4, 0x65, 0xc8, 0xbb); \ No newline at end of file diff --git a/Client/Audio/windows/xaudio2.hpp b/Client/Audio/windows/xaudio2.hpp index 2d48e64..8554a17 100644 --- a/Client/Audio/windows/xaudio2.hpp +++ b/Client/Audio/windows/xaudio2.hpp @@ -9,7 +9,7 @@ #undef NULL #define NULL 0 -#include +#include #include DEFINE_GUID(CLSID_XAudio2, 0xe21a7345, 0xeb21, 0x468e, 0xbe, 0x50, 0x80, 0x4d, 0xb9, 0x7c, 0xf7, 0x08); diff --git a/Client/CMakeLists.txt b/Client/CMakeLists.txt index ebd789e..a63ae51 100644 --- a/Client/CMakeLists.txt +++ b/Client/CMakeLists.txt @@ -6,6 +6,7 @@ if(WIN32) Client.cpp MessageHandler.cpp Audio/Startup.cpp + Audio/windows/XAudio2.cpp Graphics/Startup.cpp Graphics/Viewport.cpp resources/Resource.rc diff --git a/Client/Client.cpp b/Client/Client.cpp index 645304c..1e034d6 100644 --- a/Client/Client.cpp +++ b/Client/Client.cpp @@ -26,6 +26,8 @@ namespace Window { int CreateWindowInvisible(HINSTANCE hInst, unsigned Width, unsigned Height, bool Fullscreen); void Shutdown(); +Scene * CurrentScene; + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { int result; @@ -75,6 +77,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) } } + CurrentScene = new LoginScreen(); + CurrentScene->Render(); + MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { diff --git a/Client/EngineInterface.hpp b/Client/EngineInterface.hpp index 8e1c743..c177016 100644 --- a/Client/EngineInterface.hpp +++ b/Client/EngineInterface.hpp @@ -27,8 +27,10 @@ #include "version.h" #include "System/System.hpp" #include "Resources/Resource.h" -#include "Graphics/Graphics.hpp" + #include "Audio/Audio.hpp" +#include "Graphics/Graphics.hpp" +#include "Scene/Scene.hpp" //IsometricEngine.cpp namespace Window { diff --git a/Client/Scene/Scene.hpp b/Client/Scene/Scene.hpp new file mode 100644 index 0000000..4f44e42 --- /dev/null +++ b/Client/Scene/Scene.hpp @@ -0,0 +1,58 @@ +/* + Niotso - Copyright (C) 2012 Fatbag + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + 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 the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +class Scene { + const float TickPeriod; + float TimeDelta; + virtual int Run(float TimeDelta) = 0; + + protected: + Scene(float c) : TickPeriod(c), TimeDelta(0) {} + + public: + int RunFor(float TimeDelta) { + if(TickPeriod == 0){ + return Run(TimeDelta); + } + + bool Redraw = false; + this->TimeDelta += TimeDelta; + while(this->TimeDelta >= 0){ + int result = Run(TickPeriod); + if(result == System::SHUTDOWN) + return System::SHUTDOWN; + if(result > 0) Redraw = true; + this->TimeDelta -= TickPeriod; + } + return (Redraw) ? 1 : -1; + } + + virtual void Render() = 0; +}; + +class LoginScreen : public Scene { + public: LoginScreen() : Scene(1.0f/15) {} + + private: + int Run(float){ + return 0; + } + + public: + void Render(){ + } +}; \ No newline at end of file diff --git a/Client/System/System.hpp b/Client/System/System.hpp index f03761b..ae3cdf4 100644 --- a/Client/System/System.hpp +++ b/Client/System/System.hpp @@ -26,6 +26,10 @@ namespace System { //Event objects extern HANDLE Shutdown; extern HANDLE Initialized[2], Terminated[2]; + + enum { + SHUTDOWN + }; } enum { diff --git a/Libraries/libvitaboy/Renderer.cpp b/Libraries/libvitaboy/Renderer.cpp index ef401ee..fd13b63 100644 --- a/Libraries/libvitaboy/Renderer.cpp +++ b/Libraries/libvitaboy/Renderer.cpp @@ -445,7 +445,6 @@ void KillGLWindow() hInstance = NULL; } -typedef bool (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int); BOOL CreateGLWindow(const char * title, int width, int height, int bits, bool fullscreenflag) { fullscreen = fullscreenflag; @@ -531,7 +530,7 @@ BOOL CreateGLWindow(const char * title, int width, int height, int bits, bool fu return false; } - unsigned PixelFormat = ChoosePixelFormat(hDC, &pfd); + int PixelFormat = ChoosePixelFormat(hDC, &pfd); if(!PixelFormat){ KillGLWindow(); MessageBox(NULL, "Can't find a suitable PixelFormat.", NULL, MB_OK | MB_ICONERROR); @@ -568,9 +567,10 @@ BOOL CreateGLWindow(const char * title, int width, int height, int bits, bool fu return false; } - PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0; - wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT"); + BOOL (WINAPI *wglSwapIntervalEXT)(int) = (BOOL (WINAPI *)(int)) wglGetProcAddress("wglSwapIntervalEXT"); if(wglSwapIntervalEXT) wglSwapIntervalEXT(1); + int (WINAPI *wglGetSwapIntervalEXT)(void) = (int (WINAPI *)(void)) wglGetProcAddress("wglGetSwapIntervalEXT"); + if(wglGetSwapIntervalEXT) wglGetSwapIntervalEXT(); //Seems necessary on some cards QueryPerformanceFrequency(&ClockFreq); QueryPerformanceCounter(&PreviousTime); @@ -587,7 +587,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) }else if(wParam == VK_F11 && !keys[VK_F11]){ KillGLWindow(); fullscreen = !fullscreen; - if(!CreateGLWindow("libvitaboy - Renderer",640,480,16,fullscreen)){ + if(!CreateGLWindow("libvitaboy - Renderer",640,480,24,fullscreen)){ PostQuitMessage(0); } }