From 56f6487206ac4e82f66f2fb8fb9eddffe7892a3c Mon Sep 17 00:00:00 2001 From: Fatbag Date: Thu, 28 Jun 2012 07:00:45 -0500 Subject: [PATCH] * Fixed MP3 playback with libmpg123 * Finally removed the dependency on libstdc++ with TDM GCC, reducing the size of the exe from 153kB to 87kB --- CMakeLists.txt | 8 ++++---- Client/Audio/windows/xaudio2.hpp | 6 +----- Client/Client.cpp | 11 ++++++++++- Client/EngineInterface.hpp | 18 ++++++++++++------ Client/System/System.cpp | 2 -- Client/System/System.hpp | 2 -- Libraries/FileHandler/CMakeLists.txt | 3 +++ Libraries/FileHandler/File.cpp | 23 +++++++++++------------ Libraries/FileHandler/FileHandler.hpp | 17 ++++++++++++----- Libraries/FileHandler/Image.cpp | 1 - Libraries/FileHandler/far/libfar.c | 14 +------------- Libraries/libvitaboy/config.h | 1 - Libraries/libvitaboy/resource.rc | 10 +++++++++- 13 files changed, 63 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c8e35c..30ce015 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,13 +18,13 @@ endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) # Base options - set(CFLAGS "-Wall -Wextra -Wabi -pedantic -m32 -mmmx -msse -msse2 -msse3 -mfpmath=both -msahf -fvisibility=internal") - set(LDFLAGS "-m32 -fvisibility=hidden -fvisibility-inlines-hidden") + set(CFLAGS "-Wall -Wextra -Wabi -pedantic -m32 -mmmx -msse -msse2 -msse3 -mfpmath=both -msahf -malign-double -mpc32 -fvisibility=hidden") + set(LDFLAGS "-m32") set(RCFLAGS "-F pe-i386") set(ASMFLAGS "-O3 -F win32") set(CFLAGS_LANG_C "-ansi") - set(CFLAGS_LANG_CPP "-fno-exceptions -fno-rtti -fno-threadsafe-statics") + set(CFLAGS_LANG_CPP "-fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fno-threadsafe-statics") #### @@ -39,7 +39,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) endif() # Size - set(CFLAGS_SIZE "${CFLAGS} -Os -g0 -fomit-frame-pointer -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure") + set(CFLAGS_SIZE "${CFLAGS} -Os -g0 -fomit-frame-pointer -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -mstringop-strategy=rep_byte") set(LDFLAGS_SIZE "${LDFLAGS} -s -fwhole-program") # Speed diff --git a/Client/Audio/windows/xaudio2.hpp b/Client/Audio/windows/xaudio2.hpp index 83f65e9..758539e 100644 --- a/Client/Audio/windows/xaudio2.hpp +++ b/Client/Audio/windows/xaudio2.hpp @@ -5,11 +5,7 @@ ruby-specific header to provide mingw-friendly xaudio2 interfaces */ -#include -#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/Client.cpp b/Client/Client.cpp index dfb6c64..5851845 100644 --- a/Client/Client.cpp +++ b/Client/Client.cpp @@ -23,6 +23,13 @@ static void Shutdown(); Scene * CurrentScene; +#ifdef _WIN32 + +/* TDM GCC bonus feature; saves 66 kB in the binary :) */ +/* */ void* operator new(unsigned size){return malloc(size);} +/* */ void operator delete(void *ptr){free(ptr);} +/* */ extern "C" void __cxa_pure_virtual(){} + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { int result; @@ -121,4 +128,6 @@ static void Shutdown() Graphics::Shutdown(); System::Shutdown(); Window::Shutdown(); -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/Client/EngineInterface.hpp b/Client/EngineInterface.hpp index a17f080..cc730fc 100644 --- a/Client/EngineInterface.hpp +++ b/Client/EngineInterface.hpp @@ -19,18 +19,24 @@ */ //Compiler/platform constants -#define WINVER 0x0502 -#define _WIN32_WINNT 0x0502 -#define _CRT_SECURE_NO_WARNINGS +#ifdef _WIN32 + #define WINVER 0x0502 + #define _WIN32_WINNT 0x0502 + #define NTDDI_VERSION 0x05010300 + #define _CRT_SECURE_NO_WARNINGS +#endif //Standard libraries #include #include #include #include -#include -#undef NULL -#define NULL 0 +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #include + #undef NULL + #define NULL 0 +#endif //Codebase libraries #include "FileHandler.hpp" diff --git a/Client/System/System.cpp b/Client/System/System.cpp index f677a12..1ebf8c3 100644 --- a/Client/System/System.cpp +++ b/Client/System/System.cpp @@ -23,8 +23,6 @@ namespace System { HINSTANCE hInst = NULL; -HANDLE Process; -HANDLE ProcessHeap; LARGE_INTEGER ClockFreq; volatile float FramePeriod; UserInput_t UserInput = UserInput_t(); diff --git a/Client/System/System.hpp b/Client/System/System.hpp index 82dcd6c..9306529 100644 --- a/Client/System/System.hpp +++ b/Client/System/System.hpp @@ -23,8 +23,6 @@ namespace System { void Shutdown(); extern HINSTANCE hInst; - extern HANDLE Process; - extern HANDLE ProcessHeap; extern LARGE_INTEGER ClockFreq; extern volatile float FramePeriod; diff --git a/Libraries/FileHandler/CMakeLists.txt b/Libraries/FileHandler/CMakeLists.txt index 011a068..7ba2e2a 100644 --- a/Libraries/FileHandler/CMakeLists.txt +++ b/Libraries/FileHandler/CMakeLists.txt @@ -25,6 +25,9 @@ set(FILEHANDLER_SOURCES wav/read_wav.c xa/read_xa.c ) +if(WIN32) + set(FILEHANDLER_SOURCES ${FILEHANDLER_SOURCES} resource.rc) +endif() include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler) diff --git a/Libraries/FileHandler/File.cpp b/Libraries/FileHandler/File.cpp index 1abad14..80f0981 100644 --- a/Libraries/FileHandler/File.cpp +++ b/Libraries/FileHandler/File.cpp @@ -21,38 +21,37 @@ namespace File { int Error = 0; -unsigned FileSize = 0; +size_t FileSize = 0; uint8_t * ReadFile(const char * Filename){ - HANDLE hFile = CreateFile(Filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); - if(hFile == INVALID_HANDLE_VALUE){ - File::Error = (GetLastError() == ERROR_FILE_NOT_FOUND) ? FERR_NOT_FOUND : FERR_OPEN; + FILE * hFile = fopen(Filename, "rb"); + if(hFile == NULL){ + File::Error = FERR_OPEN; return NULL; } - FileSize = GetFileSize(hFile, NULL); + FileSize = File::GetFileSize(hFile); if(FileSize == 0){ - CloseHandle(hFile); + fclose(hFile); File::Error = FERR_BLANK; return NULL; } uint8_t * InData = (uint8_t*) malloc(FileSize); if(InData == NULL){ - CloseHandle(hFile); + fclose(hFile); File::Error = FERR_MEMORY; return NULL; } - DWORD bytestransferred; - BOOL result = ::ReadFile(hFile, InData, FileSize, &bytestransferred, NULL); - CloseHandle(hFile); - - if(!result || bytestransferred != FileSize){ + size_t bytestransferred = fread(InData, 1, FileSize, hFile); + if(bytestransferred != FileSize){ free(InData); + fclose(hFile); File::Error = FERR_READ; return NULL; } + return InData; } diff --git a/Libraries/FileHandler/FileHandler.hpp b/Libraries/FileHandler/FileHandler.hpp index 2f7caf2..3c8ac41 100644 --- a/Libraries/FileHandler/FileHandler.hpp +++ b/Libraries/FileHandler/FileHandler.hpp @@ -24,12 +24,12 @@ #include #include #include -#include -#ifndef NOWINDOWS - #include -#endif -#define fhexport __declspec(dllexport) +#ifdef WIN32 + #define fhexport __declspec(dllexport) +#else + #define fhexport __attribute__((visibility ("default"))) +#endif struct Asset_t { uint32_t Group; @@ -68,6 +68,13 @@ struct Sound_t { namespace File { +inline unsigned GetFileSize(FILE * hFile){ + fseek(hFile, 0, SEEK_END); + unsigned FileSize = ftell(hFile); + fseek(hFile, 0, SEEK_SET); + return FileSize; +} + fhexport extern int Error; fhexport extern size_t FileSize; diff --git a/Libraries/FileHandler/Image.cpp b/Libraries/FileHandler/Image.cpp index c8198b7..accbf56 100644 --- a/Libraries/FileHandler/Image.cpp +++ b/Libraries/FileHandler/Image.cpp @@ -16,7 +16,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define NOWINDOWS #include "FileHandler.hpp" #include //Used by libpng #include "bmp/read_bmp.h" diff --git a/Libraries/FileHandler/far/libfar.c b/Libraries/FileHandler/far/libfar.c index b29bf67..f0eb198 100644 --- a/Libraries/FileHandler/far/libfar.c +++ b/Libraries/FileHandler/far/libfar.c @@ -18,21 +18,9 @@ #include "config.h" -#include #include #include - -#ifdef HAVE_STDINT_H - #include -#else - typedef signed char int8_t; - typedef unsigned char uint8_t; - typedef signed short int16_t; - typedef unsigned short uint16_t; - typedef signed long int32_t; - typedef unsigned long uint32_t; - typedef unsigned int uintptr_t; -#endif +#include #include "libfar.h" diff --git a/Libraries/libvitaboy/config.h b/Libraries/libvitaboy/config.h index 50e7111..1c7cbd9 100644 --- a/Libraries/libvitaboy/config.h +++ b/Libraries/libvitaboy/config.h @@ -8,5 +8,4 @@ #define VERSION_B 0 #define VERSION_C 1 #define VERSION_STR "1.0.1" -/* You should fill the revision in if you're compiling from the trunk */ #define REVISION 0 \ No newline at end of file diff --git a/Libraries/libvitaboy/resource.rc b/Libraries/libvitaboy/resource.rc index 7a3c2a2..ef9e827 100644 --- a/Libraries/libvitaboy/resource.rc +++ b/Libraries/libvitaboy/resource.rc @@ -1,4 +1,12 @@ -#include "config.h" +/* Name of package */ +#define PACKAGE "libvitaboy" + +/* Version number of package */ +#define VERSION_A 1 +#define VERSION_B 0 +#define VERSION_C 1 +#define VERSION_STR "1.0.1" +#define REVISION 0 1 VERSIONINFO FILEVERSION VERSION_A,VERSION_B,VERSION_C,REVISION