mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-03-15 14:51:21 +00:00
Added eagames.bmp reading to the LoginScreen scene.
Added BCON parsing functionality contributed by Propeng.
This commit is contained in:
parent
cb751c0bb8
commit
7d9259b63d
13 changed files with 157 additions and 54 deletions
|
@ -19,8 +19,6 @@
|
|||
|
||||
namespace Audio {
|
||||
|
||||
HANDLE Thread;
|
||||
|
||||
IXAudio2 *pXAudio2 = NULL;
|
||||
IXAudio2MasteringVoice *MasterVoice = NULL;
|
||||
|
||||
|
|
|
@ -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()
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
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"
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
namespace Graphics {
|
||||
|
||||
HANDLE Thread;
|
||||
HDC hDC;
|
||||
HGLRC hRC;
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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:
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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; i<height; i++)
|
||||
memcpy(OutData + i*width*3, Scanlines[height-i-1], width*3);
|
||||
|
||||
|
@ -215,7 +214,7 @@ uint8_t * ReadPNG(Image_t * Image, const uint8_t * InData, size_t FileSize){
|
|||
return OutData;
|
||||
}
|
||||
|
||||
uint8_t * ReadTGA(Image_t * Image, const uint8_t * InData, size_t FileSize){
|
||||
static uint8_t * ReadTGA(Image_t * Image, const uint8_t * InData, size_t FileSize){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,13 +25,54 @@ int iff_parse_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
|||
!strcmp(ChunkInfo->Type, "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; i<BCONData->ConstantCount; 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;
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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, "<table>\n");
|
||||
fprintf(hFile, "<tr><td>Format:</td><td>");
|
||||
switch(StringData->Format){
|
||||
|
@ -349,6 +349,26 @@ int main(int argc, char *argv[]){
|
|||
|
||||
fprintf(hFile, "</table>\n");
|
||||
}
|
||||
}else if(!strcmp(ChunkNode->Chunk.Type, "BCON")){
|
||||
/****
|
||||
** BCON parsing
|
||||
*/
|
||||
|
||||
IFF_BCON * BCONData = (IFF_BCON*) ChunkNode->Chunk.FormattedData;
|
||||
fprintf(hFile, "<table>\n");
|
||||
fprintf(hFile, "<tr><td>Flags:</td><td><tt>%02X</tt> (%d)</td></tr>\n", BCONData->Flags, BCONData->Flags);
|
||||
fprintf(hFile, "<tr><td>Number of Constants:</td><td>%u</td></tr>\n", BCONData->ConstantCount);
|
||||
fprintf(hFile, "</table>\n");
|
||||
if(BCONData->ConstantCount > 0){
|
||||
unsigned ConstantIndex;
|
||||
|
||||
fprintf(hFile, "<br />\n");
|
||||
fprintf(hFile, "<table class=\"center\">\n");
|
||||
fprintf(hFile, "<tr><th colspan=\"2\">Constant Value</th></tr>\n");
|
||||
for(ConstantIndex=0; ConstantIndex<BCONData->ConstantCount; ConstantIndex++)
|
||||
fprintf(hFile, "<tr><td>%u</td><td>%u</td></tr>\n", ConstantIndex+1, BCONData->Constants[ConstantIndex]);
|
||||
fprintf(hFile, "</table>\n");
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(hFile, "</div>\n\n");
|
||||
|
|
Loading…
Add table
Reference in a new issue