diff --git a/Client/Audio/Startup.cpp b/Client/Audio/Startup.cpp index 8693f18..959ec28 100644 --- a/Client/Audio/Startup.cpp +++ b/Client/Audio/Startup.cpp @@ -19,8 +19,6 @@ namespace Audio { -HANDLE Thread; - IXAudio2 *pXAudio2 = NULL; IXAudio2MasteringVoice *MasterVoice = NULL; diff --git a/Client/CMakeLists.txt b/Client/CMakeLists.txt index a63ae51..731f56f 100644 --- a/Client/CMakeLists.txt +++ b/Client/CMakeLists.txt @@ -1,17 +1,19 @@ -cmake_minimum_required(VERSION 2.6) -project(NiotsoClient) - -if(WIN32) - set(NIOTSOCLIENT_SOURCES - Client.cpp - MessageHandler.cpp - Audio/Startup.cpp - Audio/windows/XAudio2.cpp - Graphics/Startup.cpp - Graphics/Viewport.cpp - resources/Resource.rc - System/System.cpp - ) - add_executable(TSO WIN32 ${NIOTSOCLIENT_SOURCES}) - target_link_libraries(TSO ole32 opengl32) +cmake_minimum_required(VERSION 2.6) +project(NiotsoClient) + +include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler) + +if(WIN32) + set(NIOTSOCLIENT_SOURCES + Client.cpp + MessageHandler.cpp + Audio/Startup.cpp + Audio/windows/XAudio2.cpp + Graphics/Startup.cpp + Graphics/Viewport.cpp + resources/Resource.rc + System/System.cpp + ) + add_executable(TSO WIN32 ${NIOTSOCLIENT_SOURCES}) + target_link_libraries(TSO FileHandler_shared ole32 opengl32) endif() \ No newline at end of file diff --git a/Client/Client.cpp b/Client/Client.cpp index 58e1699..b952617 100644 --- a/Client/Client.cpp +++ b/Client/Client.cpp @@ -69,7 +69,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) } CurrentScene = new LoginScreen(); - if(CurrentScene == NULL){ + if(System::SceneFailed || CurrentScene == NULL){ + if(System::SceneFailed) delete CurrentScene; Shutdown(); return ERROR_INIT | ERROR_INIT_LOGIC | ERROR_LOGIC_CREATE_SCENE; } @@ -110,8 +111,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) } ShowWindow(Window::hWnd, SW_HIDE); - Audio::Shutdown(); - Graphics::Shutdown(); + delete CurrentScene; Shutdown(); return 0; @@ -193,10 +193,12 @@ int CreateWindowInvisible(HINSTANCE hInst, unsigned Width, unsigned Height, bool void Shutdown() { + Audio::Shutdown(); + Graphics::Shutdown(); + if(Window::hWnd){ DestroyWindow(Window::hWnd); Window::hWnd = NULL; } - UnregisterClass("TSO_NIOTSO", System::hInst); } \ No newline at end of file diff --git a/Client/EngineInterface.hpp b/Client/EngineInterface.hpp index b1d155b..6ac10e7 100644 --- a/Client/EngineInterface.hpp +++ b/Client/EngineInterface.hpp @@ -23,13 +23,7 @@ #undef NULL #define NULL 0 -#include "version.h" -#include "System/System.hpp" -#include "Resources/Resource.h" - -#include "Audio/Audio.hpp" -#include "Graphics/Graphics.hpp" -#include "Scene/Scene.hpp" +#include "FileHandler.hpp" //IsometricEngine.cpp namespace Window { @@ -39,4 +33,12 @@ namespace Window { } //MessageHandler.cpp -LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); \ No newline at end of file +LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +#include "version.h" +#include "System/System.hpp" +#include "Resources/Resource.h" + +#include "Audio/Audio.hpp" +#include "Graphics/Graphics.hpp" +#include "Scene/Scene.hpp" \ No newline at end of file diff --git a/Client/Graphics/Startup.cpp b/Client/Graphics/Startup.cpp index 90cd57e..836e057 100644 --- a/Client/Graphics/Startup.cpp +++ b/Client/Graphics/Startup.cpp @@ -19,7 +19,6 @@ namespace Graphics { -HANDLE Thread; HDC hDC; HGLRC hRC; diff --git a/Client/Scene/Scene.hpp b/Client/Scene/Scene.hpp index 4dfb78f..5850eb2 100644 --- a/Client/Scene/Scene.hpp +++ b/Client/Scene/Scene.hpp @@ -15,6 +15,11 @@ along with this program. If not, see . */ +#define EXIT_SCENE() do { System::SceneFailed = true; delete this; return; } while(0) +#define SCENE_EXIT 0 +#define SCENE_NEED_REDRAW 1 +#define SCENE_NO_REDRAW -1 + class Scene { const float TickPeriod; float TimeDelta; @@ -45,15 +50,43 @@ class Scene { }; class LoginScreen : public Scene { - public: LoginScreen() : Scene(1.0f/15) {} + public: + LoginScreen() : Scene(1.0f/15){ + Image_t * Image = File::ReadImageFile("eagames.bmp"); + if(!Image){ + const char * Message; + switch(File::Error){ + case FERR_NOT_FOUND: + Message = "%s does not exist."; + break; + case FERR_OPEN: + Message = "%s could not be opened for reading."; + break; + case FERR_BLANK: + case FERR_UNRECOGNIZED: + case FERR_INVALIDDATA: + Message = "%s is corrupt or invalid."; + break; + case FERR_MEMORY: + Message = "Memory for %s could not be allocated."; + break; + default: + Message = "%s could not be read."; + } + + char Buffer[1024]; + sprintf(Buffer, Message, "eagames.bmp"); + MessageBox(Window::hWnd, Buffer, NULL, MB_OK | MB_ICONERROR); + EXIT_SCENE(); + } + } private: int Run(float){ if(System::UserInput.CloseWindow){ - System::Shutdown = true; - return 0; + return SCENE_EXIT; } - return 1; + return SCENE_NEED_REDRAW; } public: diff --git a/Client/System/System.cpp b/Client/System/System.cpp index 072ebfa..cca7fe2 100644 --- a/Client/System/System.cpp +++ b/Client/System/System.cpp @@ -18,13 +18,13 @@ #include "../EngineInterface.hpp" namespace System { - bool Shutdown = false; HINSTANCE hInst = NULL; HANDLE Process; HANDLE ProcessHeap; LARGE_INTEGER ClockFreq; float FramePeriod; UserInput_t UserInput; + bool SceneFailed = false; int Initialize(){ memset(&UserInput, 0, sizeof(UserInput)); diff --git a/Client/System/System.hpp b/Client/System/System.hpp index 51fac26..2652e83 100644 --- a/Client/System/System.hpp +++ b/Client/System/System.hpp @@ -18,13 +18,11 @@ //System/System.cpp namespace System { int Initialize(); - extern bool Shutdown; extern HINSTANCE hInst; extern HANDLE Process; extern HANDLE ProcessHeap; extern LARGE_INTEGER ClockFreq; extern float FramePeriod; - extern bool Keys[256]; struct UserInput_t { bool Keys[256]; @@ -33,6 +31,8 @@ namespace System { }; extern UserInput_t UserInput; + extern bool SceneFailed; + //Constants enum { SHUTDOWN = 0 diff --git a/Libraries/FileHandler/FileHandler.hpp b/Libraries/FileHandler/FileHandler.hpp index 40ea85d..e76147c 100644 --- a/Libraries/FileHandler/FileHandler.hpp +++ b/Libraries/FileHandler/FileHandler.hpp @@ -58,7 +58,6 @@ extern size_t FileSize; uint8_t * ReadFile(const char * Filename); Image_t * ReadImageFile(const char * Filename); -uint8_t * ReadJPG(Image_t * Image, const uint8_t * InData, size_t FileSize); } diff --git a/Libraries/FileHandler/Image.cpp b/Libraries/FileHandler/Image.cpp index 11690a3..0673793 100644 --- a/Libraries/FileHandler/Image.cpp +++ b/Libraries/FileHandler/Image.cpp @@ -34,10 +34,10 @@ enum ImageType { FIMG_COUNT }; -uint8_t * ReadJPG(Image_t * Image, const uint8_t * InData, size_t FileSize); -uint8_t * ReadBMP(Image_t * Image, const uint8_t * InData, size_t FileSize); -uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSize); -uint8_t * ReadTGA(Image_t * Image, const uint8_t * InData, size_t FileSize); +static uint8_t * ReadJPG(Image_t * Image, const uint8_t * InData, size_t FileSize); +static uint8_t * ReadBMP(Image_t * Image, const uint8_t * InData, size_t FileSize); +static uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSize); +static uint8_t * ReadTGA(Image_t * Image, const uint8_t * InData, size_t FileSize); static const uint8_t Signature[] = { 'B', //BMP @@ -87,7 +87,7 @@ Image_t * ReadImageFile(const char * Filename){ return NULL; } -uint8_t * ReadBMP(Image_t * Image, const uint8_t * InData, size_t FileSize){ +static uint8_t * ReadBMP(Image_t * Image, const uint8_t * InData, size_t FileSize){ bmpheader_t BMPHeader; if(!bmp_read_header(&BMPHeader, InData, FileSize)){ return NULL; @@ -109,7 +109,7 @@ uint8_t * ReadBMP(Image_t * Image, const uint8_t * InData, size_t FileSize){ return OutData; } -uint8_t * ReadJPG(Image_t * Image, const uint8_t * InData, size_t FileSize){ +static uint8_t * ReadJPG(Image_t * Image, const uint8_t * InData, size_t FileSize){ //Initialize jpeg_decompress_struct cinfo; jpeg_error_mgr jerr; @@ -170,7 +170,7 @@ static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t lengt pngdata->buffer += length; pngdata->size -= length; } -uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSize){ +static uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSize){ pngdata_t pngdata; png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -203,7 +203,6 @@ uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSize){ } uint8_t **Scanlines = png_get_rows(png_ptr, info_ptr); - printf("png:Now. %ux%u\n", width, height); for(unsigned i=0; iType, "FAMs") || !strcmp(ChunkInfo->Type, "TTAs") ) return iff_parse_str(ChunkInfo, Buffer); + if( !strcmp(ChunkInfo->Type, "BCON") ) + return iff_parse_bcon(ChunkInfo, Buffer); + return 0; } +int iff_parse_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned IFFSize){ + return 1; +} + +int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer){ + IFF_BCON *BCONData; + unsigned Size = ChunkInfo->Size - 76; + unsigned i; + + if(Size < 2) + return 0; + ChunkInfo->FormattedData = malloc(sizeof(IFF_BCON)); + if(ChunkInfo->FormattedData == NULL) + return 0; + + BCONData = (IFF_BCON*) ChunkInfo->FormattedData; + BCONData->ConstantCount = read_uint8le(Buffer); + BCONData->Flags = read_uint8le(Buffer + 1); + if(BCONData->ConstantCount == 0) + return 1; + if(BCONData->ConstantCount * 2 > 255*2){ + free(ChunkInfo->FormattedData); + return 0; + } + + BCONData->Constants = malloc(BCONData->ConstantCount * sizeof(uint16_t)); + if(BCONData->Constants == NULL){ + free(ChunkInfo->FormattedData); + return 0; + } + + Buffer += 2; + for(i=0; iConstantCount; i++, Buffer += 2) + BCONData->Constants[i] = read_uint16le(Buffer); + return 1; +} + int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ /* No bounds checking yet */ IFF_STR * StringData; unsigned Size = ChunkInfo->Size - 76; + if(Size < 2) return 0; ChunkInfo->FormattedData = malloc(sizeof(IFF_STR)); @@ -254,9 +295,7 @@ int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){ } return 1; } - return 0; -} -int iff_parse_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned IFFSize){ - return 1; + free(ChunkInfo->FormattedData); + return 0; } \ No newline at end of file diff --git a/Libraries/FileHandler/iff/iff.h b/Libraries/FileHandler/iff/iff.h index 67001f2..6698600 100644 --- a/Libraries/FileHandler/iff/iff.h +++ b/Libraries/FileHandler/iff/iff.h @@ -71,6 +71,15 @@ static const uint8_t Header_IFF[] = "IFF FILE 2.5:TYPE FOLLOWED BY SIZE\0 JAMIE ** IFF chunk structs */ +/* BCON chunk */ + +typedef struct IFF_BCON_struct +{ + uint8_t ConstantCount; + uint8_t Flags; + uint16_t * Constants; +} IFF_BCON; + /* STR# chunk */ enum IFFLanguage { @@ -147,8 +156,9 @@ void iff_delete(IFFFile * IFFFileInfo); ** IFF chunk functions */ -int iff_parse_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned IFFSize); int iff_parse_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer); +int iff_parse_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned IFFSize); +int iff_parse_bcon(IFFChunk * ChunkInfo, const uint8_t * Buffer); int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer); #ifdef __cplusplus diff --git a/Tools/iff2html/iff2html.c b/Tools/iff2html/iff2html.c index 05b8180..045aa08 100644 --- a/Tools/iff2html/iff2html.c +++ b/Tools/iff2html/iff2html.c @@ -285,10 +285,10 @@ int main(int argc, char *argv[]){ !strcmp(ChunkNode->Chunk.Type, "CTSS") || !strcmp(ChunkNode->Chunk.Type, "FAMs") || !strcmp(ChunkNode->Chunk.Type, "TTAs") ){ - /**** ** STR# parsing */ + fprintf(hFile, "\n"); fprintf(hFile, "
Format:"); switch(StringData->Format){ @@ -349,6 +349,26 @@ int main(int argc, char *argv[]){ fprintf(hFile, "
\n"); } + }else if(!strcmp(ChunkNode->Chunk.Type, "BCON")){ + /**** + ** BCON parsing + */ + + IFF_BCON * BCONData = (IFF_BCON*) ChunkNode->Chunk.FormattedData; + fprintf(hFile, "\n"); + fprintf(hFile, "\n", BCONData->Flags, BCONData->Flags); + fprintf(hFile, "\n", BCONData->ConstantCount); + fprintf(hFile, "
Flags:%02X (%d)
Number of Constants:%u
\n"); + if(BCONData->ConstantCount > 0){ + unsigned ConstantIndex; + + fprintf(hFile, "
\n"); + fprintf(hFile, "\n"); + fprintf(hFile, "\n"); + for(ConstantIndex=0; ConstantIndexConstantCount; ConstantIndex++) + fprintf(hFile, "\n", ConstantIndex+1, BCONData->Constants[ConstantIndex]); + fprintf(hFile, "
Constant Value
%u%u
\n"); + } } fprintf(hFile, "\n\n");