mirror of
https://github.com/1dot13/source.git
synced 2026-08-12 14:10:23 +02:00
Rename 'Standard Gaming Platform' to 'sgp' (#246)
* rename 'Standard Gaming Platform' to 'sgp' * Adapt CMakeLists.txt files to renamed SGP directory * Lowercase it
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
#include "types.h"
|
||||
#include "Button System.h"
|
||||
#include "Button Sound Control.h"
|
||||
#include "Sound Control.h"
|
||||
#include "jascreens.h"
|
||||
|
||||
void SpecifyButtonSoundScheme( INT32 iButtonID, INT8 bSoundScheme )
|
||||
{
|
||||
ButtonList[ iButtonID ]->ubSoundSchemeID = (UINT8)bSoundScheme;
|
||||
if( bSoundScheme == BUTTON_SOUND_SCHEME_GENERIC )
|
||||
{
|
||||
switch( guiCurrentScreen )
|
||||
{
|
||||
case MAINMENU_SCREEN:
|
||||
case OPTIONS_SCREEN:
|
||||
case LOADSAVE_SCREEN:
|
||||
case SAVE_LOAD_SCREEN:
|
||||
case INIT_SCREEN:
|
||||
ButtonList[ iButtonID ]->ubSoundSchemeID = BUTTON_SOUND_SCHEME_BIGSWITCH3;
|
||||
break;
|
||||
|
||||
case LAPTOP_SCREEN:
|
||||
ButtonList[ iButtonID ]->ubSoundSchemeID = BUTTON_SOUND_SCHEME_COMPUTERBEEP2;
|
||||
break;
|
||||
|
||||
case AUTORESOLVE_SCREEN:
|
||||
case MAP_SCREEN:
|
||||
case GAME_SCREEN:
|
||||
case SHOPKEEPER_SCREEN:
|
||||
ButtonList[ iButtonID ]->ubSoundSchemeID = BUTTON_SOUND_SCHEME_SMALLSWITCH2;
|
||||
break;
|
||||
|
||||
case GAME_INIT_OPTIONS_SCREEN:
|
||||
ButtonList[ iButtonID ]->ubSoundSchemeID = BUTTON_SOUND_SCHEME_VERYSMALLSWITCH2;
|
||||
break;
|
||||
|
||||
//Anything not handled gets NO sound.
|
||||
//SHOPKEEPER_SCREEN,
|
||||
//GAME_SCREEN,
|
||||
//MSG_BOX_SCREEN,
|
||||
|
||||
//ERROR_SCREEN,
|
||||
//ANIEDIT_SCREEN,
|
||||
//PALEDIT_SCREEN,
|
||||
//DEBUG_SCREEN,
|
||||
//SEX_SCREEN,
|
||||
}
|
||||
if( bSoundScheme == BUTTON_SOUND_SCHEME_GENERIC )
|
||||
bSoundScheme = BUTTON_SOUND_SCHEME_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayButtonSound( INT32 iButtonID, INT32 iSoundType )
|
||||
{
|
||||
if ( ButtonList[ iButtonID ] == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch( ButtonList[ iButtonID ]->ubSoundSchemeID )
|
||||
{
|
||||
case BUTTON_SOUND_SCHEME_NONE:
|
||||
case BUTTON_SOUND_SCHEME_GENERIC:
|
||||
break;
|
||||
|
||||
|
||||
case BUTTON_SOUND_SCHEME_VERYSMALLSWITCH1:
|
||||
switch( iSoundType )
|
||||
{
|
||||
case BUTTON_SOUND_CLICKED_ON:
|
||||
PlayJA2Sample( VSM_SWITCH1_IN, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_CLICKED_OFF:
|
||||
PlayJA2Sample( VSM_SWITCH1_OUT, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_DISABLED_CLICK:
|
||||
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BUTTON_SOUND_SCHEME_VERYSMALLSWITCH2:
|
||||
switch( iSoundType )
|
||||
{
|
||||
case BUTTON_SOUND_CLICKED_ON:
|
||||
PlayJA2Sample( VSM_SWITCH2_IN, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_CLICKED_OFF:
|
||||
PlayJA2Sample( VSM_SWITCH2_OUT, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_DISABLED_CLICK:
|
||||
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BUTTON_SOUND_SCHEME_SMALLSWITCH1:
|
||||
switch( iSoundType )
|
||||
{
|
||||
case BUTTON_SOUND_CLICKED_ON:
|
||||
PlayJA2Sample( SM_SWITCH1_IN, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_CLICKED_OFF:
|
||||
PlayJA2Sample( SM_SWITCH1_OUT, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_DISABLED_CLICK:
|
||||
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BUTTON_SOUND_SCHEME_SMALLSWITCH2:
|
||||
switch( iSoundType )
|
||||
{
|
||||
case BUTTON_SOUND_CLICKED_ON:
|
||||
PlayJA2Sample( SM_SWITCH2_IN, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_CLICKED_OFF:
|
||||
PlayJA2Sample( SM_SWITCH2_OUT, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_DISABLED_CLICK:
|
||||
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BUTTON_SOUND_SCHEME_SMALLSWITCH3:
|
||||
switch( iSoundType )
|
||||
{
|
||||
case BUTTON_SOUND_CLICKED_ON:
|
||||
PlayJA2Sample( SM_SWITCH3_IN, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_CLICKED_OFF:
|
||||
PlayJA2Sample( SM_SWITCH3_OUT, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_DISABLED_CLICK:
|
||||
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BUTTON_SOUND_SCHEME_BIGSWITCH3:
|
||||
switch( iSoundType )
|
||||
{
|
||||
case BUTTON_SOUND_CLICKED_ON:
|
||||
PlayJA2Sample( BIG_SWITCH3_IN, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_CLICKED_OFF:
|
||||
PlayJA2Sample( BIG_SWITCH3_OUT, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_DISABLED_CLICK:
|
||||
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BUTTON_SOUND_SCHEME_COMPUTERBEEP2:
|
||||
switch( iSoundType )
|
||||
{
|
||||
case BUTTON_SOUND_CLICKED_ON:
|
||||
PlayJA2Sample( COMPUTER_BEEP2_IN, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_CLICKED_OFF:
|
||||
PlayJA2Sample( COMPUTER_BEEP2_OUT, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_DISABLED_CLICK:
|
||||
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BUTTON_SOUND_SCHEME_COMPUTERSWITCH1:
|
||||
switch( iSoundType )
|
||||
{
|
||||
case BUTTON_SOUND_CLICKED_ON:
|
||||
PlayJA2Sample( COMPUTER_SWITCH1_IN, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_CLICKED_OFF:
|
||||
PlayJA2Sample( COMPUTER_SWITCH1_OUT, RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
case BUTTON_SOUND_DISABLED_CLICK:
|
||||
PlayJA2SampleFromFile( "Sounds\\Disabled Button.wav", RATE_11025, 15, 1, MIDDLEPAN );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef __BUTTON_SOUND_CONTROL_H
|
||||
#define __BUTTON_SOUND_CONTROL_H
|
||||
|
||||
|
||||
//These are gener
|
||||
enum
|
||||
{
|
||||
BUTTON_SOUND_SCHEME_NONE,
|
||||
BUTTON_SOUND_SCHEME_GENERIC,
|
||||
BUTTON_SOUND_SCHEME_VERYSMALLSWITCH1,
|
||||
BUTTON_SOUND_SCHEME_VERYSMALLSWITCH2,
|
||||
BUTTON_SOUND_SCHEME_SMALLSWITCH1,
|
||||
BUTTON_SOUND_SCHEME_SMALLSWITCH2,
|
||||
BUTTON_SOUND_SCHEME_SMALLSWITCH3,
|
||||
BUTTON_SOUND_SCHEME_BIGSWITCH3,
|
||||
BUTTON_SOUND_SCHEME_COMPUTERBEEP2,
|
||||
BUTTON_SOUND_SCHEME_COMPUTERSWITCH1,
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,360 @@
|
||||
//*****************************************************************************************************
|
||||
// Button System.h
|
||||
//
|
||||
// by Kris Morness (originally created by Bret Rowden)
|
||||
//*****************************************************************************************************
|
||||
|
||||
#ifndef __BUTTON_SYSTEM_H
|
||||
#define __BUTTON_SYSTEM_H
|
||||
|
||||
#include "vobject.h"
|
||||
#include "mousesystem.h"
|
||||
#include "soundman.h"
|
||||
#include "Button Sound Control.h"
|
||||
|
||||
|
||||
// Moved here from Button System.c by DB 99/01/07
|
||||
// Names of the default generic button image files.
|
||||
#define DEFAULT_GENERIC_BUTTON_OFF "GENBUTN.STI"
|
||||
#define DEFAULT_GENERIC_BUTTON_ON "GENBUTN2.STI"
|
||||
#define DEFAULT_GENERIC_BUTTON_OFF_HI "GENBUTN3.STI"
|
||||
#define DEFAULT_GENERIC_BUTTON_ON_HI "GENBUTN4.STI"
|
||||
|
||||
#define BUTTON_TEXT_LEFT -1
|
||||
#define BUTTON_TEXT_CENTER 0
|
||||
#define BUTTON_TEXT_RIGHT 1
|
||||
|
||||
#define TEXT_LJUSTIFIED BUTTON_TEXT_LEFT
|
||||
#define TEXT_CJUSTIFIED BUTTON_TEXT_CENTER
|
||||
#define TEXT_RJUSTIFIED BUTTON_TEXT_RIGHT
|
||||
|
||||
|
||||
// Some GUI_BUTTON system defines
|
||||
#define BUTTON_USE_DEFAULT -1
|
||||
#define BUTTON_NO_FILENAME NULL
|
||||
#define BUTTON_NO_CALLBACK NULL
|
||||
#define BUTTON_NO_IMAGE -1
|
||||
#define BUTTON_NO_SLOT -1
|
||||
|
||||
#define BUTTON_INIT 1
|
||||
#define BUTTON_WAS_CLICKED 2
|
||||
|
||||
//affects how the button is rendered.
|
||||
#define BUTTON_TYPES ( BUTTON_QUICK | BUTTON_GENERIC | BUTTON_HOT_SPOT | BUTTON_CHECKBOX )
|
||||
//affects how the button is processed
|
||||
#define BUTTON_TYPE_MASK (BUTTON_NO_TOGGLE| BUTTON_ALLOW_DISABLED_CALLBACK | BUTTON_CHECKBOX | BUTTON_IGNORE_CLICKS )
|
||||
|
||||
//button flags
|
||||
#define BUTTON_TOGGLE 0x00000000
|
||||
#define BUTTON_QUICK 0x00000000
|
||||
#define BUTTON_ENABLED 0x00000001
|
||||
#define BUTTON_CLICKED_ON 0x00000002
|
||||
#define BUTTON_NO_TOGGLE 0x00000004
|
||||
#define BUTTON_CLICK_CALLBACK 0x00000008
|
||||
#define BUTTON_MOVE_CALLBACK 0x00000010
|
||||
#define BUTTON_GENERIC 0x00000020
|
||||
#define BUTTON_HOT_SPOT 0x00000040
|
||||
#define BUTTON_SELFDELETE_IMAGE 0x00000080
|
||||
#define BUTTON_DELETION_PENDING 0x00000100
|
||||
#define BUTTON_ALLOW_DISABLED_CALLBACK 0x00000200
|
||||
#define BUTTON_DIRTY 0x00000400
|
||||
#define BUTTON_SAVEBACKGROUND 0x00000800
|
||||
#define BUTTON_CHECKBOX 0x00001000
|
||||
#define BUTTON_NEWTOGGLE 0x00002000
|
||||
#define BUTTON_FORCE_UNDIRTY 0x00004000 // no matter what happens this buttons does NOT get marked dirty
|
||||
#define BUTTON_IGNORE_CLICKS 0x00008000 // Ignore any clicks on this button
|
||||
#define BUTTON_16BPPCOLOURTEXT 0x00010000 // Use 16 bit colours for the text of this button
|
||||
#define BUTTON_DISABLED_CALLBACK 0x80000000
|
||||
|
||||
#define BUTTON_SOUND_NONE 0x00
|
||||
#define BUTTON_SOUND_CLICKED_ON 0x01
|
||||
#define BUTTON_SOUND_CLICKED_OFF 0x02
|
||||
#define BUTTON_SOUND_MOVED_ONTO 0x04
|
||||
#define BUTTON_SOUND_MOVED_OFF_OF 0x08
|
||||
#define BUTTON_SOUND_DISABLED_CLICK 0x10
|
||||
#define BUTTON_SOUND_DISABLED_MOVED_ONTO 0x20
|
||||
#define BUTTON_SOUND_DISABLED_MOVED_OFF_OF 0x40
|
||||
#define BUTTON_SOUND_ALREADY_PLAYED 0X80
|
||||
|
||||
#define BUTTON_SOUND_ALL_EVENTS 0xff
|
||||
|
||||
|
||||
// Internal use!
|
||||
#define GUI_SND_CLK_ON BUTTON_SOUND_CLICKED_ON
|
||||
#define GUI_SND_CLK_OFF BUTTON_SOUND_CLICKED_OFF
|
||||
#define GUI_SND_MOV_ON BUTTON_SOUND_MOVED_ONTO
|
||||
#define GUI_SND_MOV_OFF BUTTON_SOUND_MOVED_OFF_OF
|
||||
#define GUI_SND_DCLK BUTTON_SOUND_DISABLED_CLICK
|
||||
#define GUI_SND_DMOV BUTTON_SOUND_DISABLED_MOVED_ONTO
|
||||
|
||||
extern UINT32 ButtonDestBuffer;
|
||||
|
||||
// GUI_BUTTON callback function type
|
||||
typedef void (*GUI_CALLBACK)(struct _GUI_BUTTON *,INT32);
|
||||
|
||||
// GUI_BUTTON structure definitions.
|
||||
typedef struct _GUI_BUTTON {
|
||||
INT32 IDNum; // ID Number, contains it's own button number
|
||||
UINT32 ImageNum; // Image number to use (see DOCs for details)
|
||||
MOUSE_REGION Area; // Mouse System's mouse region to use for this button
|
||||
GUI_CALLBACK ClickCallback; // Button Callback when button is clicked
|
||||
GUI_CALLBACK MoveCallback; // Button Callback when mouse moved on this region
|
||||
INT16 Cursor; // Cursor to use for this button
|
||||
UINT32 uiFlags; // Button state flags etc.( 32-bit )
|
||||
UINT32 uiOldFlags; // Old flags from previous render loop
|
||||
INT16 XLoc; // Coordinates where button is on the screen
|
||||
INT16 YLoc;
|
||||
INT32 UserData[4]; // Place holder for user data etc.
|
||||
INT16 Group; // Group this button belongs to (see DOCs)
|
||||
INT8 bDefaultStatus;
|
||||
//Button disabled style
|
||||
INT8 bDisabledStyle;
|
||||
//For buttons with text
|
||||
CHAR16 *string; //the string
|
||||
UINT16 usFont; //font for text
|
||||
BOOLEAN fMultiColor; //font is a multi-color font
|
||||
INT16 sForeColor; //text colors if there is text
|
||||
INT16 sShadowColor;
|
||||
INT16 sForeColorDown; //text colors when button is down (optional)
|
||||
INT16 sShadowColorDown;
|
||||
INT16 sForeColorHilited; //text colors when button is down (optional)
|
||||
INT16 sShadowColorHilited;
|
||||
INT8 bJustification; // BUTTON_TEXT_LEFT, BUTTON_TEXT_CENTER, BUTTON_TEXT_RIGHT
|
||||
INT8 bTextXOffset;
|
||||
INT8 bTextYOffset;
|
||||
INT8 bTextXSubOffSet;
|
||||
INT8 bTextYSubOffSet;
|
||||
BOOLEAN fShiftText;
|
||||
INT16 sWrappedWidth;
|
||||
//For buttons with icons (don't confuse this with quickbuttons which have up to 5 states )
|
||||
INT32 iIconID;
|
||||
INT16 usIconIndex;
|
||||
INT8 bIconXOffset; //-1 means horizontally centered
|
||||
INT8 bIconYOffset; //-1 means vertically centered
|
||||
BOOLEAN fShiftImage; //if true, icon is shifted +1,+1 when button state is down.
|
||||
|
||||
UINT8 ubToggleButtonOldState; // Varibles for new toggle buttons that work
|
||||
UINT8 ubToggleButtonActivated;
|
||||
|
||||
INT32 BackRect; // Handle to a Background Rectangle
|
||||
UINT8 ubSoundSchemeID;
|
||||
} GUI_BUTTON;
|
||||
|
||||
|
||||
#define MAX_BUTTONS 400
|
||||
|
||||
//extern GUI_BUTTON *ButtonList[MAX_BUTTONS]; // Button System's Main Button List
|
||||
extern std::vector<GUI_BUTTON *> ButtonList;
|
||||
|
||||
#define GetButtonPtr(x) (((x>=0) && (x<MAX_BUTTONS))? ButtonList[x] : NULL)
|
||||
|
||||
// Struct definition for the QuickButton pictures.
|
||||
typedef struct {
|
||||
HVOBJECT vobj; // The Image itself
|
||||
INT32 Grayed; // Index to use for a "Grayed-out" button
|
||||
INT32 OffNormal; // Index to use when button is OFF
|
||||
INT32 OffHilite; // Index to use when button is OFF w/ hilite on it
|
||||
INT32 OnNormal; // Index to use when button is ON
|
||||
INT32 OnHilite; // Index to use when button is ON w/ hilite on it
|
||||
UINT32 MaxWidth; // Width of largest image in use
|
||||
UINT32 MaxHeight; // Height of largest image in use
|
||||
UINT32 fFlags; // Special image flags
|
||||
} BUTTON_PICS;
|
||||
|
||||
#define MAX_BUTTON_PICS 256
|
||||
|
||||
//extern BUTTON_PICS ButtonPictures[MAX_BUTTON_PICS];
|
||||
extern std::vector<BUTTON_PICS> ButtonPictures;
|
||||
|
||||
|
||||
// Function protos for button system
|
||||
BOOLEAN InitializeButtonImageManager(INT32 DefaultBuffer, INT32 DefaultPitch, INT32 DefaultBPP);
|
||||
void ShutdownButtonImageManager(void);
|
||||
BOOLEAN InitButtonSystem(void);
|
||||
void ShutdownButtonSystem(void);
|
||||
|
||||
INT16 FindFreeIconSlot(void);
|
||||
INT32 FindFreeButtonSlot(void);
|
||||
INT16 FindFreeGenericSlot(void);
|
||||
INT16 FindFreeIconSlot(void);
|
||||
INT32 GetNextButtonNumber(void);
|
||||
|
||||
// Now used by Wizardry -- DB
|
||||
void SetButtonFastHelpText(INT32 iButton, STR16 Text);
|
||||
|
||||
#ifdef _JA2_RENDER_DIRTY
|
||||
void SetBtnHelpEndCallback( INT32 iButton, MOUSE_HELPTEXT_DONE_CALLBACK CallbackFxn );
|
||||
//void DisplayFastHelp(GUI_BUTTON *b);
|
||||
void RenderButtonsFastHelp(void);
|
||||
|
||||
#define RenderButtonsFastHelp() RenderFastHelp()
|
||||
|
||||
BOOLEAN SetButtonSavedRect( INT32 iButton );
|
||||
void FreeButtonSavedRect( INT32 iButton );
|
||||
|
||||
#endif
|
||||
|
||||
INT16 LoadGenericButtonIcon(STR8 filename);
|
||||
|
||||
BOOLEAN UnloadGenericButtonIcon(INT16 GenImg);
|
||||
|
||||
INT32 LoadButtonImage(STR8 filename, INT32 Grayed, INT32 OffNormal, INT32 OffHilite, INT32 OnNormal, INT32 OnHilite);
|
||||
INT32 UseLoadedButtonImage(INT32 LoadedImg, INT32 Grayed, INT32 OffNormal, INT32 OffHilite, INT32 OnNormal, INT32 OnHilite);
|
||||
INT32 UseVObjAsButtonImage(HVOBJECT hVObject, INT32 Grayed, INT32 OffNormal, INT32 OffHilite, INT32 OnNormal, INT32 OnHilite);
|
||||
void UnloadButtonImage(INT32 Index);
|
||||
INT16 LoadGenericButtonImages(STR8 GrayName,STR8 OffNormName, STR8 OffHiliteName, STR8 OnNormName,STR8 OnHiliteName,STR8 BkGrndName,INT16 Index,INT16 OffsetX, INT16 OffsetY);
|
||||
BOOLEAN UnloadGenericButtonImage(INT16 GenImg);
|
||||
|
||||
BOOLEAN SetButtonDestBuffer(UINT32 DestBuffer);
|
||||
|
||||
BOOLEAN EnableButton(INT32 iButtonID);
|
||||
BOOLEAN DisableButton(INT32 iButtonID);
|
||||
void RemoveButton(INT32 iButtonID );
|
||||
void HideButton( INT32 iButtonID );
|
||||
void ShowButton( INT32 iButton );
|
||||
|
||||
void RenderButtons(void);
|
||||
BOOLEAN DrawButton(INT32 iButtonID);
|
||||
void DrawButtonFromPtr(GUI_BUTTON *b);
|
||||
|
||||
//Base button types
|
||||
void DrawGenericButton(GUI_BUTTON *b);
|
||||
void DrawQuickButton(GUI_BUTTON *b);
|
||||
void DrawCheckBoxButton( GUI_BUTTON *b );
|
||||
//Additional layers on buttons that can exist in any combination on generic or quick buttons
|
||||
//To do so, use the new specify functions below.
|
||||
void DrawIconOnButton(GUI_BUTTON *b);
|
||||
void DrawTextOnButton(GUI_BUTTON *b);
|
||||
|
||||
extern BOOLEAN gfRenderHilights;
|
||||
#define EnableHilightsAndHelpText() gfRenderHilights = TRUE;
|
||||
#define DisableHilightsAndHelpText() gfRenderHilights = FALSE;
|
||||
|
||||
//Providing you have allocated your own image, this is a somewhat simplified function.
|
||||
INT32 QuickCreateButton(UINT32 Image, INT16 xloc, INT16 yloc, INT32 Type,INT16 Priority,GUI_CALLBACK MoveCallback,GUI_CALLBACK ClickCallback);
|
||||
|
||||
//A hybrid of QuickCreateButton. Takes a lot less parameters, but makes more assumptions. It self manages the
|
||||
//loading, and deleting of the image. The size of the image determines the size of the button. It also uses
|
||||
//the default move callback which emulates Win95. Finally, it sets the priority to normal. The function you
|
||||
//choose also determines the type of button (toggle, notoggle, or newtoggle)
|
||||
INT32 CreateEasyNoToggleButton ( INT32 x, INT32 y, STR8 filename, GUI_CALLBACK ClickCallback );
|
||||
|
||||
INT32 CreateEasyToggleButton ( INT32 x, INT32 y, STR8 filename, GUI_CALLBACK ClickCallback );
|
||||
|
||||
INT32 CreateEasyNewToggleButton( INT32 x, INT32 y, STR8 filename, GUI_CALLBACK ClickCallback );
|
||||
//Same as above, but accepts specify toggle type
|
||||
|
||||
INT32 CreateEasyButton( INT32 x, INT32 y, STR8 filename, INT32 Type, GUI_CALLBACK ClickCallback);
|
||||
//Same as above, but accepts priority specification.
|
||||
INT32 CreateSimpleButton( INT32 x, INT32 y, STR8 filename, INT32 Type, INT16 Priority, GUI_CALLBACK ClickCallback );
|
||||
|
||||
INT32 CreateCheckBoxButton( INT16 x, INT16 y, STR8 filename, INT16 Priority, GUI_CALLBACK ClickCallback );
|
||||
|
||||
INT32 CreateIconButton(INT16 Icon,INT16 IconIndex,INT16 GenImg,INT16 xloc,INT16 yloc,INT16 w,INT16 h,INT32 Type,INT16 Priority,GUI_CALLBACK MoveCallback,GUI_CALLBACK ClickCallback);
|
||||
INT32 CreateHotSpot(INT16 xloc, INT16 yloc, INT16 Width, INT16 Height,INT16 Priority,GUI_CALLBACK MoveCallback,GUI_CALLBACK ClickCallback);
|
||||
|
||||
INT32 CreateTextButton(STR16 string, UINT32 uiFont, INT16 sForeColor, INT16 sShadowColor, INT16 GenImg, INT16 xloc, INT16 yloc, INT16 w, INT16 h, INT32 Type, INT16 Priority,GUI_CALLBACK MoveCallback, GUI_CALLBACK ClickCallback);
|
||||
INT32 CreateIconAndTextButton( INT32 Image, const STR16 string, UINT32 uiFont,
|
||||
INT16 sForeColor, INT16 sShadowColor,
|
||||
INT16 sForeColorDown, INT16 sShadowColorDown,
|
||||
INT8 bJustification,
|
||||
INT16 xloc, INT16 yloc, INT32 Type, INT16 Priority,
|
||||
GUI_CALLBACK MoveCallback,GUI_CALLBACK ClickCallback);
|
||||
|
||||
//New functions
|
||||
void SpecifyButtonText( INT32 iButtonID, STR16 string );
|
||||
void SpecifyButtonFont( INT32 iButtonID, UINT32 uiFont );
|
||||
void SpecifyButtonMultiColorFont(INT32 iButtonID, BOOLEAN fMultiColor);
|
||||
void SpecifyButtonUpTextColors( INT32 iButtonID, INT16 sForeColor, INT16 sShadowColor );
|
||||
void SpecifyButtonDownTextColors( INT32 iButtonID, INT16 sForeColorDown, INT16 sShadowColorDown );
|
||||
void SpecifyButtonHilitedTextColors( INT32 iButtonID, INT16 sForeColorHilited, INT16 sShadowColorHilited );
|
||||
void SpecifyButtonTextJustification( INT32 iButtonID, INT8 bJustification );
|
||||
void SpecifyGeneralButtonTextAttributes( INT32 iButtonID, STR16 string, INT32 uiFont,
|
||||
INT16 sForeColor, INT16 sShadowColor );
|
||||
void SpecifyFullButtonTextAttributes( INT32 iButtonID, STR16 string, INT32 uiFont,
|
||||
INT16 sForeColor, INT16 sShadowColor,
|
||||
INT16 sForeColorDown, INT16 sShadowColorDown, INT8 bJustification );
|
||||
void SpecifyGeneralButtonTextAttributes( INT32 iButtonID, STR16 string, INT32 uiFont,
|
||||
INT16 sForeColor, INT16 sShadowColor );
|
||||
void SpecifyButtonTextOffsets( INT32 iButtonID, INT8 bTextXOffset, INT8 bTextYOffset, BOOLEAN fShiftText );
|
||||
void SpecifyButtonTextSubOffsets( INT32 iButtonID, INT8 bTextXOffset, INT8 bTextYOffset, BOOLEAN fShiftText );
|
||||
void SpecifyButtonTextWrappedWidth(INT32 iButtonID, INT16 sWrappedWidth);
|
||||
|
||||
void SpecifyButtonSoundScheme( INT32 iButtonID, INT8 bSoundScheme );
|
||||
//OJW - 20081224
|
||||
BOOLEAN SpecifyButtonImage( INT32 iButtonID, UINT32 iButtonImageID);
|
||||
BOOLEAN SpecifyButtonImage( GUI_BUTTON *b, UINT32 iButtonImageID);
|
||||
void PlayButtonSound( INT32 iButtonID, INT32 iSoundType );
|
||||
|
||||
void AllowDisabledButtonFastHelp( INT32 iButtonID, BOOLEAN fAllow );
|
||||
|
||||
enum{
|
||||
DEFAULT_STATUS_NONE,
|
||||
DEFAULT_STATUS_DARKBORDER, //shades the borders 2 pixels deep
|
||||
DEFAULT_STATUS_DOTTEDINTERIOR, //draws the familiar dotted line in the interior portion of the button.
|
||||
DEFAULT_STATUS_WINDOWS95, //both DARKBORDER and DOTTEDINTERIOR
|
||||
};
|
||||
void GiveButtonDefaultStatus( INT32 iButtonID, INT32 iDefaultStatus );
|
||||
void RemoveButtonDefaultStatus( INT32 iButtonID );
|
||||
|
||||
enum //for use with SpecifyDisabledButtonStyle
|
||||
{
|
||||
DISABLED_STYLE_NONE, //for dummy buttons, panels, etc. Always displays normal state.
|
||||
DISABLED_STYLE_DEFAULT, //if button has text then shade, else hatch
|
||||
DISABLED_STYLE_HATCHED, //always hatches the disabled button
|
||||
DISABLED_STYLE_SHADED //always shades the disabled button 25% darker
|
||||
};
|
||||
void SpecifyDisabledButtonStyle( INT32 iButtonID, INT8 bStyle );
|
||||
|
||||
|
||||
void RemoveTextFromButton( INT32 iButtonID );
|
||||
void RemoveIconFromButton( INT32 iButtonID );
|
||||
|
||||
//Note: Text is always on top
|
||||
//If fShiftImage is true, then the image will shift down one pixel and right one pixel
|
||||
//just like the text does.
|
||||
BOOLEAN SpecifyButtonIcon( INT32 iButtonID, INT32 iVideoObjectID, UINT16 usVideoObjectIndex,
|
||||
INT8 bXOffset, INT8 bYOffset, BOOLEAN fShiftImage );
|
||||
|
||||
|
||||
|
||||
void SetButtonPosition(INT32 iButtonID,INT16 x, INT16 y);
|
||||
void ResizeButton(INT32 iButtonID,INT16 w, INT16 h);
|
||||
|
||||
|
||||
void QuickButtonCallbackMMove(MOUSE_REGION *reg,INT32 reason);
|
||||
void QuickButtonCallbackMButn(MOUSE_REGION *reg,INT32 reason);
|
||||
|
||||
BOOLEAN SetButtonCursor(INT32 iBtnId, UINT16 crsr);
|
||||
void MSYS_SetBtnUserData(INT32 iButtonNum,INT32 index,INT32 userdata);
|
||||
INT32 MSYS_GetBtnUserData(GUI_BUTTON *b,INT32 index);
|
||||
void MarkAButtonDirty( INT32 iButtonNum ); // will mark only selected button dirty
|
||||
void MarkButtonsDirty(void);// Function to mark buttons dirty ( all will redraw at next RenderButtons )
|
||||
void PausedMarkButtonsDirty( void ); // mark buttons dirty for button render the frame after the next
|
||||
void UnMarkButtonDirty( INT32 iButtonIndex ); // unmark button
|
||||
void UnmarkButtonsDirty( void ); // unmark ALL the buttoms on the screen dirty
|
||||
void ForceButtonUnDirty( INT32 iButtonIndex ); // forces button undirty no matter the reason, only lasts one frame
|
||||
|
||||
// DB 98-05-05
|
||||
BOOLEAN GetButtonArea(INT32 iButtonID, SGPRect *pRect);
|
||||
// DB 99-01-13
|
||||
INT32 GetButtonWidth(INT32 iButtonID);
|
||||
INT32 GetButtonHeight(INT32 iButtonID);
|
||||
|
||||
// DB 99-08-27
|
||||
INT32 GetButtonX(INT32 iButtonID);
|
||||
INT32 GetButtonY(INT32 iButtonID);
|
||||
|
||||
void BtnGenericMouseMoveButtonCallback(GUI_BUTTON *btn,INT32 reason);
|
||||
#define DEFAULT_MOVE_CALLBACK BtnGenericMouseMoveButtonCallback
|
||||
|
||||
|
||||
void DrawCheckBoxButtonOn( INT32 iButtonID );
|
||||
|
||||
void DrawCheckBoxButtonOff( INT32 iButtonID );
|
||||
|
||||
extern UINT16 GetWidthOfButtonPic( UINT16 usButtonPicID, INT32 iSlot );
|
||||
extern UINT16 GetHeightOfButtonPic( UINT16 usButtonPicID, INT32 iSlot );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
set(sgpSrc
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Button Sound Control.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Button System.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Compression.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Cursor Control.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/DEBUG.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/debug_util.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/debug_win_util.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/DirectDraw Calls.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/DirectX Common.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/English.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/FileMan.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Font.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/himage.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/impTGA.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/input.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Ja2 Libs.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/LibraryDataBase.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/line.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/MemMan.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mousesystem.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/PCX.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/PngLoader.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Random.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sgp.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sgp_logger.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/shading.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/soundman.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/STCI.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/stringicmp.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/timer.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/vobject.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/vobject_blitters.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/vsurface.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/WinFont.cpp"
|
||||
PARENT_SCOPE)
|
||||
@@ -0,0 +1,159 @@
|
||||
#include "MemMan.h"
|
||||
#include "debug.h"
|
||||
#include "zlib.h"
|
||||
|
||||
|
||||
// mem allocation functions for ZLIB's purposes
|
||||
|
||||
voidpf ZAlloc( voidpf opaque, uInt items, uInt size )
|
||||
{
|
||||
return( MemAlloc( items * size ) );
|
||||
}
|
||||
|
||||
void ZFree( voidpf opaque, voidpf address )
|
||||
{
|
||||
MemFree( address );
|
||||
}
|
||||
|
||||
PTR DecompressInit( PTR pCompressedData, UINT32 uiDataSize )
|
||||
{
|
||||
z_stream * pZStream;
|
||||
int iZRetCode;
|
||||
|
||||
// allocate memory for the z_stream struct
|
||||
pZStream = (z_stream *)MemAlloc( sizeof( z_stream ) );
|
||||
if( pZStream == NULL )
|
||||
{ // out of memory!
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
// initial defines
|
||||
pZStream->zalloc = ZAlloc;
|
||||
pZStream->zfree = ZFree;
|
||||
pZStream->opaque = NULL;
|
||||
|
||||
// call the ZLIB init routine
|
||||
iZRetCode = inflateInit( pZStream );
|
||||
if( iZRetCode != Z_OK )
|
||||
{ // ZLIB init error!
|
||||
MemFree( pZStream );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
// set up our parameters
|
||||
pZStream->next_in = (BYTE*)pCompressedData;
|
||||
pZStream->avail_in = uiDataSize;
|
||||
return( (PTR) pZStream );
|
||||
}
|
||||
|
||||
UINT32 Decompress( PTR pDecompPtr, BYTE * pBuffer, UINT32 uiBufferLen )
|
||||
{
|
||||
int iZRetCode;
|
||||
z_stream * pZStream = (z_stream *) pDecompPtr;
|
||||
|
||||
// these assertions is in here to ensure that we get passed a proper z_stream pointer
|
||||
Assert( pZStream != NULL );
|
||||
Assert( pZStream->zalloc == ZAlloc );
|
||||
|
||||
if (pZStream->avail_in == 0)
|
||||
{ // There is nothing left to decompress!
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
// set up the z_stream with our parameters
|
||||
pZStream->next_out = pBuffer;
|
||||
pZStream->avail_out = uiBufferLen;
|
||||
|
||||
// decompress!
|
||||
iZRetCode = inflate( pZStream, Z_PARTIAL_FLUSH );
|
||||
Assert( iZRetCode == Z_OK || iZRetCode == Z_STREAM_END );
|
||||
|
||||
return( uiBufferLen - pZStream->avail_out );
|
||||
}
|
||||
|
||||
void DecompressFini( PTR pDecompPtr )
|
||||
{
|
||||
z_stream * pZStream = (z_stream *) pDecompPtr;
|
||||
|
||||
// these assertions is in here to ensure that we get passed a proper z_stream pointer
|
||||
Assert( pZStream != NULL );
|
||||
Assert( pZStream->zalloc == ZAlloc );
|
||||
|
||||
inflateEnd( pZStream );
|
||||
MemFree( pZStream );
|
||||
}
|
||||
|
||||
UINT32 CompressedBufferSize( UINT32 uiDataSize )
|
||||
{ // Function that calculates the worst-case buffer size needed to
|
||||
// hold uiDataSize bytes compressed
|
||||
|
||||
return( uiDataSize + uiDataSize / 10 + 13 );
|
||||
}
|
||||
|
||||
PTR CompressInit( BYTE * pUncompressedData, UINT32 uiDataSize )
|
||||
{
|
||||
z_stream * pZStream;
|
||||
int iZRetCode;
|
||||
|
||||
// allocate memory for the z_stream struct
|
||||
pZStream = (z_stream *)MemAlloc( sizeof( z_stream ) );
|
||||
if( pZStream == NULL )
|
||||
{ // out of memory!
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
// initial defines
|
||||
pZStream->zalloc = ZAlloc;
|
||||
pZStream->zfree = ZFree;
|
||||
pZStream->opaque = NULL;
|
||||
|
||||
// call the ZLIB init routine
|
||||
iZRetCode = deflateInit( pZStream, Z_BEST_COMPRESSION );
|
||||
if( iZRetCode != Z_OK )
|
||||
{ // ZLIB init error!
|
||||
MemFree( pZStream );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
// set up our parameters
|
||||
pZStream->next_in = pUncompressedData;
|
||||
pZStream->avail_in = uiDataSize;
|
||||
return( (PTR) pZStream );
|
||||
}
|
||||
|
||||
UINT32 Compress( PTR pCompPtr, BYTE * pBuffer, UINT32 uiBufferLen )
|
||||
{
|
||||
int iZRetCode;
|
||||
z_stream * pZStream = (z_stream *) pCompPtr;
|
||||
|
||||
// these assertions is in here to ensure that we get passed a proper z_stream pointer
|
||||
Assert( pZStream != NULL );
|
||||
Assert( pZStream->zalloc == ZAlloc );
|
||||
|
||||
if (pZStream->avail_in == 0)
|
||||
{ // There is nothing left to compress!
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
// set up the z_stream with our parameters
|
||||
pZStream->next_out = pBuffer;
|
||||
pZStream->avail_out = uiBufferLen;
|
||||
|
||||
// decompress!
|
||||
iZRetCode = deflate( pZStream, Z_FINISH );
|
||||
Assert( iZRetCode == Z_STREAM_END );
|
||||
|
||||
return( uiBufferLen - pZStream->avail_out );
|
||||
}
|
||||
|
||||
void CompressFini( PTR pCompPtr )
|
||||
{
|
||||
z_stream * pZStream = (z_stream *) pCompPtr;
|
||||
|
||||
// these assertions is in here to ensure that we get passed a proper z_stream pointer
|
||||
Assert( pZStream != NULL );
|
||||
Assert( pZStream->zalloc == ZAlloc );
|
||||
|
||||
deflateEnd( pZStream );
|
||||
MemFree( pZStream );
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#if !defined( COMPRESSION_H )
|
||||
|
||||
#define COMPRESSION_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
// Notes on how to use these functions without getting your hands dirty:
|
||||
|
||||
// To decompress:
|
||||
//
|
||||
// 1) call DecompressInit() with a pointer to your compressed data, and the
|
||||
// size of that compressed data. DecompressInit() returns a "decompression
|
||||
// pointer" that you should pass to Decompress() and DecompressFini()
|
||||
//
|
||||
// 2) call Decompress() with the decompression pointer, a pointer to a
|
||||
// buffer for decompressed data, and the length of that buffer. If the
|
||||
// buffer is not large enough to hold all of the decompressed data,
|
||||
// Decompress() will fill it completely, and you can call Decompress() again
|
||||
// to continue your decompression. You are responsible for knowing the
|
||||
// size your data will be after decompression. (The STI/STCI file format
|
||||
// records your original data size for you...) Decompress() returns the
|
||||
// number of bytes of output.
|
||||
//
|
||||
// 3) call DecompressFini() with the decompression pointer when you're done
|
||||
|
||||
PTR DecompressInit( PTR pCompressedData, UINT32 uiDataSize );
|
||||
UINT32 Decompress( PTR pDecompPtr, BYTE * pBuffer, UINT32 uiBufferLen );
|
||||
void DecompressFini( PTR pDecompPtr );
|
||||
|
||||
// To compress:
|
||||
//
|
||||
// 1) call CompressInit() with a pointer to your uncompressed data, and the
|
||||
// size of that uncompressed data. CompressInit() returns a "compression
|
||||
// pointer" that you should pass to Compress() and CompressFini()
|
||||
//
|
||||
// 2) call Compress() with the compression pointer, a pointer to a
|
||||
// buffer for compressed data, and the length of that buffer. If the
|
||||
// buffer is not large enough to hold all of the compressed data,
|
||||
// Compress() will fill it completely, and you can call Compress() again
|
||||
// with a new or emptied buffer to continue your compression later. You
|
||||
// can call CompressedBufferSize() to determine the largest buffer size you
|
||||
// should need for a certain number of bytes. Ccompress() returns the number
|
||||
// of bytes of output.
|
||||
//
|
||||
// 3) call CompressFini() with the compression pointer when you're done
|
||||
|
||||
UINT32 CompressedBufferSize( UINT32 uiDataSize );
|
||||
PTR CompressInit( BYTE * pUncompressedData, UINT32 uiDataSize );
|
||||
UINT32 Compress( PTR pCompPtr, BYTE * pBuffer, UINT32 uiBufferLen );
|
||||
void CompressFini( PTR pCompPtr );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,627 @@
|
||||
#include "Cursor Control.h"
|
||||
|
||||
#include "video.h"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Cursor Database
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOLEAN gfCursorDatabaseInit = FALSE;
|
||||
|
||||
CursorFileData *gpCursorFileDatabase;
|
||||
CursorData *gpCursorDatabase;
|
||||
INT16 gsGlobalCursorYOffset = 0;
|
||||
INT16 gsCurMouseOffsetX = 0;
|
||||
INT16 gsCurMouseOffsetY = 0;
|
||||
UINT16 gsCurMouseHeight = 0;
|
||||
UINT16 gsCurMouseWidth = 0;
|
||||
UINT16 gusNumDataFiles = 0;
|
||||
UINT32 guiExternVo;
|
||||
UINT16 gusExternVoSubIndex;
|
||||
UINT32 guiExtern2Vo;
|
||||
UINT16 gusExtern2VoSubIndex;
|
||||
UINT32 guiOldSetCursor = 0;
|
||||
UINT32 guiDelayTimer = 0;
|
||||
|
||||
|
||||
MOUSEBLT_HOOK gMouseBltOverride = NULL;
|
||||
|
||||
|
||||
|
||||
BOOLEAN BltToMouseCursorFromVObject( HVOBJECT hVObject, UINT16 usVideoObjectSubIndex, UINT16 usXPos, UINT16 usYPos )
|
||||
{
|
||||
BOOLEAN ReturnValue;
|
||||
|
||||
ReturnValue = BltVideoObject(MOUSE_BUFFER, hVObject, usVideoObjectSubIndex, usXPos, usYPos, VO_BLT_SRCTRANSPARENCY, NULL);
|
||||
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
BOOLEAN BltToMouseCursorFromVObjectWithOutline( HVOBJECT hVObject, UINT16 usVideoObjectSubIndex, UINT16 usXPos, UINT16 usYPos )
|
||||
{
|
||||
BOOLEAN ReturnValue;
|
||||
ETRLEObject *pTrav;
|
||||
INT16 sXPos, sYPos;
|
||||
|
||||
// Adjust for offsets
|
||||
pTrav = &(hVObject->pETRLEObject[ usVideoObjectSubIndex ] );
|
||||
|
||||
sXPos = 0;
|
||||
sYPos = 0;
|
||||
|
||||
// Remove offsets...
|
||||
sXPos -= pTrav->sOffsetX;
|
||||
sYPos -= pTrav->sOffsetY;
|
||||
|
||||
// Center!
|
||||
sXPos += ( ( gsCurMouseWidth - pTrav->usWidth ) / 2 );
|
||||
sYPos += ( ( gsCurMouseHeight - pTrav->usHeight ) / 2 );
|
||||
|
||||
ReturnValue = BltVideoObjectOutline(MOUSE_BUFFER, hVObject, usVideoObjectSubIndex, sXPos, sYPos, Get16BPPColor( FROMRGB( 0, 255, 0 ) ), TRUE );
|
||||
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
|
||||
// THESE TWO PARAMETERS MUST POINT TO STATIC OR GLOBAL DATA, NOT AUTOMATIC VARIABLES
|
||||
void InitCursorDatabase( CursorFileData *pCursorFileData, CursorData *pCursorData, UINT16 suNumDataFiles )
|
||||
{
|
||||
// Set global values!
|
||||
|
||||
gpCursorFileDatabase = pCursorFileData;
|
||||
gpCursorDatabase = pCursorData;
|
||||
gusNumDataFiles = suNumDataFiles;
|
||||
gfCursorDatabaseInit = TRUE;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Cursor Handlers
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOLEAN LoadCursorData(UINT32 uiCursorIndex)
|
||||
{
|
||||
// Load cursor data will load all data required for the cursor specified by this index
|
||||
CursorData *pCurData;
|
||||
CursorImage *pCurImage;
|
||||
UINT32 cnt;
|
||||
INT16 sMaxHeight = -1;
|
||||
INT16 sMaxWidth = -1;
|
||||
ETRLEObject *pTrav;
|
||||
|
||||
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
|
||||
|
||||
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
|
||||
{
|
||||
|
||||
pCurImage = &( pCurData->Composites[ cnt ] );
|
||||
|
||||
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].fLoaded == FALSE )
|
||||
{
|
||||
//
|
||||
// The file containing the video object hasn't been loaded yet. Let's load it now
|
||||
//
|
||||
VOBJECT_DESC VideoObjectDescription;
|
||||
// FIRST LOAD AS AN HIMAGE SO WE CAN GET AUX DATA!
|
||||
HIMAGE hImage;
|
||||
AuxObjectData *pAuxData;
|
||||
|
||||
|
||||
// ATE: First check if we are using an extern vo cursor...
|
||||
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags & USE_EXTERN_VO_CURSOR )
|
||||
{
|
||||
// Let's check if we have NOT NULL here...
|
||||
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject == NULL )
|
||||
{
|
||||
// Something wrong here...
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
hImage = CreateImage( (CHAR8 *)gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFilename, IMAGE_ALLDATA );
|
||||
if (hImage == NULL)
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
VideoObjectDescription.fCreateFlags = VOBJECT_CREATE_FROMHIMAGE;
|
||||
VideoObjectDescription.hImage = hImage;
|
||||
|
||||
if ( !AddVideoObject( &VideoObjectDescription, &( gpCursorFileDatabase[ pCurImage->uiFileIndex ].uiIndex) ) )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Check for animated tile
|
||||
if (hImage->uiAppDataSize > 0 )
|
||||
{
|
||||
// Valid auxiliary data, so get # od frames from data
|
||||
pAuxData = ( AuxObjectData* ) hImage->pAppData;
|
||||
|
||||
if ( pAuxData->fFlags & AUX_ANIMATED_TILE )
|
||||
{
|
||||
gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags |= ANIMATED_CURSOR;
|
||||
gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubNumberOfFrames = pAuxData->ubNumberOfFrames;
|
||||
}
|
||||
}
|
||||
|
||||
// the hImage is no longer needed
|
||||
DestroyImage( hImage );
|
||||
|
||||
// Save hVObject....
|
||||
GetVideoObject( &(gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject), gpCursorFileDatabase[ pCurImage->uiFileIndex ].uiIndex );
|
||||
|
||||
}
|
||||
|
||||
gpCursorFileDatabase[ pCurImage->uiFileIndex ].fLoaded = TRUE;
|
||||
|
||||
}
|
||||
|
||||
// Get ETRLE Data for this video object
|
||||
pTrav = &(gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject->pETRLEObject[ pCurImage->uiSubIndex ] );
|
||||
|
||||
if( !pTrav )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( pTrav->usHeight > sMaxHeight )
|
||||
{
|
||||
sMaxHeight = pTrav->usHeight;
|
||||
}
|
||||
|
||||
if ( pTrav->usWidth > sMaxWidth )
|
||||
{
|
||||
sMaxWidth = pTrav->usWidth;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
pCurData->usHeight = sMaxHeight;
|
||||
pCurData->usWidth = sMaxWidth;
|
||||
|
||||
|
||||
if ( pCurData->sOffsetX == CENTER_CURSOR )
|
||||
{
|
||||
pCurData->sOffsetX = ( pCurData->usWidth / 2 );
|
||||
}
|
||||
if ( pCurData->sOffsetX == RIGHT_CURSOR )
|
||||
{
|
||||
pCurData->sOffsetX = pCurData->usWidth;
|
||||
}
|
||||
if ( pCurData->sOffsetX == LEFT_CURSOR )
|
||||
{
|
||||
pCurData->sOffsetX = 0;
|
||||
}
|
||||
|
||||
if ( pCurData->sOffsetY == CENTER_CURSOR )
|
||||
{
|
||||
pCurData->sOffsetY = ( pCurData->usHeight / 2 );
|
||||
}
|
||||
if ( pCurData->sOffsetY == BOTTOM_CURSOR )
|
||||
{
|
||||
pCurData->sOffsetY = pCurData->usHeight;
|
||||
}
|
||||
if ( pCurData->sOffsetY == TOP_CURSOR )
|
||||
{
|
||||
pCurData->sOffsetY = 0;
|
||||
}
|
||||
|
||||
|
||||
gsCurMouseOffsetX = pCurData->sOffsetX;
|
||||
gsCurMouseOffsetY = pCurData->sOffsetY;
|
||||
gsCurMouseHeight = pCurData->usHeight;
|
||||
gsCurMouseWidth = pCurData->usWidth;
|
||||
|
||||
// Adjust relative offsets
|
||||
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
|
||||
{
|
||||
pCurImage = &( pCurData->Composites[ cnt ] );
|
||||
|
||||
// Get ETRLE Data for this video object
|
||||
pTrav = &(gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject->pETRLEObject[ pCurImage->uiSubIndex ] );
|
||||
|
||||
if( !pTrav )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( pCurImage->usPosX == CENTER_SUBCURSOR )
|
||||
{
|
||||
pCurImage->usPosX = pCurData->sOffsetX - ( pTrav->usWidth / 2 );
|
||||
}
|
||||
|
||||
if ( pCurImage->usPosY == CENTER_SUBCURSOR )
|
||||
{
|
||||
pCurImage->usPosY = pCurData->sOffsetY - ( pTrav->usHeight / 2 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void UnLoadCursorData(UINT32 uiCursorIndex)
|
||||
{
|
||||
// This function will unload add data used for this cursor
|
||||
//
|
||||
// Ok, first we make sure that the video object file is indeed loaded. Once this is verified, we will
|
||||
// move on to the deletion
|
||||
//
|
||||
CursorData *pCurData;
|
||||
CursorImage *pCurImage;
|
||||
UINT32 cnt;
|
||||
|
||||
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
|
||||
|
||||
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
|
||||
{
|
||||
|
||||
pCurImage = &( pCurData->Composites[ cnt ] );
|
||||
|
||||
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].fLoaded )
|
||||
{
|
||||
if ( !( gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags & USE_EXTERN_VO_CURSOR ) )
|
||||
{
|
||||
DeleteVideoObjectFromIndex( gpCursorFileDatabase[ pCurImage->uiFileIndex ].uiIndex);
|
||||
gpCursorFileDatabase[ pCurImage->uiFileIndex ].uiIndex = 0;
|
||||
}
|
||||
gpCursorFileDatabase[ pCurImage->uiFileIndex ].fLoaded = FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CursorDatabaseClear(void)
|
||||
{
|
||||
UINT32 uiIndex;
|
||||
|
||||
for (uiIndex = 0; uiIndex < gusNumDataFiles; uiIndex++)
|
||||
{
|
||||
if (gpCursorFileDatabase[uiIndex].fLoaded == TRUE)
|
||||
{
|
||||
if ( !( gpCursorFileDatabase[ uiIndex ].ubFlags & USE_EXTERN_VO_CURSOR ) )
|
||||
{
|
||||
DeleteVideoObjectFromIndex( gpCursorFileDatabase[uiIndex].uiIndex);
|
||||
gpCursorFileDatabase[uiIndex].uiIndex = 0;
|
||||
}
|
||||
|
||||
gpCursorFileDatabase[uiIndex].fLoaded = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOLEAN SetCurrentCursorFromDatabase( UINT32 uiCursorIndex )
|
||||
{
|
||||
|
||||
BOOLEAN ReturnValue = TRUE;
|
||||
UINT16 usSubIndex;
|
||||
CursorData *pCurData;
|
||||
CursorImage *pCurImage;
|
||||
UINT32 cnt;
|
||||
INT16 sCenterValX, sCenterValY;
|
||||
HVOBJECT hVObject;
|
||||
ETRLEObject *pTrav;
|
||||
UINT16 usEffHeight, usEffWidth;
|
||||
|
||||
if ( gfCursorDatabaseInit )
|
||||
{
|
||||
// If the current cursor is the first index, disable cursors
|
||||
|
||||
if ( uiCursorIndex == VIDEO_NO_CURSOR )
|
||||
{
|
||||
EraseMouseCursor( );
|
||||
|
||||
SetMouseCursorProperties( 0, 0, 5, 5 );
|
||||
DirtyCursor( );
|
||||
|
||||
//EnableCursor( FALSE );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// CHECK FOR EXTERN CURSOR
|
||||
if ( uiCursorIndex == EXTERN_CURSOR || uiCursorIndex == EXTERN2_CURSOR )
|
||||
{
|
||||
INT16 sSubX, sSubY;
|
||||
HVOBJECT hVObjectTemp;
|
||||
ETRLEObject *pTravTemp;
|
||||
|
||||
// Erase old cursor
|
||||
EraseMouseCursor( );
|
||||
|
||||
if ( uiCursorIndex == EXTERN2_CURSOR )
|
||||
{
|
||||
// Get ETRLE values
|
||||
GetVideoObject( &hVObject, guiExtern2Vo );
|
||||
pTrav = &(hVObject->pETRLEObject[ gusExtern2VoSubIndex ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get ETRLE values
|
||||
GetVideoObject( &hVObject, guiExternVo );
|
||||
pTrav = &(hVObject->pETRLEObject[ gusExternVoSubIndex ] );
|
||||
}
|
||||
|
||||
// Determine center
|
||||
sCenterValX = 0;
|
||||
sCenterValY = 0;
|
||||
|
||||
// Effective height
|
||||
usEffHeight = pTrav->usHeight + pTrav->sOffsetY;
|
||||
usEffWidth = pTrav->usWidth + pTrav->sOffsetX;
|
||||
|
||||
|
||||
// ATE: Check for extern 2nd...
|
||||
if ( uiCursorIndex == EXTERN2_CURSOR )
|
||||
{
|
||||
BltVideoObjectOutlineFromIndex( MOUSE_BUFFER, guiExtern2Vo, gusExtern2VoSubIndex, 0, 0, 0, FALSE );
|
||||
|
||||
// Get ETRLE values
|
||||
GetVideoObject( &hVObjectTemp, guiExternVo );
|
||||
pTravTemp = &(hVObjectTemp->pETRLEObject[ gusExternVoSubIndex ] );
|
||||
|
||||
sSubX = ( pTrav->usWidth - pTravTemp->usWidth - pTravTemp->sOffsetX ) / 2;
|
||||
sSubY = ( pTrav->usHeight - pTravTemp->usHeight - pTravTemp->sOffsetY ) / 2;
|
||||
|
||||
BltVideoObjectOutlineFromIndex( MOUSE_BUFFER, guiExternVo, gusExternVoSubIndex, sSubX, sSubY, 0, FALSE );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
BltVideoObjectOutlineFromIndex( MOUSE_BUFFER, guiExternVo, gusExternVoSubIndex, 0, 0, 0, FALSE );
|
||||
}
|
||||
|
||||
// Hook into hook function
|
||||
if ( gMouseBltOverride != NULL )
|
||||
{
|
||||
gMouseBltOverride( );
|
||||
}
|
||||
|
||||
|
||||
SetMouseCursorProperties( (INT16)(usEffWidth/2), (INT16)(usEffHeight/2), (UINT16)(usEffHeight), (UINT16)(usEffWidth ) );
|
||||
DirtyCursor( );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
|
||||
|
||||
// First check if we are a differnet curosr...
|
||||
if ( uiCursorIndex != guiOldSetCursor )
|
||||
{
|
||||
// OK, check if we are a delay cursor...
|
||||
if ( pCurData->bFlags & DELAY_START_CURSOR )
|
||||
{
|
||||
guiDelayTimer = GetTickCount( );
|
||||
}
|
||||
}
|
||||
|
||||
guiOldSetCursor = uiCursorIndex;
|
||||
|
||||
// Olny update if delay timer has elapsed...
|
||||
if ( pCurData->bFlags & DELAY_START_CURSOR )
|
||||
{
|
||||
if ( ( GetTickCount( ) - guiDelayTimer ) < 1000 )
|
||||
{
|
||||
EraseMouseCursor( );
|
||||
|
||||
SetMouseCursorProperties( 0, 0, 5, 5 );
|
||||
DirtyCursor( );
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Call LoadCursorData to make sure that the video object is loaded
|
||||
//
|
||||
LoadCursorData(uiCursorIndex);
|
||||
|
||||
// Erase old cursor
|
||||
EraseMouseCursor( );
|
||||
// NOW ACCOMODATE COMPOSITE CURSORS
|
||||
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
|
||||
|
||||
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
|
||||
{
|
||||
|
||||
// Check if we are a flashing cursor!
|
||||
if ( pCurData->bFlags & CURSOR_TO_FLASH )
|
||||
{
|
||||
if ( cnt <= 1 )
|
||||
{
|
||||
if ( pCurData->bFlashIndex != cnt )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if we are a sub cursor!
|
||||
// IN this case, do all frames but
|
||||
// skip the 1st or second!
|
||||
|
||||
if ( pCurData->bFlags & CURSOR_TO_SUB_CONDITIONALLY )
|
||||
{
|
||||
if ( pCurData->bFlags & CURSOR_TO_FLASH )
|
||||
{
|
||||
if ( cnt <= 1 )
|
||||
{
|
||||
if ( pCurData->bFlashIndex != cnt )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( pCurData->bFlags & CURSOR_TO_FLASH2 )
|
||||
{
|
||||
if ( cnt <= 2 && cnt > 0 )
|
||||
{
|
||||
if ( pCurData->bFlashIndex != cnt )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( cnt <= 1 )
|
||||
{
|
||||
if ( pCurData->bFlashIndex != cnt )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pCurImage = &( pCurData->Composites[ cnt ] );
|
||||
|
||||
// Adjust sub-index if cursor is animated
|
||||
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex].ubFlags & ANIMATED_CURSOR )
|
||||
{
|
||||
usSubIndex = (UINT16)pCurImage->uiCurrentFrame;
|
||||
}
|
||||
else
|
||||
{
|
||||
usSubIndex = pCurImage->uiSubIndex;
|
||||
}
|
||||
|
||||
if ( pCurImage->usPosX != HIDE_SUBCURSOR && pCurImage->usPosY != HIDE_SUBCURSOR )
|
||||
{
|
||||
// Blit cursor at position in mouse buffer
|
||||
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex].ubFlags & USE_OUTLINE_BLITTER )
|
||||
{
|
||||
ReturnValue = BltToMouseCursorFromVObjectWithOutline( gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject , usSubIndex, pCurImage->usPosX, pCurImage->usPosY );
|
||||
}
|
||||
else
|
||||
{
|
||||
ReturnValue = BltToMouseCursorFromVObject( gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject , usSubIndex, pCurImage->usPosX, pCurImage->usPosY );
|
||||
}
|
||||
if ( !ReturnValue )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//if ( pCurData->bFlags & CURSOR_TO_FLASH )
|
||||
//{
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
// Hook into hook function
|
||||
if ( gMouseBltOverride != NULL )
|
||||
{
|
||||
gMouseBltOverride( );
|
||||
}
|
||||
|
||||
|
||||
sCenterValX = pCurData->sOffsetX;
|
||||
sCenterValY = pCurData->sOffsetY;
|
||||
|
||||
SetMouseCursorProperties( sCenterValX, (INT16)( sCenterValY + gsGlobalCursorYOffset ), pCurData->usHeight, pCurData->usWidth );
|
||||
DirtyCursor( );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( uiCursorIndex == VIDEO_NO_CURSOR )
|
||||
{
|
||||
EraseMouseCursor( );
|
||||
|
||||
SetMouseCursorProperties( 0, 0, 5, 5 );
|
||||
DirtyCursor( );
|
||||
|
||||
//EnableCursor( FALSE );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
SetCurrentCursor( (UINT16)uiCursorIndex, 0, 0 );
|
||||
ReturnValue = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return ( ReturnValue );
|
||||
|
||||
}
|
||||
|
||||
void SetMouseBltHook( MOUSEBLT_HOOK pMouseBltOverride )
|
||||
{
|
||||
gMouseBltOverride = pMouseBltOverride;
|
||||
}
|
||||
|
||||
|
||||
// Sets an external video object as cursor file data....
|
||||
void SetExternVOData( UINT32 uiCursorIndex, HVOBJECT hVObject, UINT16 usSubIndex )
|
||||
{
|
||||
CursorData *pCurData;
|
||||
CursorImage *pCurImage;
|
||||
UINT32 cnt;
|
||||
|
||||
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
|
||||
|
||||
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
|
||||
{
|
||||
pCurImage = &( pCurData->Composites[ cnt ] );
|
||||
|
||||
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags & USE_EXTERN_VO_CURSOR )
|
||||
{
|
||||
// OK, set Video Object here....
|
||||
|
||||
// If loaded, unload...
|
||||
UnLoadCursorData( uiCursorIndex );
|
||||
|
||||
// Set extern vo
|
||||
gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject = hVObject;
|
||||
pCurImage->uiSubIndex = usSubIndex;
|
||||
|
||||
|
||||
// Reload....
|
||||
LoadCursorData( uiCursorIndex );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RemoveExternVOData( UINT32 uiCursorIndex )
|
||||
{
|
||||
CursorData *pCurData;
|
||||
CursorImage *pCurImage;
|
||||
UINT32 cnt;
|
||||
|
||||
pCurData = &( gpCursorDatabase[ uiCursorIndex ] );
|
||||
|
||||
for ( cnt = 0; cnt < pCurData->usNumComposites; cnt++ )
|
||||
{
|
||||
pCurImage = &( pCurData->Composites[ cnt ] );
|
||||
|
||||
if ( gpCursorFileDatabase[ pCurImage->uiFileIndex ].ubFlags & USE_EXTERN_VO_CURSOR )
|
||||
{
|
||||
gpCursorFileDatabase[ pCurImage->uiFileIndex ].hVObject = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -0,0 +1,114 @@
|
||||
#ifndef __CURSOR_DATABASE_
|
||||
#define __CURSOR_DATABASE_
|
||||
|
||||
#include "Types.h"
|
||||
#include "FileMan.h"
|
||||
#include "VObject.h"
|
||||
#include "VSurface.h"
|
||||
|
||||
#include "Video.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
extern UINT32 GetCursorHandle(UINT32 uiCursorIndex);
|
||||
extern void UnloadCursorData(UINT32 uiCursorIndex);
|
||||
extern BOOLEAN LoadCursorData(UINT32 uiCursorIndex);
|
||||
extern void CursorDatabaseClear(void);
|
||||
extern UINT16 GetCursorSubIndex(UINT32 uiCursorIndex);
|
||||
extern BOOLEAN SetCurrentCursorFromDatabase( UINT32 uiCursorIndex );
|
||||
|
||||
#define ANIMATED_CURSOR 0x02
|
||||
#define USE_EXTERN_VO_CURSOR 0x04
|
||||
#define USE_OUTLINE_BLITTER 0x08
|
||||
|
||||
#define EXTERN_CURSOR 0xFFF0
|
||||
#define EXTERN2_CURSOR 0xFFE0
|
||||
#define MAX_COMPOSITES 5
|
||||
#define CENTER_SUBCURSOR 31000
|
||||
#define HIDE_SUBCURSOR 32000
|
||||
|
||||
#define CENTER_CURSOR 32000
|
||||
#define RIGHT_CURSOR 32001
|
||||
#define LEFT_CURSOR 32002
|
||||
#define TOP_CURSOR 32003
|
||||
#define BOTTOM_CURSOR 32004
|
||||
|
||||
#define CURSOR_TO_FLASH 0x01
|
||||
#define CURSOR_TO_FLASH2 0x02
|
||||
#define CURSOR_TO_SUB_CONDITIONALLY 0x04
|
||||
#define DELAY_START_CURSOR 0x08
|
||||
#define CURSOR_TO_PLAY_SOUND 0x10
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Cursor Database
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 ubFilename[MAX_FILENAME_LEN];
|
||||
BOOLEAN fLoaded;
|
||||
UINT32 uiIndex;
|
||||
UINT8 ubFlags;
|
||||
UINT8 ubNumberOfFrames;
|
||||
HVOBJECT hVObject;
|
||||
|
||||
} CursorFileData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT32 uiFileIndex;
|
||||
UINT16 uiSubIndex;
|
||||
UINT32 uiCurrentFrame;
|
||||
INT16 usPosX;
|
||||
INT16 usPosY;
|
||||
|
||||
} CursorImage;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CursorImage Composites[ MAX_COMPOSITES ];
|
||||
UINT16 usNumComposites;
|
||||
INT16 sOffsetX;
|
||||
INT16 sOffsetY;
|
||||
UINT16 usHeight;
|
||||
UINT16 usWidth;
|
||||
UINT8 bFlags;
|
||||
UINT8 bFlashIndex;
|
||||
|
||||
} CursorData;
|
||||
|
||||
extern INT16 gsGlobalCursorYOffset;
|
||||
|
||||
// Globals for cursor database offset values
|
||||
extern INT16 gsCurMouseOffsetX;
|
||||
extern INT16 gsCurMouseOffsetY;
|
||||
extern UINT16 gsCurMouseHeight;
|
||||
extern UINT16 gsCurMouseWidth;
|
||||
|
||||
extern UINT32 guiExternVo;
|
||||
extern UINT16 gusExternVoSubIndex;
|
||||
extern UINT32 guiExtern2Vo;
|
||||
extern UINT16 gusExtern2VoSubIndex;
|
||||
extern BOOLEAN gfExternUse2nd;
|
||||
|
||||
typedef void (*MOUSEBLT_HOOK)( void );
|
||||
|
||||
void InitCursorDatabase( CursorFileData *pCursorFileData, CursorData *pCursorData, UINT16 suNumDataFiles );
|
||||
void SetMouseBltHook( MOUSEBLT_HOOK pMouseBltOverride );
|
||||
|
||||
void SetExternVOData( UINT32 uiCursorIndex, HVOBJECT hVObject, UINT16 usSubIndex );
|
||||
void RemoveExternVOData( UINT32 uiCursorIndex );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
//**************************************************************************
|
||||
//
|
||||
// Filename : debug.h
|
||||
//
|
||||
// Purpose : prototypes for the debug manager
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// xxxxx96:LH - Creation
|
||||
// xxnov96:HJH - made it work
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#ifndef __DEBUG_MANAGER_
|
||||
#define __DEBUG_MANAGER_
|
||||
|
||||
#include <crtdbg.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "TopicOps.h"
|
||||
#include "TopicIDs.h"
|
||||
|
||||
#include <vfs/Core/vfs_types.h>
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
#define MAX_TOPICS_ALLOTED 1024
|
||||
|
||||
|
||||
extern BOOLEAN gfRecordToFile;
|
||||
extern BOOLEAN gfRecordToDebugger;
|
||||
extern UINT32 guiProfileStart, guiExecutions, guiProfileTime;
|
||||
extern INT32 giProfileCount;
|
||||
|
||||
#define PROFILE(x) guiProfileStart=GetTickCount(); \
|
||||
guiExecutions=x; \
|
||||
for(giProfileCount=0; giProfileCount < x; giProfileCount++)
|
||||
|
||||
#define PROFILE_REPORT() guiProfileTime=(GetTickCount()-guiProfileStart); \
|
||||
_RPT3(_CRT_WARN, "*** PROFILE REPORT: %d executions took %dms, average of %.2fms per iteration.\n", guiExecutions, guiProfileTime, (FLOAT)guiProfileTime/guiExecutions);
|
||||
|
||||
extern STR8 String(const STR8 String, ...);
|
||||
|
||||
// This func is used by Assert()
|
||||
inline void _Null() { }
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifndef FORCE_ASSERTS_ON
|
||||
#define FORCE_ASSERTS_ON
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// Uncomment the follow to turn on more aggressive assertions
|
||||
//
|
||||
//#define USE_AGGRESSIVE_ASSERTIONS
|
||||
|
||||
#ifdef FORCE_ASSERTS_ON
|
||||
|
||||
// If FORCE_ASSERTS_ON is defined, we need to initialize all the debug macros. Otherwise all the
|
||||
// debug macros will be substituted by blank lines at compile time
|
||||
//*******************************************************************************************
|
||||
// Debug Mode
|
||||
//*******************************************************************************************
|
||||
|
||||
// *****************************************************
|
||||
// OLD ASSERT CODE. USE THE NEW ONES FURTHER DOWN BELOW
|
||||
// *****************************************************
|
||||
//Modified the Assertion code. As of the writing of this code, there are no other functions that
|
||||
//make use of _FailMessage. With that assumption made, we can then make two functions, the first Assert, taking
|
||||
//one argument, and passing a NULL string. The second one, AssertMsg(), accepts a string as the second parameter.
|
||||
//This string that has vanished for Assert is now built inside of fail message. This is the case for both Asserts, but the second one
|
||||
//also is added. Ex:
|
||||
//Assert( pointer );
|
||||
//Assert( pointer, "This pointer is null and you tried to access it in function A ");
|
||||
//It'll make debugging a little simpler. In anal cases, you could build the string first, then assert
|
||||
//with it.
|
||||
extern void _FailMessage(const char* message, unsigned lineNum, const char * functionName, const char* sourceFileName);
|
||||
inline void _FailMessage(const char* message, unsigned lineNum, const char* sourceFileName) {
|
||||
_FailMessage(message, lineNum, 0, sourceFileName );
|
||||
}
|
||||
|
||||
#define Assert(a) (a) ? _Null() : _FailMessage( NULL, __LINE__, __FILE__ )
|
||||
#define AssertMsg(a,b) (a) ? _Null() : _FailMessage( b, __LINE__, __FILE__ )
|
||||
|
||||
extern CHAR8 gubAssertString[512];//for long filenames
|
||||
|
||||
|
||||
// WDS - Enhanced debugging
|
||||
// These provide more information than the original assertions. Assertions test their condition and
|
||||
// if it fails they generate a message, try to save the game, then terminate the program.
|
||||
|
||||
|
||||
// (a) is not NIL or generate a message and terminate
|
||||
#define AssertNotNIL(a) ((a)!=0 ? _Null() : _FailMessage ("("#a" is a null pointer", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
// (a) is true or generate a message and terminate
|
||||
#define AssertT(a) ((a) ? _Null() : _FailMessage ("("#a" is false but should be true", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
// (a) is false
|
||||
#define AssertF(a) ((a) ? _Null() : _FailMessage ("("#a" is true but should be false", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
// (a == b)
|
||||
//#define AssertEQs(a,as,b,bs) (((a)==(b)) ? _Null() : _FailMessage ("("#a" "#as") != ("#b" "#bs") but they should be equal", __LINE__, __FUNCTION__, __FILE__))
|
||||
//#define AssertEQ(a,b) (AssertEQs(a,#a,b,#b))
|
||||
#define AssertEQ(a,b) (((a)==(b)) ? _Null() : _FailMessage ("("#a") != ("#b") but they should be equal", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
// (a != b)
|
||||
#define AssertNE(a,b) (((a)!=(b)) ? _Null() : _FailMessage ("("#a") == ("#b") but they should not be equal", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
// (a < b)
|
||||
#define AssertLT(a,b) (((a)<(b)) ? _Null() : _FailMessage ("("#a") >= ("#b") but should be less than", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
// (a <= b)
|
||||
#define AssertLE(a,b) (((a)<=(b)) ? _Null() : _FailMessage ("("#a") > ("#b") but should be less than or equal", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
// (a > b)
|
||||
#define AssertGT(a,b) (((a)>(b)) ? _Null() : _FailMessage ("("#a") <= ("#b") but should be greater than", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
// (a >= b)
|
||||
#define AssertGE(a,b) (((a)>=(b)) ? _Null() : _FailMessage ("("#a") < ("#b") but should be greater than or equal", __LINE__, __FUNCTION__, __FILE__))
|
||||
|
||||
#else
|
||||
|
||||
#define Assert(a) ((void *)0)
|
||||
#define AssertMsg(a,b) ((void *)0)
|
||||
|
||||
//*******************************************************************************************
|
||||
#endif
|
||||
|
||||
|
||||
// Kaiden: Added this for Map Editor
|
||||
#ifdef JA2BETAVERSION
|
||||
extern CHAR8 gubAssertString[512];//for long filenames
|
||||
#endif
|
||||
|
||||
// Moved these out of the defines - debug mgr always initialized
|
||||
#define InitializeDebugManager() DbgInitialize()
|
||||
#define ShutdownDebugManager() DbgShutdown()
|
||||
|
||||
extern bool DbgInitialize();
|
||||
extern void DbgShutdown();
|
||||
|
||||
|
||||
#ifdef SGP_DEBUG
|
||||
// If DEBUG_ is defined, we need to initialize all the debug macros. Otherwise all the
|
||||
// debug macros will be substituted by blank lines at compile time
|
||||
//*******************************************************************************************
|
||||
// Debug Mode
|
||||
//*******************************************************************************************
|
||||
|
||||
extern bool gfDebugTopics[MAX_TOPICS_ALLOTED];
|
||||
// These are the debug macros (the ones the use will use). The user should never call
|
||||
// the actual debug functions directly
|
||||
|
||||
// Force a breakpoint in the debugger
|
||||
#define DebugBreakpoint() __asm { int 3 }
|
||||
|
||||
|
||||
#define DbgMessage(a, b, c) (gfDebugTopics[(a)] ? DbgMessageReal((a), TOPIC_MESSAGE, (b), (c) ) : _Null())
|
||||
#define FastDebugMsg(a) _DebugMessage((a), __LINE__, __FILE__)
|
||||
|
||||
#define UnRegisterDebugTopic(a, b) DbgTopicRegistration( TOPIC_UNREGISTER, (a), (b) )
|
||||
#define ClearAllDebugTopics( ) DbgClearAllTopics( )
|
||||
|
||||
#define ErrorMsg(a) _DebugMessage( (a), __LINE__, __FILE__)
|
||||
|
||||
#define RegisterJA2DebugTopic(a, b) DbgTopicRegistration( TOPIC_REGISTER, (a), (b) )
|
||||
#define RegisterDebugTopic(a, b) ((void *)0)
|
||||
#define DebugMsg(a, b, c) DbgMessageReal( (a), TOPIC_MESSAGE, (b), (c) )
|
||||
|
||||
// public interface to debug methods:
|
||||
extern void DbgMessageReal(unsigned uiTopicId, unsigned uiCommand, unsigned uiDebugLevel, const char *strMessage);
|
||||
|
||||
extern bool DbgSetDebugLevel(unsigned TopicId, unsigned uiDebugLevel);
|
||||
extern void DbgTopicRegistration( unsigned ubCmd, const unsigned usTopicID, const char *zMessage );
|
||||
extern void DbgClearAllTopics( void );
|
||||
extern void _DebugMessage(const char *pSourceFile, unsigned uiLineNum, const char *pString);
|
||||
|
||||
//*******************************************************************************************
|
||||
|
||||
#else
|
||||
|
||||
//*******************************************************************************************
|
||||
// Release Mode
|
||||
//*******************************************************************************************
|
||||
#define DebugBreakpoint() ((void *)0)
|
||||
|
||||
#define RegisterDebugTopic(a, b) ((void *)0)
|
||||
#define UnRegisterDebugTopic(a, b) ((void *)0)
|
||||
#define ClearAllDebugTopics( ) ((void *)0)
|
||||
|
||||
#define FastDebugMsg(a) ((void *)0)
|
||||
#define ErrorMsg(a) ((void *)0)
|
||||
|
||||
#define DbgTopicRegistration(a, b, c); ((void *)0)
|
||||
#define DbgMessage(a, b, c) ((void *)0)
|
||||
|
||||
#define RegisterJA2DebugTopic(a, b) ((void *)0)
|
||||
#define DebugMsg(a, b, c) ((void *)0)
|
||||
|
||||
//*******************************************************************************************
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUG_ATTACKBUSY
|
||||
#define DebugAttackBusy(x) OutputDebugString( x)
|
||||
#else
|
||||
#define DebugAttackBusy(x)
|
||||
#endif
|
||||
|
||||
#define SGP_CALLER_LOCATION , int line=0, const char* function=NULL, const char* file=NULL
|
||||
#define SGP_CALLER_LOCATION_IMPL , int line, const char* function, const char* file
|
||||
#define SGP_GET_CALLER_LOCATION , __LINE__, __FUNCTION__, __FILE__
|
||||
#define SGP_SET_CALLER_LOCATION , line, function, file
|
||||
|
||||
#include <stdexcept>
|
||||
#include <list>
|
||||
|
||||
namespace vfs { class Exception; }
|
||||
namespace sgp
|
||||
{
|
||||
class WString
|
||||
{
|
||||
public:
|
||||
WString(std::string const& s){
|
||||
convert_string(s,str);
|
||||
}
|
||||
WString(const char* s) {
|
||||
convert_string(s,str);
|
||||
}
|
||||
WString(std::wstring const& s) : str(s) {
|
||||
}
|
||||
WString(const wchar_t* s) : str(s) {
|
||||
}
|
||||
public:
|
||||
std::wstring str;
|
||||
};
|
||||
|
||||
class Exception : public std::exception
|
||||
{
|
||||
public:
|
||||
Exception(WString const& msg SGP_CALLER_LOCATION);
|
||||
|
||||
// default exception
|
||||
Exception(WString const& msg, Exception& ex SGP_CALLER_LOCATION);
|
||||
|
||||
// compatibility with std::exception
|
||||
Exception(WString const& msg, std::exception& ex SGP_CALLER_LOCATION);
|
||||
|
||||
// compatibility with vfs::Exception
|
||||
Exception(WString const& msg, vfs::Exception& ex SGP_CALLER_LOCATION);
|
||||
|
||||
virtual const char* what() const throw();
|
||||
|
||||
struct Excp
|
||||
{
|
||||
int line;
|
||||
std::string function, file;
|
||||
std::wstring msg;
|
||||
};
|
||||
std::list<Excp> _msg;
|
||||
};
|
||||
}
|
||||
|
||||
#define SGP_THROW(msg) throw sgp::Exception( (msg) SGP_GET_CALLER_LOCATION )
|
||||
#define SGP_RETHROW(msg, ex) throw sgp::Exception( (msg), (ex) SGP_GET_CALLER_LOCATION )
|
||||
#define SGP_TRYCATCH_RETHROW(expr, msg) try { (expr); } catch(std::exception &ex) { throw sgp::Exception((msg), (ex) SGP_GET_CALLER_LOCATION); }
|
||||
|
||||
#define SGP_THROW_IFFALSE(cond, msg) if((cond) == false) { throw sgp::Exception(msg SGP_GET_CALLER_LOCATION); }
|
||||
#define SGP_THROW_IFNULL(ptr, msg) if((ptr) == NULL) { throw sgp::Exception(msg SGP_GET_CALLER_LOCATION); }
|
||||
|
||||
#include <vfs/Core/vfs_debug.h>
|
||||
|
||||
void _ExceptionMessage( sgp::Exception &ex );
|
||||
void _ExceptionMessage( vfs::Exception &ex );
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif
|
||||
+659
@@ -0,0 +1,659 @@
|
||||
|
||||
// JA2
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Filename : debug.c
|
||||
//
|
||||
// Purpose : debug manager implementation
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// xxxxx96:LH - Creation
|
||||
// xxnov96:HJH - made it work
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
// Because we're in a library, define SGP_DEBUG here - the client may not always
|
||||
// use the code to write text, because the header switches on the define
|
||||
//#define SGP_DEBUG
|
||||
//#undef _DEBUG
|
||||
|
||||
// WDS: Note: To compile with VS2005 in release mode you might have to not define SGP_DEBUG and
|
||||
// undefine _DEBUG or you get linker errors.
|
||||
|
||||
|
||||
#include "types.h"
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "debug.h"
|
||||
|
||||
//Kris addition
|
||||
#include "screenids.h"
|
||||
#include "Sys Globals.h"
|
||||
#include "jascreens.h"
|
||||
#include "gameloop.h"
|
||||
#include "input.h"
|
||||
|
||||
// CJC added
|
||||
#ifndef _NO_DEBUG_TXT
|
||||
#include "fileman.h"
|
||||
#endif
|
||||
#include "GameSettings.h"
|
||||
#include "SaveLoadGame.h"
|
||||
#include "Font.h"
|
||||
#include "GameVersion.h"
|
||||
#include "Text.h"
|
||||
|
||||
#include "debug_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BOOLEAN gfRecordToFile = FALSE;
|
||||
BOOLEAN gfRecordToDebugger = TRUE;
|
||||
|
||||
// moved from header file: 24mar98:HJH
|
||||
UINT32 guiProfileStart, guiExecutions, guiProfileTime;
|
||||
INT32 giProfileCount;
|
||||
|
||||
// Had to move these outside the ifdef SGP_DEBUG below, because
|
||||
// they are required for the String() function, which is NOT a
|
||||
// debug-mode only function, it's used in release-mode as well! -- DB
|
||||
|
||||
CHAR8 gubAssertString[512];
|
||||
|
||||
#define MAX_MSG_LENGTH2 512
|
||||
CHAR8 gbTmpDebugString[8][MAX_MSG_LENGTH2];
|
||||
UINT8 gubStringIndex = 0;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SGP_DEBUG
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#define BUFSIZE 100
|
||||
#define TIMER_TIMEOUT 1000
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Variables
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
|
||||
UINT32 guiTimerID = 0;
|
||||
|
||||
bool gfDebugTopics[MAX_TOPICS_ALLOTED];
|
||||
|
||||
// remove debug .txt file
|
||||
void RemoveDebugText( void );
|
||||
|
||||
STRING512 debugLogFileName;
|
||||
FILE * debugLogFile = 0;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// DbgGetLogFileName
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// xxjun98:CJC ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
bool DbgGetLogFileName( STRING512 pcName )
|
||||
{
|
||||
// use the provided buffer to get the directory name, then tack on
|
||||
// "\debug.txt"
|
||||
#ifndef _NO_DEBUG_TXT
|
||||
if ( ! GetExecutableDirectory( pcName ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( strlen( pcName ) > (512 - strlen( "\\debug.txt" ) - 1 ) )
|
||||
{
|
||||
// no room!
|
||||
return false;
|
||||
}
|
||||
|
||||
strcat( pcName, "\\debug.txt" );
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// DbgInitialize
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// xxnov96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
bool DbgInitialize()
|
||||
{
|
||||
DbgClearAllTopics();
|
||||
|
||||
gfRecordToFile = TRUE;
|
||||
gfRecordToDebugger = TRUE;
|
||||
gubAssertString[0] = '\0';
|
||||
|
||||
#ifndef _NO_DEBUG_TXT
|
||||
if (! DbgGetLogFileName( debugLogFileName ) ) {
|
||||
return false;
|
||||
}
|
||||
// clear debug text file out
|
||||
RemoveDebugText( );
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// DbgShutdown
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// xxnov96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
void DbgShutdown()
|
||||
{
|
||||
DbgMessageReal( -1, CLIENT_SHUTDOWN, 0, "SGP Going Down" );
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// DbgTopicRegistration
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// June 97: BR ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
void DbgTopicRegistration( unsigned ubCmd, const unsigned usTopicID, const char *zMessage )
|
||||
{
|
||||
if ( usTopicID == NULL )
|
||||
return;
|
||||
|
||||
AssertGE(ubCmd, TOPIC_REGISTER);
|
||||
AssertLE(ubCmd, TOPIC_UNREGISTER);
|
||||
|
||||
if( ubCmd == TOPIC_REGISTER )
|
||||
{
|
||||
gfDebugTopics[ usTopicID ] = true;
|
||||
DbgMessageReal(usTopicID, TOPIC_MESSAGE, DBG_LEVEL_0, zMessage );
|
||||
}
|
||||
else if( ubCmd == TOPIC_UNREGISTER )
|
||||
{
|
||||
if ( usTopicID >= MAX_TOPICS_ALLOTED )
|
||||
return;
|
||||
|
||||
DbgMessageReal( usTopicID, TOPIC_MESSAGE, DBG_LEVEL_0, zMessage );
|
||||
gfDebugTopics[ usTopicID ] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// Clear the debug txt file out to prevent it from getting huge
|
||||
//
|
||||
//
|
||||
// *************************************************************************
|
||||
|
||||
void RemoveDebugText()
|
||||
{
|
||||
DeleteFile( debugLogFileName );
|
||||
debugLogFile = 0;
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// DbgClearAllTopics
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// June 97: BR ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
void DbgClearAllTopics( void )
|
||||
{
|
||||
for( unsigned usIndex = 0; usIndex < MAX_TOPICS_ALLOTED; usIndex++)
|
||||
{
|
||||
gfDebugTopics[ usIndex ] = false;
|
||||
}
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// DbgMessageReal
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// xxnov96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
void DbgMessageReal(unsigned uiTopicId, unsigned uiCommand, unsigned uiDebugLevel, const char* strMessage)
|
||||
{
|
||||
#ifndef _NO_DEBUG_TXT
|
||||
static FILE *OutFile = 0;
|
||||
#endif
|
||||
// Check for a registered topic ID
|
||||
if ( (uiTopicId < MAX_TOPICS_ALLOTED) && (gfDebugTopics[uiTopicId]) )
|
||||
{
|
||||
OutputDebugString ( strMessage );
|
||||
OutputDebugString ( "\n" );
|
||||
|
||||
//add _NO_DEBUG_TXT to your SGP preprocessor definitions to avoid this f**king huge file from
|
||||
//slowly growing behind the scenes!!!!
|
||||
#ifndef _NO_DEBUG_TXT
|
||||
if (!debugLogFile)
|
||||
debugLogFile = fopen(debugLogFileName, "a+t");
|
||||
if (debugLogFile) {
|
||||
fprintf(debugLogFile, "%s\n", strMessage);
|
||||
fflush( debugLogFile );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// DbgSetDebugLevel
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 11nov96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
bool DbgSetDebugLevel(unsigned uiTopicId, unsigned uiDebugLevel)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void _DebugRecordToFile(BOOLEAN gfState)
|
||||
{
|
||||
gfRecordToFile = gfState;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void _DebugRecordToDebugger(BOOLEAN gfState)
|
||||
{
|
||||
gfRecordToDebugger = gfState;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Wiz8 compatible debug messaging
|
||||
|
||||
void _DebugMessage(const char *pString, unsigned uiLineNum, const char *pSourceFile)
|
||||
{
|
||||
CHAR8 ubOutputString[512];
|
||||
|
||||
//
|
||||
// Build the output string
|
||||
//
|
||||
|
||||
sprintf( ubOutputString, "{ %ld } %s [Line %d in %s]\n", GetTickCount(), pString, uiLineNum, pSourceFile );
|
||||
|
||||
//
|
||||
// Output to debugger
|
||||
//
|
||||
|
||||
if (gfRecordToDebugger)
|
||||
{
|
||||
OutputDebugString( (LPCSTR) ubOutputString );
|
||||
}
|
||||
|
||||
//
|
||||
// Record to file if required
|
||||
//
|
||||
|
||||
#ifndef _NO_DEBUG_TXT
|
||||
if (gfRecordToFile)
|
||||
{
|
||||
if (!debugLogFile)
|
||||
debugLogFile = fopen( debugLogFileName, "a+t" );
|
||||
if (debugLogFile) {
|
||||
fputs( ubOutputString, debugLogFile );
|
||||
fflush( debugLogFile );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
bool DbgInitialize() { return true; };
|
||||
void DbgShutdown() {};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef FORCE_ASSERTS_ON
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern HVOBJECT FontObjs[25];
|
||||
|
||||
#include <vfs/Core/vfs_os_functions.h>
|
||||
void _FailMessage(const char* message, unsigned lineNum, const char * functionName, const char* sourceFileName)
|
||||
{
|
||||
// This function shouldn't recurse
|
||||
static bool alreadyInThisFunction = false;
|
||||
if (alreadyInThisFunction)
|
||||
return;
|
||||
alreadyInThisFunction = true;
|
||||
|
||||
sgp::dumpStackTrace(message);
|
||||
|
||||
mprintf( 10, 10, L"%s: %s %S %s", pMessageStrings[ MSG_VERSION ], zProductLabel, czVersionString, zBuildInformation );
|
||||
|
||||
std::stringstream basicInformation;
|
||||
basicInformation << "Assertion Failure [Line " << lineNum;
|
||||
if (functionName) {
|
||||
basicInformation << " in function " << functionName;
|
||||
}
|
||||
basicInformation << " in file " << sourceFileName << "]";
|
||||
|
||||
std::stringstream outputString;
|
||||
outputString << "{ " << GetTickCount() << " } " << basicInformation.str();
|
||||
|
||||
//Build the output strings
|
||||
if( message )
|
||||
sprintf( gubAssertString, message );
|
||||
else
|
||||
sprintf( gubAssertString, "" );
|
||||
|
||||
//Output to debugger
|
||||
if (gfRecordToDebugger)
|
||||
OutputDebugString( outputString.str().c_str() );
|
||||
|
||||
DbgMessage( TOPIC_GAME, DBG_LEVEL_1, outputString.str().c_str());
|
||||
|
||||
//This will actually bring up a screen that prints out the assert message
|
||||
//until the user hits esc or alt-x.
|
||||
// WDS - Automatically try to save when an assertion failure occurs
|
||||
if (gGameExternalOptions.autoSaveOnAssertionFailure &&
|
||||
!alreadySaving) {
|
||||
sprintf( gubErrorText, "%s. Attempting to do a debug save as SaveGame%d.sav (this may fail)", basicInformation.str().c_str(), SAVE__ASSERTION_FAILURE );
|
||||
} else {
|
||||
sprintf( gubErrorText, "%s", basicInformation.str().c_str());
|
||||
}
|
||||
SetPendingNewScreen( ERROR_SCREEN );
|
||||
SetCurrentScreen( ERROR_SCREEN );
|
||||
|
||||
// WDS - Automatically try to save when an assertion failure occurs
|
||||
if (gGameExternalOptions.autoSaveOnAssertionFailure &&
|
||||
!alreadySaving) {
|
||||
SaveGame( SAVE__ASSERTION_FAILURE, L"Assertion Failure Auto Save" );
|
||||
}
|
||||
|
||||
MSG Message;
|
||||
while (gfProgramIsRunning)
|
||||
{
|
||||
if (PeekMessage(&Message, NULL, 0, 0, PM_NOREMOVE))
|
||||
{ // We have a message on the WIN95 queue, let's get it
|
||||
if (!GetMessage(&Message, NULL, 0, 0))
|
||||
{ // It's quitting time
|
||||
continue;
|
||||
}
|
||||
// Ok, now that we have the message, let's handle it
|
||||
TranslateMessage(&Message);
|
||||
DispatchMessage(&Message);
|
||||
}
|
||||
else
|
||||
{ // Windows hasn't processed any messages, therefore we handle the rest
|
||||
GameLoop();
|
||||
gfSGPInputReceived = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
alreadyInThisFunction = false;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// This is NOT a _DEBUG only function! It is also needed in
|
||||
// release mode builds. -- DB
|
||||
STR8 String(const STR8 String, ...)
|
||||
{
|
||||
|
||||
va_list ArgPtr;
|
||||
UINT8 usIndex;
|
||||
|
||||
// Record string index. This index is used since we live in a multitasking environment.
|
||||
// It is still not bulletproof, but it's better than a single string
|
||||
usIndex = gubStringIndex++;
|
||||
if (gubStringIndex == 8)
|
||||
{ // reset string pointer
|
||||
gubStringIndex = 0;
|
||||
}
|
||||
|
||||
va_start(ArgPtr, String);
|
||||
vsprintf( gbTmpDebugString[usIndex], String, ArgPtr);
|
||||
va_end(ArgPtr);
|
||||
|
||||
return gbTmpDebugString[usIndex];
|
||||
|
||||
}
|
||||
|
||||
void _ExceptionMessage( sgp::Exception &ex )
|
||||
{
|
||||
g_ExceptionList.clear();
|
||||
std::list<sgp::Exception::Excp>::iterator it = ex._msg.begin();
|
||||
for(; it!=ex._msg.end(); ++it)
|
||||
{
|
||||
SExceptionData exd;
|
||||
exd.message = (*it).msg;
|
||||
exd.function = (*it).function;
|
||||
exd.file = (*it).file;
|
||||
exd.line = (*it).line;
|
||||
g_ExceptionList.push_back(exd);
|
||||
}
|
||||
_FailMessage("",0,"");
|
||||
}
|
||||
|
||||
void _ExceptionMessage( vfs::Exception &ex )
|
||||
{
|
||||
g_ExceptionList.clear();
|
||||
vfs::Exception::CALLSTACK::iterator it = ex.m_CallStack.begin();
|
||||
for(; it!=ex.m_CallStack.end(); ++it)
|
||||
{
|
||||
SExceptionData exd;
|
||||
exd.message = (*it).message;
|
||||
exd.function = (*it).function;
|
||||
exd.file = (*it).file;
|
||||
exd.line = (*it).line;
|
||||
g_ExceptionList.push_back(exd);
|
||||
}
|
||||
_FailMessage("",0,"");
|
||||
}
|
||||
|
||||
#include <vfs/Core/vfs_string.h>
|
||||
#include <vfs/Core/vfs_debug.h>
|
||||
|
||||
sgp::Exception::Exception(sgp::WString const& msg SGP_CALLER_LOCATION_IMPL)
|
||||
{
|
||||
Excp excp;
|
||||
excp.line = line;
|
||||
excp.file = file ? file : "";
|
||||
excp.function = function ? function : "";
|
||||
excp.msg = msg.str;
|
||||
|
||||
_msg.push_back(excp);
|
||||
}
|
||||
|
||||
sgp::Exception::Exception(sgp::WString const& msg, Exception& ex SGP_CALLER_LOCATION_IMPL)
|
||||
{
|
||||
_msg.insert(_msg.end(), ex._msg.begin(), ex._msg.end());
|
||||
|
||||
Excp excp;
|
||||
excp.line = line;
|
||||
excp.file = file ? file : "";
|
||||
excp.function = function ? function : "";
|
||||
excp.msg = msg.str;
|
||||
|
||||
_msg.push_back(excp);
|
||||
}
|
||||
|
||||
sgp::Exception::Exception(sgp::WString const& msg, vfs::Exception& ex SGP_CALLER_LOCATION_IMPL)
|
||||
{
|
||||
vfs::Exception::CALLSTACK::iterator it = ex.m_CallStack.begin();
|
||||
for(; it != ex.m_CallStack.end(); ++it)
|
||||
{
|
||||
Excp excp;
|
||||
excp.file = it->file.utf8();
|
||||
excp.function = it->function.utf8();
|
||||
excp.line = it->line;
|
||||
excp.msg = it->message.c_wcs();
|
||||
_msg.push_back(excp);
|
||||
}
|
||||
|
||||
Excp excp;
|
||||
excp.line = line;
|
||||
excp.file = file ? file : "";
|
||||
excp.function = function ? function : "";
|
||||
excp.msg = msg.str;
|
||||
|
||||
_msg.push_back(excp);
|
||||
}
|
||||
|
||||
sgp::Exception::Exception(WString const& msg, std::exception& ex SGP_CALLER_LOCATION_IMPL)
|
||||
{
|
||||
if(dynamic_cast<sgp::Exception*>(&ex))
|
||||
{
|
||||
sgp::Exception& sgp_ex = *static_cast<sgp::Exception*>(&ex);
|
||||
_msg.insert(_msg.end(), sgp_ex._msg.begin(), sgp_ex._msg.end());
|
||||
}
|
||||
else if(dynamic_cast<vfs::Exception*>(&ex))
|
||||
{
|
||||
vfs::Exception& vfs_ex = *static_cast<vfs::Exception*>(&ex);
|
||||
vfs::Exception::CALLSTACK::iterator it = vfs_ex.m_CallStack.begin();
|
||||
for(; it != vfs_ex.m_CallStack.end(); ++it)
|
||||
{
|
||||
Excp excp;
|
||||
excp.file = it->file.utf8();
|
||||
excp.function = it->function.utf8();
|
||||
excp.line = it->line;
|
||||
excp.msg = it->message.c_wcs();
|
||||
_msg.push_back(excp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Excp excp;
|
||||
excp.file = "";
|
||||
excp.function = "";
|
||||
excp.line = -1;
|
||||
convert_string(ex.what(), excp.msg);
|
||||
_msg.push_back(excp);
|
||||
}
|
||||
|
||||
Excp excp;
|
||||
excp.line = line;
|
||||
excp.file = file ? file : "";
|
||||
excp.function = function ? function : "";
|
||||
excp.msg = msg.str;
|
||||
|
||||
_msg.push_back(excp);
|
||||
}
|
||||
|
||||
|
||||
#if defined(_WIN32) || defined(WIN64)
|
||||
# define ENDL "\r\n"
|
||||
#else
|
||||
# define ENDL "\n"
|
||||
#endif
|
||||
|
||||
static std::string gs_exception_string;
|
||||
|
||||
const char* sgp::Exception::what() const
|
||||
{
|
||||
// cannot return pointer local variable
|
||||
std::stringstream ss;
|
||||
ss.str("");
|
||||
ss.clear();
|
||||
|
||||
std::list<Excp>::const_reverse_iterator rit = _msg.rbegin();
|
||||
for(; rit != _msg.rend(); ++rit)
|
||||
{
|
||||
std::string msg;
|
||||
convert_string(rit->msg, msg);
|
||||
//wss << "========== " << rit->time << " =========="ENDL;
|
||||
ss << "File : " << rit->file << ENDL;
|
||||
ss << "Line : " << rit->line << ENDL;
|
||||
ss << "Location : " << rit->function << ENDL;
|
||||
ss << " " << msg << ENDL;
|
||||
}
|
||||
|
||||
gs_exception_string = ss.str();
|
||||
return gs_exception_string.c_str();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,535 @@
|
||||
#include "DirectX Common.h"
|
||||
#include "DirectDraw Calls.h"
|
||||
|
||||
#include <ddraw.h>
|
||||
#include "debug.h"
|
||||
#include "vobject_blitters.h"
|
||||
|
||||
// DirectDrawSurface2 Calls
|
||||
void
|
||||
DDCreateSurface ( LPDIRECTDRAW2 pExistingDirectDraw,
|
||||
DDSURFACEDESC *pNewSurfaceDesc,
|
||||
LPDIRECTDRAWSURFACE *ppNewSurface1,
|
||||
LPDIRECTDRAWSURFACE2 *ppNewSurface2 )
|
||||
{
|
||||
Assert ( pExistingDirectDraw != NULL );
|
||||
Assert ( pNewSurfaceDesc != NULL );
|
||||
Assert ( ppNewSurface1 != NULL );
|
||||
Assert ( ppNewSurface2 != NULL );
|
||||
|
||||
// create the directdraw surface
|
||||
ATTEMPT ( IDirectDraw2_CreateSurface ( pExistingDirectDraw,
|
||||
pNewSurfaceDesc, ppNewSurface1, NULL ) );
|
||||
|
||||
//get the direct draw surface 2 interface
|
||||
ATTEMPT ( IDirectDrawSurface_QueryInterface ( *ppNewSurface1, /*&*/IID_IDirectDrawSurface2, (LPVOID*) ppNewSurface2 ) ); // (jonathanl)
|
||||
}
|
||||
|
||||
|
||||
// DirectDrawSurface2 Calls
|
||||
void
|
||||
DDCreateSurfaceInMemory ( LPDIRECTDRAW2 pExistingDirectDraw,
|
||||
DDSURFACEDESC *pNewSurfaceDesc,
|
||||
BOOLEAN fVideoMemory, LPDIRECTDRAWSURFACE *ppNewSurface1,
|
||||
LPDIRECTDRAWSURFACE2 *ppNewSurface2 )
|
||||
{
|
||||
DDSURFACEDESC DDSurfaceDesc;
|
||||
BOOLEAN fDestination;
|
||||
|
||||
Assert ( pExistingDirectDraw != NULL );
|
||||
Assert ( pNewSurfaceDesc != NULL );
|
||||
Assert ( ppNewSurface1 != NULL );
|
||||
Assert ( ppNewSurface2 != NULL );
|
||||
|
||||
// copy to a local so we don't change the input parameter
|
||||
memcpy ( &DDSurfaceDesc, pNewSurfaceDesc, sizeof ( DDSURFACEDESC ) );
|
||||
|
||||
// must have caps set since we are adding to the ddsCaps element
|
||||
DDSurfaceDesc.dwFlags |= DDSD_CAPS;
|
||||
|
||||
// If this is a hardware D3D driver, the Z-Buffer MUST end up in video
|
||||
// memory. Otherwise, it MUST end up in system memory.
|
||||
if ( fVideoMemory )
|
||||
DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
|
||||
else
|
||||
DDSurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
|
||||
|
||||
// create the surface
|
||||
DDCreateSurface ( pExistingDirectDraw, &DDSurfaceDesc, ppNewSurface1, ppNewSurface2 );
|
||||
|
||||
// get surface information
|
||||
DDGetSurfaceDescription ( *ppNewSurface2, &DDSurfaceDesc );
|
||||
|
||||
// was the surface created in video memory?
|
||||
fDestination = ( DDSurfaceDesc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY ) ?
|
||||
TRUE : FALSE;
|
||||
|
||||
// did we create the surface in the right memory area?
|
||||
if ( fDestination != fVideoMemory )
|
||||
{
|
||||
// nope we couldn't do it right so release the newly created surface
|
||||
// and pass back a NULL pointer to the user
|
||||
DDReleaseSurface ( ppNewSurface1, ppNewSurface2 );
|
||||
}
|
||||
}
|
||||
|
||||
// Lock, unlock calls
|
||||
void DDLockSurface ( LPDIRECTDRAWSURFACE2 pSurface, LPRECT pDestRect, LPDDSURFACEDESC pSurfaceDesc, UINT32 uiFlags, HANDLE hEvent )
|
||||
{
|
||||
HRESULT ReturnCode;
|
||||
|
||||
Assert( pSurface != NULL );
|
||||
Assert( pSurfaceDesc != NULL );
|
||||
|
||||
ZEROMEM ( *pSurfaceDesc );
|
||||
pSurfaceDesc->dwSize = sizeof(DDSURFACEDESC);
|
||||
|
||||
do
|
||||
{
|
||||
ReturnCode = IDirectDrawSurface2_Lock( pSurface, pDestRect, pSurfaceDesc, uiFlags, hEvent);
|
||||
|
||||
} while( ReturnCode == DDERR_WASSTILLDRAWING );
|
||||
|
||||
ATTEMPT( ReturnCode );
|
||||
|
||||
}
|
||||
|
||||
void DDUnlockSurface( LPDIRECTDRAWSURFACE2 pSurface, PTR pSurfaceData )
|
||||
{
|
||||
Assert( pSurface != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_Unlock( pSurface, pSurfaceData ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DDGetSurfaceDescription ( LPDIRECTDRAWSURFACE2 pSurface, DDSURFACEDESC *pSurfaceDesc )
|
||||
{
|
||||
Assert ( pSurface != NULL );
|
||||
Assert ( pSurfaceDesc != NULL );
|
||||
|
||||
ZEROMEM ( *pSurfaceDesc );
|
||||
pSurfaceDesc->dwSize = sizeof ( DDSURFACEDESC );
|
||||
|
||||
ATTEMPT ( IDirectDrawSurface2_GetSurfaceDesc ( pSurface, pSurfaceDesc ) );
|
||||
}
|
||||
|
||||
void DDGetSurfaceCaps ( LPDIRECTDRAWSURFACE2 pSurface, DDSCAPS *pSurfaceCaps )
|
||||
{
|
||||
Assert( pSurface != NULL );
|
||||
Assert( pSurfaceCaps != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_GetCaps( pSurface, pSurfaceCaps ) );
|
||||
|
||||
}
|
||||
|
||||
void DDCreateRasterSurface ( LPDIRECTDRAW2 pDirectDraw, INT32 iWidth, INT32 iHeight,
|
||||
BOOLEAN fVideoMemory,
|
||||
LPDIRECTDRAWSURFACE *ppRasterSurface1,
|
||||
LPDIRECTDRAWSURFACE2 *ppRasterSurface2 )
|
||||
{
|
||||
DDSURFACEDESC DDSurfaceDesc;
|
||||
|
||||
// validate used portions of the structure
|
||||
Assert ( pDirectDraw != NULL );
|
||||
Assert ( iWidth != 0 );
|
||||
Assert ( iHeight != 0 );
|
||||
Assert ( ppRasterSurface1 != NULL );
|
||||
Assert ( ppRasterSurface2 != NULL );
|
||||
|
||||
// create the raster surface
|
||||
ZEROMEM ( DDSurfaceDesc );
|
||||
DDSurfaceDesc.dwSize = sizeof ( DDSurfaceDesc );
|
||||
DDSurfaceDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
|
||||
DDSurfaceDesc.dwWidth = iWidth;
|
||||
DDSurfaceDesc.dwHeight = iHeight;
|
||||
DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN;
|
||||
DDCreateSurfaceInMemory ( pDirectDraw, &DDSurfaceDesc, fVideoMemory, ppRasterSurface1, ppRasterSurface2 );
|
||||
}
|
||||
|
||||
void DDCreateZBufferSurface ( LPDIRECTDRAW2 pDirectDraw, INT32 iWidth, INT32 iHeight,
|
||||
BOOLEAN fVideoMemory,
|
||||
LPDIRECTDRAWSURFACE *ppZBufferSurface1,
|
||||
LPDIRECTDRAWSURFACE2 *ppZBufferSurface2 )
|
||||
{
|
||||
DDSURFACEDESC DDSurfaceDesc;
|
||||
|
||||
// validate used portions of the structure
|
||||
Assert ( pDirectDraw != NULL );
|
||||
Assert ( iWidth != 0 );
|
||||
Assert ( iHeight != 0 );
|
||||
Assert ( ppZBufferSurface1 != NULL );
|
||||
Assert ( ppZBufferSurface2 != NULL );
|
||||
|
||||
// create the z buffer
|
||||
ZEROMEM ( DDSurfaceDesc );
|
||||
DDSurfaceDesc.dwSize = sizeof ( DDSurfaceDesc );
|
||||
DDSurfaceDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_ZBUFFERBITDEPTH;
|
||||
DDSurfaceDesc.dwWidth = iWidth;
|
||||
DDSurfaceDesc.dwHeight = iHeight;
|
||||
DDSurfaceDesc.dwZBufferBitDepth = 16;
|
||||
DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
|
||||
DDCreateSurfaceInMemory ( pDirectDraw, &DDSurfaceDesc, fVideoMemory, ppZBufferSurface1, ppZBufferSurface2 );
|
||||
}
|
||||
|
||||
void
|
||||
DDAddAttachedSurface ( LPDIRECTDRAWSURFACE2 pParentSurface,
|
||||
LPDIRECTDRAWSURFACE2 pAddChildSurface )
|
||||
{
|
||||
Assert ( pParentSurface != NULL );
|
||||
Assert ( pAddChildSurface != NULL );
|
||||
|
||||
// attach the child to the parent surface
|
||||
ATTEMPT ( IDirectDrawSurface2_AddAttachedSurface ( pParentSurface,
|
||||
pAddChildSurface ) );
|
||||
}
|
||||
|
||||
void
|
||||
DDDeleteAttachedSurface ( LPDIRECTDRAWSURFACE2 pParentSurface,
|
||||
LPDIRECTDRAWSURFACE2 pDeleteChildSurface )
|
||||
{
|
||||
Assert ( pParentSurface != NULL );
|
||||
Assert ( pDeleteChildSurface != NULL );
|
||||
|
||||
// seperate the z buffer surface from the raster surface
|
||||
ATTEMPT ( IDirectDrawSurface2_DeleteAttachedSurface ( pParentSurface,
|
||||
0, pDeleteChildSurface ) );
|
||||
}
|
||||
|
||||
void
|
||||
DDReleaseSurface ( LPDIRECTDRAWSURFACE *ppOldSurface1, LPDIRECTDRAWSURFACE2 *ppOldSurface2 )
|
||||
{
|
||||
Assert ( ppOldSurface1 != NULL );
|
||||
Assert ( ppOldSurface2 != NULL );
|
||||
Assert ( *ppOldSurface1 != NULL );
|
||||
Assert ( *ppOldSurface2 != NULL );
|
||||
|
||||
ATTEMPT ( IDirectDrawSurface2_Release ( *ppOldSurface2 ) );
|
||||
ATTEMPT ( IDirectDrawSurface_Release ( *ppOldSurface1 ) );
|
||||
|
||||
*ppOldSurface1 = NULL;
|
||||
*ppOldSurface2 = NULL;
|
||||
}
|
||||
|
||||
void DDRestoreSurface( LPDIRECTDRAWSURFACE2 pSurface )
|
||||
{
|
||||
Assert( pSurface != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_Restore( pSurface ) );
|
||||
}
|
||||
|
||||
|
||||
void DDBltFastSurface( LPDIRECTDRAWSURFACE2 pDestSurface, UINT32 uiX, UINT32 uiY, LPDIRECTDRAWSURFACE2 pSrcSurface,
|
||||
LPRECT pSrcRect, UINT32 uiTrans)
|
||||
{
|
||||
HRESULT ReturnCode;
|
||||
|
||||
Assert( pDestSurface != NULL );
|
||||
Assert( pSrcSurface != NULL );
|
||||
|
||||
do
|
||||
{
|
||||
ReturnCode = IDirectDrawSurface2_SGPBltFast( pDestSurface, uiX, uiY, pSrcSurface, pSrcRect, uiTrans );
|
||||
|
||||
} while( ReturnCode == DDERR_WASSTILLDRAWING );
|
||||
}
|
||||
|
||||
|
||||
void DDBltSurface( LPDIRECTDRAWSURFACE2 pDestSurface, LPRECT pDestRect, LPDIRECTDRAWSURFACE2 pSrcSurface,
|
||||
LPRECT pSrcRect, UINT32 uiFlags, LPDDBLTFX pDDBltFx )
|
||||
{
|
||||
|
||||
HRESULT ReturnCode;
|
||||
|
||||
Assert( pDestSurface != NULL );
|
||||
|
||||
do
|
||||
{
|
||||
ReturnCode = IDirectDrawSurface2_SGPBlt( pDestSurface, pDestRect, pSrcSurface, pSrcRect, uiFlags, pDDBltFx );
|
||||
|
||||
} while( ReturnCode == DDERR_WASSTILLDRAWING );
|
||||
|
||||
ATTEMPT( ReturnCode );
|
||||
}
|
||||
|
||||
|
||||
void DDCreatePalette( LPDIRECTDRAW2 pDirectDraw, UINT32 uiFlags, LPPALETTEENTRY pColorTable, LPDIRECTDRAWPALETTE FAR *ppDDPalette,
|
||||
IUnknown FAR * pUnkOuter)
|
||||
{
|
||||
|
||||
Assert( pDirectDraw != NULL );
|
||||
|
||||
ATTEMPT( IDirectDraw2_CreatePalette( pDirectDraw, uiFlags, pColorTable, ppDDPalette, pUnkOuter ) );
|
||||
|
||||
}
|
||||
|
||||
void DDSetSurfacePalette( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWPALETTE pDDPalette )
|
||||
{
|
||||
Assert( pDDPalette != NULL );
|
||||
Assert( pSurface != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_SetPalette( pSurface, pDDPalette ) );
|
||||
|
||||
}
|
||||
|
||||
void DDGetSurfacePalette( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWPALETTE *ppDDPalette )
|
||||
{
|
||||
Assert( ppDDPalette != NULL );
|
||||
Assert( pSurface != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_GetPalette( pSurface, ppDDPalette ) );
|
||||
|
||||
}
|
||||
|
||||
void DDSetPaletteEntries( LPDIRECTDRAWPALETTE pPalette, UINT32 uiFlags, UINT32 uiStartingEntry,
|
||||
UINT32 uiCount, LPPALETTEENTRY pEntries )
|
||||
{
|
||||
Assert( pPalette != NULL );
|
||||
Assert( pEntries != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawPalette_SetEntries( pPalette, uiFlags, uiStartingEntry, uiCount, pEntries ) );
|
||||
|
||||
}
|
||||
|
||||
void DDGetPaletteEntries( LPDIRECTDRAWPALETTE pPalette, UINT32 uiFlags, UINT32 uiBase,
|
||||
UINT32 uiNumEntries, LPPALETTEENTRY pEntries )
|
||||
{
|
||||
Assert( pPalette != NULL );
|
||||
Assert( pEntries != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawPalette_GetEntries( pPalette, uiFlags, uiBase, uiNumEntries, pEntries ) );
|
||||
|
||||
}
|
||||
|
||||
void DDReleasePalette( LPDIRECTDRAWPALETTE pPalette )
|
||||
{
|
||||
Assert( pPalette != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawPalette_Release( pPalette ) );
|
||||
}
|
||||
|
||||
void DDGetDC( LPDIRECTDRAWSURFACE2 pSurface, HDC *phDC )
|
||||
{
|
||||
|
||||
Assert( pSurface != NULL );
|
||||
Assert( phDC != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_GetDC( pSurface, phDC ) );
|
||||
|
||||
}
|
||||
|
||||
void DDReleaseDC( LPDIRECTDRAWSURFACE2 pSurface, HDC hDC )
|
||||
{
|
||||
|
||||
Assert( pSurface != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_ReleaseDC( pSurface, hDC ) );
|
||||
|
||||
}
|
||||
|
||||
void DDSetSurfaceColorKey( LPDIRECTDRAWSURFACE2 pSurface, UINT32 uiFlags, LPDDCOLORKEY pDDColorKey )
|
||||
{
|
||||
Assert( pSurface != NULL );
|
||||
Assert( pDDColorKey != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_SetColorKey( pSurface, uiFlags, pDDColorKey ) );
|
||||
|
||||
}
|
||||
|
||||
void DDGetDDInterface( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAW *ppDirectDraw )
|
||||
{
|
||||
Assert( pSurface != NULL );
|
||||
Assert( ppDirectDraw != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_GetDDInterface( pSurface, (LPVOID *)ppDirectDraw ) );
|
||||
}
|
||||
|
||||
// Clipper FUnctions
|
||||
void DDCreateClipper( LPDIRECTDRAW2 pDirectDraw, UINT32 fFlags, LPDIRECTDRAWCLIPPER *pDDClipper )
|
||||
{
|
||||
Assert( pDirectDraw != NULL );
|
||||
Assert( pDDClipper != NULL );
|
||||
|
||||
ATTEMPT( IDirectDraw2_CreateClipper( pDirectDraw, 0, pDDClipper, NULL ) );
|
||||
|
||||
}
|
||||
|
||||
void DDSetClipper( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWCLIPPER pDDClipper )
|
||||
{
|
||||
Assert( pSurface != NULL );
|
||||
Assert( pDDClipper != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawSurface2_SetClipper( pSurface, pDDClipper ) );
|
||||
|
||||
}
|
||||
|
||||
void DDReleaseClipper( LPDIRECTDRAWCLIPPER pDDClipper )
|
||||
{
|
||||
Assert( pDDClipper != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawClipper_Release( pDDClipper ) );
|
||||
}
|
||||
|
||||
void DDSetClipperList( LPDIRECTDRAWCLIPPER pDDClipper, LPRGNDATA pClipList, UINT32 uiFlags)
|
||||
{
|
||||
Assert( pDDClipper != NULL );
|
||||
Assert( pClipList != NULL );
|
||||
|
||||
ATTEMPT( IDirectDrawClipper_SetClipList( pDDClipper, pClipList, uiFlags ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT BltFastDDSurfaceUsingSoftware( LPDIRECTDRAWSURFACE2 pDestSurface, INT32 uiX, INT32 uiY, LPDIRECTDRAWSURFACE2 pSrcSurface, LPRECT pSrcRect, UINT32 uiTrans )
|
||||
{
|
||||
DDSURFACEDESC SurfaceDescription;
|
||||
UINT32 uiDestPitchBYTES, uiSrcPitchBYTES;
|
||||
UINT8 *pDestBuf, *pSrcBuf;
|
||||
HRESULT ReturnCode;
|
||||
DDCOLORKEY ColorKey;
|
||||
UINT16 us16BPPColorKey;
|
||||
|
||||
|
||||
// Lock surfaces
|
||||
DDLockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL, &SurfaceDescription, 0, NULL);
|
||||
uiDestPitchBYTES = SurfaceDescription.lPitch;
|
||||
pDestBuf = (UINT8 *) SurfaceDescription.lpSurface;
|
||||
|
||||
|
||||
// Lock surfaces
|
||||
DDLockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL, &SurfaceDescription, 0, NULL);
|
||||
uiSrcPitchBYTES = SurfaceDescription.lPitch;
|
||||
pSrcBuf = (UINT8 *) SurfaceDescription.lpSurface;
|
||||
|
||||
if ( uiTrans == DDBLTFAST_NOCOLORKEY )
|
||||
{
|
||||
Blt16BPPTo16BPP( (UINT16 *)pDestBuf, uiDestPitchBYTES,
|
||||
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
|
||||
uiX , uiY,
|
||||
pSrcRect->left , pSrcRect->top,
|
||||
( pSrcRect->right - pSrcRect->left ),
|
||||
( pSrcRect->bottom - pSrcRect->top ) );
|
||||
}
|
||||
else if ( uiTrans == DDBLTFAST_SRCCOLORKEY )
|
||||
{
|
||||
// Get 16 bpp color key.....
|
||||
ReturnCode = IDirectDrawSurface2_GetColorKey( pSrcSurface, DDCKEY_SRCBLT, &ColorKey);
|
||||
|
||||
if (ReturnCode == DD_OK)
|
||||
{
|
||||
us16BPPColorKey = (UINT16)ColorKey.dwColorSpaceLowValue;
|
||||
|
||||
Blt16BPPTo16BPPTrans( (UINT16 *)pDestBuf, uiDestPitchBYTES,
|
||||
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
|
||||
uiX , uiY,
|
||||
pSrcRect->left , pSrcRect->top,
|
||||
( pSrcRect->right - pSrcRect->left ),
|
||||
( pSrcRect->bottom - pSrcRect->top ), us16BPPColorKey );
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not supported.....
|
||||
}
|
||||
|
||||
|
||||
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL );
|
||||
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL );
|
||||
|
||||
return( DD_OK );
|
||||
}
|
||||
|
||||
|
||||
HRESULT BltDDSurfaceUsingSoftware( LPDIRECTDRAWSURFACE2 pDestSurface, LPRECT pDestRect, LPDIRECTDRAWSURFACE2 pSrcSurface, LPRECT pSrcRect, UINT32 uiFlags, LPDDBLTFX pDDBltFx )
|
||||
{
|
||||
DDSURFACEDESC SurfaceDescription;
|
||||
UINT32 uiDestPitchBYTES, uiSrcPitchBYTES = 0;
|
||||
UINT8 *pDestBuf, *pSrcBuf = NULL;
|
||||
HRESULT ReturnCode;
|
||||
DDCOLORKEY ColorKey;
|
||||
UINT16 us16BPPColorKey;
|
||||
|
||||
|
||||
// Lock surfaces
|
||||
DDLockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL, &SurfaceDescription, 0, NULL);
|
||||
uiDestPitchBYTES = SurfaceDescription.lPitch;
|
||||
pDestBuf = (UINT8 *) SurfaceDescription.lpSurface;
|
||||
|
||||
|
||||
if ( pSrcSurface != NULL )
|
||||
{
|
||||
// Lock surfaces
|
||||
DDLockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL, &SurfaceDescription, 0, NULL);
|
||||
uiSrcPitchBYTES = SurfaceDescription.lPitch;
|
||||
pSrcBuf = (UINT8 *) SurfaceDescription.lpSurface;
|
||||
}
|
||||
|
||||
if ( pSrcRect != NULL &&
|
||||
( ( pSrcRect->right - pSrcRect->left ) != ( pDestRect->right - pDestRect->left ) ||
|
||||
( pSrcRect->bottom - pSrcRect->top ) != ( pDestRect->bottom - pDestRect->top ) ) )
|
||||
{
|
||||
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL );
|
||||
|
||||
if ( pSrcSurface != NULL )
|
||||
{
|
||||
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL );
|
||||
}
|
||||
|
||||
// Fall back to DD
|
||||
IDirectDrawSurface2_Blt( pDestSurface, pDestRect, pSrcSurface, pSrcRect, uiFlags, pDDBltFx );
|
||||
|
||||
return( DD_OK );
|
||||
}
|
||||
else if ( (pSrcRect != nullptr) && (uiFlags == DDBLT_WAIT) )
|
||||
{
|
||||
// Lock surfaces
|
||||
DDLockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL, &SurfaceDescription, 0, NULL);
|
||||
uiSrcPitchBYTES = SurfaceDescription.lPitch;
|
||||
pSrcBuf = (UINT8 *) SurfaceDescription.lpSurface;
|
||||
|
||||
Blt16BPPTo16BPP( (UINT16 *)pDestBuf, uiDestPitchBYTES,
|
||||
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
|
||||
pDestRect->left , pDestRect->top,
|
||||
pSrcRect->left , pSrcRect->top,
|
||||
( pSrcRect->right - pSrcRect->left ),
|
||||
( pSrcRect->bottom - pSrcRect->top ) );
|
||||
}
|
||||
else if ((pSrcSurface != nullptr) && (pSrcRect != nullptr) && (uiFlags & DDBLT_KEYSRC ))
|
||||
{
|
||||
// Get 16 bpp color key.....
|
||||
ReturnCode = IDirectDrawSurface2_GetColorKey( pSrcSurface, DDCKEY_SRCBLT, &ColorKey);
|
||||
|
||||
if (ReturnCode == DD_OK)
|
||||
{
|
||||
us16BPPColorKey = (UINT16)ColorKey.dwColorSpaceLowValue;
|
||||
|
||||
Blt16BPPTo16BPPTrans( (UINT16 *)pDestBuf, uiDestPitchBYTES,
|
||||
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
|
||||
pDestRect->left , pDestRect->top,
|
||||
pSrcRect->left , pSrcRect->top,
|
||||
( pSrcRect->right - pSrcRect->left ),
|
||||
( pSrcRect->bottom - pSrcRect->top ), us16BPPColorKey );
|
||||
|
||||
}
|
||||
}
|
||||
else if ( uiFlags & DDBLT_COLORFILL )
|
||||
{
|
||||
// do color fill here...
|
||||
FillRect16BPP( (UINT16 *)pDestBuf, uiDestPitchBYTES, pDestRect->left, pDestRect->top, pDestRect->right, pDestRect->bottom, (UINT16)pDDBltFx->dwFillColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not supported.....
|
||||
}
|
||||
|
||||
|
||||
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pDestSurface, NULL );
|
||||
|
||||
if ( pSrcSurface != NULL )
|
||||
{
|
||||
DDUnlockSurface( (LPDIRECTDRAWSURFACE2)pSrcSurface, NULL );
|
||||
}
|
||||
|
||||
return( DD_OK );
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#ifndef __DirectDraw_Calls_H__
|
||||
#define __DirectDraw_Calls_H__
|
||||
|
||||
#include "DirectX Common.h"
|
||||
#include <ddraw.h>
|
||||
#include "sgp.h"
|
||||
|
||||
// Direct Draw Functions
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Surface Functions
|
||||
|
||||
void DDCreateSurface ( LPDIRECTDRAW2 pExistingDirectDraw,
|
||||
DDSURFACEDESC *pNewSurfaceDesc, LPDIRECTDRAWSURFACE *ppNewSurface1, LPDIRECTDRAWSURFACE2 *ppNewSurface2 );
|
||||
void DDCreateSurfaceInMemory ( LPDIRECTDRAW2 pExistingDirectDraw,
|
||||
DDSURFACEDESC *pNewSurfaceDesc,
|
||||
BOOLEAN fVideoMemory, LPDIRECTDRAWSURFACE *ppNewSurface1,
|
||||
LPDIRECTDRAWSURFACE2 *ppNewSurface2 );
|
||||
void DDCreateZBufferSurface ( LPDIRECTDRAW2 pDirectDraw, INT32 iWidth, INT32 iHeight,
|
||||
BOOLEAN fVideoMemory, LPDIRECTDRAWSURFACE *ppZBufferSurface1,
|
||||
LPDIRECTDRAWSURFACE2 *ppZBufferSurface2 );
|
||||
void DDCreateRasterSurface ( LPDIRECTDRAW2 pDirectDraw, INT32 iWidth, INT32 iHeight,
|
||||
BOOLEAN fVideoMemory, LPDIRECTDRAWSURFACE *ppRasterSurface1,
|
||||
LPDIRECTDRAWSURFACE2 *ppRasterSurface2 );
|
||||
void DDGetSurfaceDescription ( LPDIRECTDRAWSURFACE2 pSurface, DDSURFACEDESC *pSurfaceDesc );
|
||||
void DDGetSurfaceCaps ( LPDIRECTDRAWSURFACE2 pSurface, DDSCAPS *pSurfaceCaps );
|
||||
void DDAddAttachedSurface ( LPDIRECTDRAWSURFACE2 pParentSurface,
|
||||
LPDIRECTDRAWSURFACE2 pAddChildSurface );
|
||||
void DDDeleteAttachedSurface ( LPDIRECTDRAWSURFACE2 pParentSurface,
|
||||
LPDIRECTDRAWSURFACE2 pDeleteChildSurface );
|
||||
void DDReleaseSurface ( LPDIRECTDRAWSURFACE *ppOldSurface1, LPDIRECTDRAWSURFACE2 *ppOldSurface2 );
|
||||
|
||||
void DDGetDDInterface( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAW *ppDirectDraw );
|
||||
|
||||
|
||||
void DDLockSurface( LPDIRECTDRAWSURFACE2 pSurface, LPRECT pDestRect, LPDDSURFACEDESC pSurfaceDesc,
|
||||
UINT32 uiFlags, HANDLE hEvent);
|
||||
|
||||
void DDUnlockSurface( LPDIRECTDRAWSURFACE2 pSurface, PTR pSurfaceData );
|
||||
|
||||
void DDRestoreSurface( LPDIRECTDRAWSURFACE2 pSurface );
|
||||
|
||||
void DDBltFastSurface( LPDIRECTDRAWSURFACE2 pDestSurface, UINT32 uiX, UINT32 uiY, LPDIRECTDRAWSURFACE2 pSrcSurface,
|
||||
LPRECT pSrcRect, UINT32 uiTrans);
|
||||
|
||||
void DDBltSurface( LPDIRECTDRAWSURFACE2 pDestSurface, LPRECT pDestRect, LPDIRECTDRAWSURFACE2 pSrcSurface,
|
||||
LPRECT pSrcRect, UINT32 uiFlags, LPDDBLTFX pDDBltFx );
|
||||
|
||||
void DDSetSurfacePalette( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWPALETTE pDDPalette );
|
||||
|
||||
void DDGetSurfacePalette( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWPALETTE *ppDDPalette );
|
||||
|
||||
void DDGetDC( LPDIRECTDRAWSURFACE2 pSurface, HDC *phDC );
|
||||
|
||||
void DDReleaseDC( LPDIRECTDRAWSURFACE2 pSurface, HDC hDC );
|
||||
|
||||
void DDSetSurfaceColorKey( LPDIRECTDRAWSURFACE2 pSurface, UINT32 uiFlags, LPDDCOLORKEY pDDColorKey );
|
||||
|
||||
|
||||
// Palette Functions
|
||||
|
||||
void DDCreatePalette( LPDIRECTDRAW2 pDirectDraw, UINT32 uiFlags, LPPALETTEENTRY pColorTable, LPDIRECTDRAWPALETTE FAR *ppDDPalette,
|
||||
IUnknown FAR * pUnkOuter);
|
||||
|
||||
|
||||
void DDSetPaletteEntries( LPDIRECTDRAWPALETTE pPalette, UINT32 uiFlags, UINT32 uiStartingEntry,
|
||||
UINT32 uiCount, LPPALETTEENTRY pEntries );
|
||||
|
||||
void DDReleasePalette( LPDIRECTDRAWPALETTE pPalette );
|
||||
|
||||
|
||||
void DDGetPaletteEntries( LPDIRECTDRAWPALETTE pPalette, UINT32 uiFlags, UINT32 uiBase,
|
||||
UINT32 uiNumEntries, LPPALETTEENTRY pEntries );
|
||||
|
||||
|
||||
// Clipper functions
|
||||
void DDCreateClipper( LPDIRECTDRAW2 pDirectDraw, UINT32 fFlags, LPDIRECTDRAWCLIPPER *pDDClipper );
|
||||
void DDSetClipper( LPDIRECTDRAWSURFACE2 pSurface, LPDIRECTDRAWCLIPPER pDDClipper );
|
||||
void DDReleaseClipper( LPDIRECTDRAWCLIPPER pDDClipper );
|
||||
void DDSetClipperList( LPDIRECTDRAWCLIPPER pDDClipper, LPRGNDATA pClipList, UINT32 uiFlags);
|
||||
|
||||
HRESULT BltFastDDSurfaceUsingSoftware( LPDIRECTDRAWSURFACE2 pDestSurface, INT32 uiX, INT32 uiY, LPDIRECTDRAWSURFACE2 pSrcSurface, LPRECT pSrcRect, UINT32 uiTrans );
|
||||
HRESULT BltDDSurfaceUsingSoftware( LPDIRECTDRAWSURFACE2 pDestSurface, LPRECT pDestRect, LPDIRECTDRAWSURFACE2 pSrcSurface, LPRECT pSrcRect, UINT32 uiFlags, LPDDBLTFX pDDBltFx );
|
||||
|
||||
|
||||
#define IDirectDrawSurface2_SGPBltFast(p,a,b,c,d,e) ( ( gfDontUseDDBlits == TRUE ) ? BltFastDDSurfaceUsingSoftware( p, a, b, c, d, e ) : ( IDirectDrawSurface2_BltFast(p,a,b,c,d,e) ) )
|
||||
#define IDirectDrawSurface2_SGPBlt(p,a,b,c,d,e) ( ( gfDontUseDDBlits == TRUE ) ? BltDDSurfaceUsingSoftware( p, a, b, c, d, e ) : ( IDirectDrawSurface2_Blt(p,a,b,c,d,e) ) )
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // __DirectDraw_Calls_H__
|
||||
@@ -0,0 +1,238 @@
|
||||
#include "types.h"
|
||||
#include <objbase.h>
|
||||
#include <initguid.h>
|
||||
|
||||
#include "types.h"
|
||||
#include <ddraw.h>
|
||||
#include "DirectX Common.h"
|
||||
#include <windows.h>
|
||||
#include "debug.h"
|
||||
|
||||
void DirectXZeroMem ( void* pMemory, int nSize )
|
||||
{
|
||||
memset ( pMemory, 0, nSize );
|
||||
}
|
||||
|
||||
|
||||
void DirectXAttempt ( INT32 iErrorCode, INT32 nLine, STR8 szFilename )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if ( iErrorCode != DD_OK )
|
||||
{
|
||||
FastDebugMsg("DIRECTX COMMON: DirectX Error\n" );
|
||||
FastDebugMsg(DirectXErrorDescription(iErrorCode));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
STR8 DirectXErrorDescription ( INT32 iDXReturn )
|
||||
{
|
||||
switch( iDXReturn )
|
||||
{
|
||||
case DD_OK
|
||||
: return "No error.\0";
|
||||
case DDERR_ALREADYINITIALIZED
|
||||
: return "The object has already been initialized.";
|
||||
case DDERR_BLTFASTCANTCLIP
|
||||
: return "A DirectDrawClipper object is attached to a source surface that has passed into a call to the IDirectDrawSurface2::BltFast method.";
|
||||
case DDERR_CANNOTATTACHSURFACE
|
||||
: return "A surface cannot be attached to another requested surface.";
|
||||
case DDERR_CANNOTDETACHSURFACE
|
||||
: return "A surface cannot be detached from another requested surface.";
|
||||
case DDERR_CANTCREATEDC
|
||||
: return "Windows cannot create any more device contexts (DCs).";
|
||||
case DDERR_CANTDUPLICATE
|
||||
: return "Primary and 3D surfaces, or surfaces that are implicitly created, cannot be duplicated.";
|
||||
case DDERR_CANTLOCKSURFACE
|
||||
: return "Access to this surface is refused because an attempt was made to lock the primary surface without DCI support.";
|
||||
case DDERR_CANTPAGELOCK
|
||||
: return "An attempt to page lock a surface failed. Page lock will not work on a display-memory surface or an emulated primary surface.";
|
||||
case DDERR_CANTPAGEUNLOCK
|
||||
: return "An attempt to page unlock a surface failed. Page unlock will not work on a display-memory surface or an emulated primary surface.";
|
||||
case DDERR_CLIPPERISUSINGHWND
|
||||
: return "An attempt was made to set a clip list for a DirectDrawClipper object that is already monitoring a window handle.";
|
||||
case DDERR_COLORKEYNOTSET
|
||||
: return "No source color key is specified for this operation.";
|
||||
case DDERR_CURRENTLYNOTAVAIL
|
||||
: return "No support is currently available.";
|
||||
case DDERR_DCALREADYCREATED
|
||||
: return "A device context (DC) has already been returned for this surface. Only one DC can be retrieved for each surface.";
|
||||
case DDERR_DIRECTDRAWALREADYCREATED
|
||||
: return "A DirectDraw object representing this driver has already been created for this process.";
|
||||
case DDERR_EXCEPTION
|
||||
: return "An exception was encountered while performing the requested operation.";
|
||||
case DDERR_EXCLUSIVEMODEALREADYSET
|
||||
: return "An attempt was made to set the cooperative level when it was already set to exclusive.";
|
||||
case DDERR_GENERIC
|
||||
: return "There is an undefined error condition.";
|
||||
case DDERR_HEIGHTALIGN
|
||||
: return "The height of the provided rectangle is not a multiple of the required alignment.";
|
||||
case DDERR_HWNDALREADYSET
|
||||
: return "The DirectDraw cooperative level window handle has already been set. It cannot be reset while the process has surfaces or palettes created.";
|
||||
case DDERR_HWNDSUBCLASSED
|
||||
: return "DirectDraw is prevented from restoring state because the DirectDraw cooperative level window handle has been subclassed.";
|
||||
case DDERR_IMPLICITLYCREATED
|
||||
: return "The surface cannot be restored because it is an implicitly created surface.";
|
||||
case DDERR_INCOMPATIBLEPRIMARY
|
||||
: return "The primary surface creation request does not match with the existing primary surface.";
|
||||
case DDERR_INVALIDCAPS
|
||||
: return "One or more of the capability bits passed to the callback function are incorrect.";
|
||||
case DDERR_INVALIDCLIPLIST
|
||||
: return "DirectDraw does not support the provided clip list.";
|
||||
case DDERR_INVALIDDIRECTDRAWGUID
|
||||
: return "The globally unique identifier (GUID) passed to the DirectDrawCreate function is not a valid DirectDraw driver identifier.";
|
||||
case DDERR_INVALIDMODE
|
||||
: return "DirectDraw does not support the requested mode.";
|
||||
case DDERR_INVALIDOBJECT
|
||||
: return "DirectDraw received a pointer that was an invalid DirectDraw object.";
|
||||
case DDERR_INVALIDPARAMS
|
||||
: return "One or more of the parameters passed to the method are incorrect.";
|
||||
case DDERR_INVALIDPIXELFORMAT
|
||||
: return "The pixel format was invalid as specified.";
|
||||
case DDERR_INVALIDPOSITION
|
||||
: return "The position of the overlay on the destination is no longer legal.";
|
||||
case DDERR_INVALIDRECT
|
||||
: return "The provided rectangle was invalid.";
|
||||
case DDERR_INVALIDSURFACETYPE
|
||||
: return "The requested operation could not be performed because the surface was of the wrong type.";
|
||||
case DDERR_LOCKEDSURFACES
|
||||
: return "One or more surfaces are locked, causing the failure of the requested operation.";
|
||||
case DDERR_NO3D
|
||||
: return "No 3D hardware or emulation is present.";
|
||||
case DDERR_NOALPHAHW
|
||||
: return "No alpha acceleration hardware is present or available, causing the failure of the requested operation.";
|
||||
case DDERR_NOBLTHW
|
||||
: return "No blitter hardware is present.";
|
||||
case DDERR_NOCLIPLIST
|
||||
: return "No clip list is available.";
|
||||
case DDERR_NOCLIPPERATTACHED
|
||||
: return "No DirectDrawClipper object is attached to the surface object.";
|
||||
case DDERR_NOCOLORCONVHW
|
||||
: return "The operation cannot be carried out because no color-conversion hardware is present or available.";
|
||||
case DDERR_NOCOLORKEY
|
||||
: return "The surface does not currently have a color key.";
|
||||
case DDERR_NOCOLORKEYHW
|
||||
: return "The operation cannot be carried out because there is no hardware support for the destination color key.";
|
||||
case DDERR_NOCOOPERATIVELEVELSET
|
||||
: return "A create function is called without the IDirectDraw2::SetCooperativeLevel method being called.";
|
||||
case DDERR_NODC
|
||||
: return "No DC has ever been created for this surface.";
|
||||
case DDERR_NODDROPSHW
|
||||
: return "No DirectDraw raster operation (ROP) hardware is available.";
|
||||
case DDERR_NODIRECTDRAWHW
|
||||
: return "Hardware-only DirectDraw object creation is not possible; the driver does not support any hardware.";
|
||||
case DDERR_NODIRECTDRAWSUPPORT
|
||||
: return "DirectDraw support is not possible with the current display driver.";
|
||||
case DDERR_NOEMULATION
|
||||
: return "Software emulation is not available.";
|
||||
case DDERR_NOEXCLUSIVEMODE
|
||||
: return "The operation requires the application to have exclusive mode, but the application does not have exclusive mode.";
|
||||
case DDERR_NOFLIPHW
|
||||
: return "Flipping visible surfaces is not supported.";
|
||||
case DDERR_NOGDI
|
||||
: return "No GDI is present.";
|
||||
case DDERR_NOHWND
|
||||
: return "Clipper notification requires a window handle, or no window handle has been previously set as the cooperative level window handle.";
|
||||
case DDERR_NOMIPMAPHW
|
||||
: return "The operation cannot be carried out because no mipmap texture mapping hardware is present or available.";
|
||||
case DDERR_NOMIRRORHW
|
||||
: return "The operation cannot be carried out because no mirroring hardware is present or available.";
|
||||
case DDERR_NOOVERLAYDEST
|
||||
: return "The IDirectDrawSurface2::GetOverlayPosition method is called on an overlay that the IDirectDrawSurface2::UpdateOverlay method has not been called on to establish a destination.";
|
||||
case DDERR_NOOVERLAYHW
|
||||
: return "The operation cannot be carried out because no overlay hardware is present or available.";
|
||||
case DDERR_NOPALETTEATTACHED
|
||||
: return "No palette object is attached to this surface.";
|
||||
case DDERR_NOPALETTEHW
|
||||
: return "There is no hardware support for 16- or 256-color palettes.";
|
||||
case DDERR_NORASTEROPHW
|
||||
: return "The operation cannot be carried out because no appropriate raster operation hardware is present or available.";
|
||||
case DDERR_NOROTATIONHW
|
||||
: return "The operation cannot be carried out because no rotation hardware is present or available.";
|
||||
case DDERR_NOSTRETCHHW
|
||||
: return "The operation cannot be carried out because there is no hardware support for stretching.";
|
||||
case DDERR_NOT4BITCOLOR
|
||||
: return "The DirectDrawSurface object is not using a 4-bit color palette and the requested operation requires a 4-bit color palette.";
|
||||
case DDERR_NOT4BITCOLORINDEX
|
||||
: return "The DirectDrawSurface object is not using a 4-bit color index palette and the requested operation requires a 4-bit color index palette.";
|
||||
case DDERR_NOT8BITCOLOR
|
||||
: return "The DirectDrawSurface object is not using an 8-bit color palette and the requested operation requires an 8-bit color palette.";
|
||||
case DDERR_NOTAOVERLAYSURFACE
|
||||
: return "An overlay component is called for a non-overlay surface.";
|
||||
case DDERR_NOTEXTUREHW
|
||||
: return "The operation cannot be carried out because no texture-mapping hardware is present or available.";
|
||||
case DDERR_NOTFLIPPABLE
|
||||
: return "An attempt has been made to flip a surface that cannot be flipped.";
|
||||
case DDERR_NOTFOUND
|
||||
: return "The requested item was not found.";
|
||||
case DDERR_NOTINITIALIZED
|
||||
: return "An attempt was made to call an interface method of a DirectDraw object created by CoCreateInstance before the object was initialized.";
|
||||
case DDERR_NOTLOCKED
|
||||
: return "An attempt is made to unlock a surface that was not locked.";
|
||||
case DDERR_NOTPAGELOCKED
|
||||
: return "An attempt is made to page unlock a surface with no outstanding page locks.";
|
||||
case DDERR_NOTPALETTIZED
|
||||
: return "The surface being used is not a palette-based surface.";
|
||||
case DDERR_NOVSYNCHW
|
||||
: return "The operation cannot be carried out because there is no hardware support for vertical blank synchronized operations.";
|
||||
case DDERR_NOZBUFFERHW
|
||||
: return "The operation to create a z-buffer in display memory or to perform a blit using a z-buffer cannot be carried out because there is no hardware support for z-buffers.";
|
||||
case DDERR_NOZOVERLAYHW
|
||||
: return "The overlay surfaces cannot be z-layered based on the z-order because the hardware does not support z-ordering of overlays.";
|
||||
case DDERR_OUTOFCAPS
|
||||
: return "The hardware needed for the requested operation has already been allocated.";
|
||||
case DDERR_OUTOFMEMORY
|
||||
: return "DirectDraw does not have enough memory to perform the operation.";
|
||||
case DDERR_OUTOFVIDEOMEMORY
|
||||
: return "DirectDraw does not have enough display memory to perform the operation.";
|
||||
case DDERR_OVERLAYCANTCLIP
|
||||
: return "The hardware does not support clipped overlays.";
|
||||
case DDERR_OVERLAYCOLORKEYONLYONEACTIVE
|
||||
: return "An attempt was made to have more than one color key active on an overlay.";
|
||||
case DDERR_OVERLAYNOTVISIBLE
|
||||
: return "The IDirectDrawSurface2::GetOverlayPosition method is called on a hidden overlay.";
|
||||
case DDERR_PALETTEBUSY
|
||||
: return "Access to this palette is refused because the palette is locked by another thread.";
|
||||
case DDERR_PRIMARYSURFACEALREADYEXISTS
|
||||
: return "This process has already created a primary surface.";
|
||||
case DDERR_REGIONTOOSMALL
|
||||
: return "The region passed to the IDirectDrawClipper::GetClipList method is too small.";
|
||||
case DDERR_SURFACEALREADYATTACHED
|
||||
: return "An attempt was made to attach a surface to another surface to which it is already attached.";
|
||||
case DDERR_SURFACEALREADYDEPENDENT
|
||||
: return "An attempt was made to make a surface a dependency of another surface to which it is already dependent.";
|
||||
case DDERR_SURFACEBUSY
|
||||
: return "Access to the surface is refused because the surface is locked by another thread.";
|
||||
case DDERR_SURFACEISOBSCURED
|
||||
: return "Access to the surface is refused because the surface is obscured.";
|
||||
case DDERR_SURFACELOST
|
||||
: return "Access to the surface is refused because the surface memory is gone. The DirectDrawSurface object representing this surface should have the IDirectDrawSurface2::Restore method called on it.";
|
||||
case DDERR_SURFACENOTATTACHED
|
||||
: return "The requested surface is not attached.";
|
||||
case DDERR_TOOBIGHEIGHT
|
||||
: return "The height requested by DirectDraw is too large.";
|
||||
case DDERR_TOOBIGSIZE
|
||||
: return "The size requested by DirectDraw is too large. However, the individual height and width are OK.";
|
||||
case DDERR_TOOBIGWIDTH
|
||||
: return "The width requested by DirectDraw is too large.";
|
||||
case DDERR_UNSUPPORTED
|
||||
: return "The operation is not supported.";
|
||||
case DDERR_UNSUPPORTEDFORMAT
|
||||
: return "The FourCC format requested is not supported by DirectDraw.";
|
||||
case DDERR_UNSUPPORTEDMASK
|
||||
: return "The bitmask in the pixel format requested is not supported by DirectDraw.";
|
||||
case DDERR_UNSUPPORTEDMODE
|
||||
: return "The display is currently in an unsupported mode.";
|
||||
case DDERR_VERTICALBLANKINPROGRESS
|
||||
: return "A vertical blank is in progress.";
|
||||
case DDERR_WASSTILLDRAWING
|
||||
: return "The previous blit operation that is transferring information to or from this surface is incomplete.";
|
||||
case DDERR_WRONGMODE
|
||||
: return "This surface cannot be restored because it was created in a different mode.";
|
||||
case DDERR_XALIGN
|
||||
: return "The provided rectangle was not horizontally aligned on a required boundary.";
|
||||
default
|
||||
: return "Unrecognized error value.\0";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef __DirectX_Common_H__
|
||||
#define __DirectX_Common_H__
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// local functions
|
||||
STR8 DirectXErrorDescription ( INT32 iDXReturn );
|
||||
void DirectXAttempt ( INT32 iErrorCode, INT32 nLine, STR8 szFilename );
|
||||
void DirectXAssert ( BOOLEAN fValue, INT32 nLine, STR8 szFilename );
|
||||
void DirectXZeroMem ( void* pMemory, int nSize );
|
||||
|
||||
#undef ATTEMPT
|
||||
#define ATTEMPT(x) DirectXAttempt ((x),__LINE__,__FILE__)
|
||||
|
||||
#undef ZEROMEM
|
||||
#define ZEROMEM(x) DirectXZeroMem ( (void*)&(x), sizeof(x) )
|
||||
|
||||
#undef DEBUGMSG
|
||||
#define DEBUGMSG(x) OutputDebugString(x)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+1034
File diff suppressed because it is too large
Load Diff
+947
@@ -0,0 +1,947 @@
|
||||
//**************************************************************************
|
||||
//
|
||||
// Filename : FileMan.c
|
||||
//
|
||||
// Purpose : function definitions for the memory manager
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
// 08Apr97:ARM ->Assign return value from Push() calls back to HStack
|
||||
// handle, because it may possibly do a MemRealloc()
|
||||
// 29Dec97:Kris Morness
|
||||
// ->Added functionality for setting file attributes which
|
||||
// allows for read-only attribute overriding
|
||||
// ->Also added a simple function that clears all file attributes
|
||||
// to normal.
|
||||
//
|
||||
// 5 Feb 98:Dave French->extensive modification to support libraries
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
//**************************************************************************
|
||||
#include "Types.h"
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <direct.h>
|
||||
|
||||
|
||||
#include "windows.h"
|
||||
#include "FileMan.h"
|
||||
#include "MemMan.h"
|
||||
#include "Debug.h"
|
||||
#include "LibraryDataBase.h"
|
||||
#include "io.h"
|
||||
#include "sgp_logger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <vfs/Core/vfs.h>
|
||||
#include <vfs/Core/vfs_os_functions.h>
|
||||
#include <vfs/Aspects/vfs_settings.h>
|
||||
|
||||
|
||||
#include <vfs/Core/vfs_file_raii.h>
|
||||
#include <vfs/Tools/vfs_parser_tools.h>
|
||||
#include <map>
|
||||
|
||||
struct SOperation
|
||||
{
|
||||
enum EOperation
|
||||
{
|
||||
UNKNOWN, READ, WRITE,
|
||||
};
|
||||
EOperation op;
|
||||
SOperation() : op(UNKNOWN) {};
|
||||
};
|
||||
|
||||
typedef std::map<vfs::IBaseFile*, SOperation> tFILEMAP;
|
||||
static tFILEMAP s_mapFiles;
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#define FILENAME_LENGTH 600
|
||||
|
||||
#define CHECKF(exp) if (!(exp)) { return(FALSE); }
|
||||
#define CHECKV(exp) if (!(exp)) { return; }
|
||||
#define CHECKN(exp) if (!(exp)) { return(NULL); }
|
||||
#define CHECKBI(exp) if (!(exp)) { return(-1); }
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Typedefs
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
typedef struct FMFileInfoTag
|
||||
{
|
||||
CHAR strFilename[FILENAME_LENGTH];
|
||||
UINT8 uiFileAccess;
|
||||
UINT32 uiFilePosition;
|
||||
HANDLE hFileHandle;
|
||||
|
||||
} FMFileInfo; // for 'File Manager File Information'
|
||||
|
||||
typedef struct FileSystemTag
|
||||
{
|
||||
FMFileInfo *pFileInfo;
|
||||
UINT32 uiNumHandles;
|
||||
BOOLEAN fDebug;
|
||||
BOOLEAN fDBInitialized;
|
||||
|
||||
CHAR *pcFileNames;
|
||||
UINT32 uiNumFilesInDirectory;
|
||||
} FileSystem;
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Variables
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
|
||||
//The FileDatabaseHeader
|
||||
DatabaseManagerHeaderStruct gFileDataBase;
|
||||
|
||||
|
||||
//FileSystem gfs;
|
||||
|
||||
WIN32_FIND_DATA Win32FindInfo[20];
|
||||
BOOLEAN fFindInfoInUse[20] = {FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
FALSE,FALSE,FALSE,FALSE,FALSE,
|
||||
FALSE,FALSE,FALSE,FALSE,FALSE };
|
||||
HANDLE hFindInfoHandle[20] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE,
|
||||
INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileSystemInit
|
||||
//
|
||||
// Starts up the file system.
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
BOOLEAN InitializeFileManager( STR strIndexFilename )
|
||||
{
|
||||
RegisterDebugTopic( TOPIC_FILE_MANAGER, "File Manager" );
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileSystemShutdown
|
||||
//
|
||||
// Shuts down the file system.
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
void ShutdownFileManager( void )
|
||||
{
|
||||
UnRegisterDebugTopic( TOPIC_FILE_MANAGER, "File Manager" );
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileExists
|
||||
//
|
||||
// Checks if a file exists.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// STR ->name of file to check existence of
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// BOOLEAN ->TRUE if it exists
|
||||
// ->FALSE if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
// Oct 2005: Snap - Rewrote, made to check data catalogues
|
||||
//
|
||||
//**************************************************************************
|
||||
BOOLEAN FileExists( STR strFilename )
|
||||
{
|
||||
return getVFS()->fileExists(vfs::Path(strFilename));
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileExistsNoDB
|
||||
//
|
||||
// Checks if a file exists, but doesn't check the database files.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// STR ->name of file to check existence of
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// BOOLEAN ->TRUE if it exists
|
||||
// ->FALSE if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// Oct 2005: Snap - Rewrote, made to check data catalogues
|
||||
//
|
||||
//**************************************************************************
|
||||
extern BOOLEAN FileExistsNoDB( STR strFilename )
|
||||
{
|
||||
return getVFS()->fileExists(vfs::Path(strFilename));
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileDelete
|
||||
//
|
||||
// Deletes a file.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// STR ->name of file to delete
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// BOOLEAN ->TRUE if successful
|
||||
// ->FALSE if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
BOOLEAN FileDelete( STR strFilename )
|
||||
{
|
||||
return getVFS()->removeFileFromFS(vfs::Path(strFilename));
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileOpen
|
||||
//
|
||||
// Opens a file.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// STR ->filename
|
||||
// UIN32 ->access - read or write, or both
|
||||
// BOOLEAN ->delete on close
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// HWFILE ->handle of opened file
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
// Oct 2005: Snap - modified to work with the custom Data directory
|
||||
//
|
||||
//**************************************************************************
|
||||
HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose, STR strProfilename )//dnl ch81 021213
|
||||
{
|
||||
vfs::Path path(strFilename);
|
||||
vfs::IBaseFile *pFile = NULL;
|
||||
try
|
||||
{
|
||||
if(uiOptions & FILE_ACCESS_WRITE)
|
||||
{
|
||||
// 'vfs::CVirtualFile::SF_TOP' should be enough, but if for some strange reason
|
||||
// file creation fails, we will stop at a writable profile
|
||||
// and won't unintentionally mess up a file from another profile
|
||||
vfs::COpenWriteFile open_w( path, true, false, vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
pFile = &open_w.file();
|
||||
open_w.release();
|
||||
s_mapFiles[pFile].op = SOperation::WRITE;
|
||||
return (HWFILE)pFile;
|
||||
}
|
||||
else if(uiOptions & FILE_ACCESS_READ)
|
||||
{
|
||||
if(strProfilename && strProfilename[0])
|
||||
{
|
||||
vfs::COpenReadFile open_r(vfs::tReadableFile::cast(getVFS()->getFile(path, strProfilename)));
|
||||
pFile = &open_r.file();
|
||||
open_r.release();
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs::COpenReadFile open_r(path, vfs::CVirtualFile::SF_TOP);
|
||||
pFile = &open_r.file();
|
||||
open_r.release();
|
||||
}
|
||||
s_mapFiles[pFile].op = SOperation::READ;
|
||||
return (HWFILE)pFile;
|
||||
}
|
||||
}
|
||||
// sometimes a file is supposed to opened that does not exist (not tested with FileExists())
|
||||
// this operation can fail with an exception that the calling code doesn't catch
|
||||
// instead we catch it (any exception, not just CBasicException) here and return 0
|
||||
catch(vfs::Exception& ex) { SGP_ERROR(ex.what()); }
|
||||
catch(...)
|
||||
{
|
||||
SGP_ERROR( "Caught undefined exception" );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileClose
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// HWFILE hFile ->handle to file to close
|
||||
//
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
//**************************************************************************
|
||||
void FileClose( HWFILE hFile )
|
||||
{
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile)
|
||||
{
|
||||
pFile->close();
|
||||
s_mapFiles.erase(pFile);
|
||||
}
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileRead
|
||||
//
|
||||
// To read a file.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// HWFILE ->handle to file to read from
|
||||
// void * ->source buffer
|
||||
// UINT32 ->num bytes to read
|
||||
// UINT32 ->num bytes read
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// BOOLEAN ->TRUE if successful
|
||||
// ->FALSE if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
// 08Dec97:ARM ->return FALSE if bytes to read != bytes read
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#ifdef JA2TESTVERSION
|
||||
extern UINT32 uiTotalFileReadTime;
|
||||
extern UINT32 uiTotalFileReadCalls;
|
||||
#include "Timer Control.h"
|
||||
|
||||
class TimeCounter
|
||||
{
|
||||
public:
|
||||
TimeCounter() : start_time(GetJA2Clock()) {}
|
||||
~TimeCounter()
|
||||
{
|
||||
uiTotalFileReadTime += GetJA2Clock() - start_time;
|
||||
uiTotalFileReadCalls++;
|
||||
}
|
||||
private:
|
||||
UINT32 start_time;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead )
|
||||
{
|
||||
#ifdef JA2TESTVERSION
|
||||
TimeCounter timer;
|
||||
#endif
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile && (s_mapFiles[pFile].op == SOperation::READ))
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::cast(pFile);
|
||||
if(pRF)
|
||||
{
|
||||
UINT32 uiBytesRead = 0;
|
||||
try
|
||||
{
|
||||
uiBytesRead = pRF->read((vfs::Byte*)pDest, uiBytesToRead);
|
||||
}
|
||||
catch(std::exception& ex)
|
||||
{
|
||||
pRF->close();
|
||||
SGP_RETHROW(L"", ex);
|
||||
}
|
||||
|
||||
if(puiBytesRead)
|
||||
{
|
||||
*puiBytesRead = uiBytesRead;
|
||||
}
|
||||
if(uiBytesToRead != uiBytesRead)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOLEAN FileReadLine( HWFILE hFile, std::string* pDest )
|
||||
{
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if ( pFile && FileCheckEndOfFile( hFile ) == FALSE && (s_mapFiles[pFile].op == SOperation::READ) )
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::cast( pFile );
|
||||
if ( pRF && pDest )
|
||||
{
|
||||
vfs::CReadLine rl( *pRF, false );
|
||||
rl.getLine( *pDest );
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileWrite
|
||||
//
|
||||
// To write a file.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// HWFILE ->handle to file to write to
|
||||
// void * ->destination buffer
|
||||
// UINT32 ->num bytes to write
|
||||
// UINT32 ->num bytes written
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// BOOLEAN ->TRUE if successful
|
||||
// ->FALSE if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
// 08Dec97:ARM ->return FALSE if dwNumBytesToWrite != dwNumBytesWritten
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBytesWritten )
|
||||
{
|
||||
if(uiBytesToWrite == 0)//dnl ch38 110909
|
||||
{
|
||||
*puiBytesWritten = 0;
|
||||
return(TRUE);
|
||||
}
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile && (s_mapFiles[pFile].op == SOperation::WRITE))
|
||||
{
|
||||
vfs::tWritableFile *pWF = vfs::tWritableFile::cast(pFile);
|
||||
if(pWF)
|
||||
{
|
||||
UINT32 uiBytesWritten;
|
||||
try
|
||||
{
|
||||
uiBytesWritten = pWF->write((vfs::Byte*)pDest, uiBytesToWrite);
|
||||
}
|
||||
catch(std::exception& ex)
|
||||
{
|
||||
pWF->close();
|
||||
SGP_RETHROW(L"", ex);
|
||||
}
|
||||
|
||||
if (uiBytesToWrite != uiBytesWritten)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if ( puiBytesWritten )
|
||||
{
|
||||
*puiBytesWritten = uiBytesWritten;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileLoad
|
||||
//
|
||||
// To open, read, and close a file.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// BOOLEAN ->TRUE if successful
|
||||
// ->FALSE if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
// 08Dec97:ARM ->return FALSE if bytes to read != bytes read (CHECKF is inappropriate?)
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead )
|
||||
{
|
||||
vfs::tReadableFile *pFile = getVFS()->getReadFile(vfs::Path(strFilename));
|
||||
vfs::COpenReadFile rfile(pFile);
|
||||
if(pFile)
|
||||
{
|
||||
UINT32 uiNumBytesRead;
|
||||
SGP_TRYCATCH_RETHROW(uiNumBytesRead = pFile->read((vfs::Byte*)pDest,uiBytesToRead), L"");
|
||||
|
||||
if (uiBytesToRead != uiNumBytesRead)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if ( puiBytesRead )
|
||||
{
|
||||
*puiBytesRead = uiNumBytesRead;
|
||||
}
|
||||
CHECKF( uiNumBytesRead == uiBytesToRead );
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FilePrintf
|
||||
//
|
||||
// To printf to a file.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// HWFILE ->handle to file to seek in
|
||||
// ... ->arguments, 1st of which should be a string
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// BOOLEAN ->TRUE if successful
|
||||
// ->FALSE if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
//**************************************************************************
|
||||
#ifndef DIM
|
||||
# define DIM(x) (sizeof(x)/sizeof(x[0])) /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */
|
||||
#endif
|
||||
|
||||
|
||||
BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... )
|
||||
{
|
||||
CHAR8 strToSend[160]; /* itemdescription of item 0 will NOT fit if only 80 Chars per Line!, Sergeant_Kolja, 2007-06-10 */
|
||||
va_list argptr;
|
||||
BOOLEAN fRetVal = FALSE;
|
||||
|
||||
va_start(argptr, strFormatted);
|
||||
_vsnprintf( strToSend, DIM(strToSend), strFormatted, argptr ); /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */
|
||||
strToSend[ DIM(strToSend)-1 ] = 0;
|
||||
va_end(argptr);
|
||||
|
||||
fRetVal = FileWrite( hFile, strToSend, strlen(strToSend), NULL );
|
||||
return( fRetVal );
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileSeek
|
||||
//
|
||||
// To seek to a position in a file.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// HWFILE ->handle to file to seek in
|
||||
// UINT32 ->distance to seek
|
||||
// UINT8 ->how to seek
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// BOOLEAN ->TRUE if successful
|
||||
// ->FALSE if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN FileSeek( HWFILE hFile, UINT32 uiDistance, UINT8 uiHow )
|
||||
{
|
||||
INT32 iDistance = (INT32)uiDistance;
|
||||
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile)
|
||||
{
|
||||
vfs::IBaseFile::ESeekDir eSD;
|
||||
if ( uiHow == FILE_SEEK_FROM_START )
|
||||
{
|
||||
eSD = vfs::IBaseFile::SD_BEGIN;
|
||||
}
|
||||
else if ( uiHow == FILE_SEEK_FROM_END )
|
||||
{
|
||||
eSD = vfs::IBaseFile::SD_END;
|
||||
if( iDistance > 0 )
|
||||
{
|
||||
iDistance = -(iDistance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eSD = vfs::IBaseFile::SD_CURRENT;
|
||||
}
|
||||
|
||||
if(s_mapFiles[pFile].op == SOperation::WRITE)
|
||||
{
|
||||
vfs::tWritableFile *pWF = vfs::tWritableFile::cast(pFile);
|
||||
if(pWF)
|
||||
{
|
||||
SGP_TRYCATCH_RETHROW(pWF->setWritePosition(iDistance, eSD), L"");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else if(s_mapFiles[pFile].op == SOperation::READ)
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::cast(pFile);
|
||||
if(pRF)
|
||||
{
|
||||
SGP_TRYCATCH_RETHROW(pRF->setReadPosition(iDistance, eSD), L"");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SGP_THROW(L"unknown operation");
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileGetPos
|
||||
//
|
||||
// To get the current position in a file.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// HWFILE ->handle to file
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// INT32 ->current offset in file if successful
|
||||
// ->-1 if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
INT32 FileGetPos( HWFILE hFile )
|
||||
{
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile && (s_mapFiles[pFile].op == SOperation::WRITE))
|
||||
{
|
||||
vfs::tWritableFile *pWF = vfs::tWritableFile::cast(pFile);
|
||||
if(pWF)
|
||||
{
|
||||
return pWF->getWritePosition();
|
||||
}
|
||||
}
|
||||
else if(pFile && (s_mapFiles[pFile].op == SOperation::READ))
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::cast(pFile);
|
||||
if(pRF)
|
||||
{
|
||||
return pRF->getReadPosition();
|
||||
}
|
||||
}
|
||||
|
||||
return BAD_INDEX;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// FileGetSize
|
||||
//
|
||||
// To get the current file size.
|
||||
//
|
||||
// Parameter List :
|
||||
//
|
||||
// HWFILE ->handle to file
|
||||
//
|
||||
// Return Value :
|
||||
//
|
||||
// INT32 ->file size in file if successful
|
||||
// ->0 if not
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH ->creation
|
||||
//
|
||||
// 9 Feb 98 DEF - modified to work with the library system
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
UINT32 FileGetSize( HWFILE hFile )
|
||||
{
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
if(pFile)
|
||||
{
|
||||
return pFile->getSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN SetFileManCurrentDirectory( STR pcDirectory )
|
||||
{
|
||||
try
|
||||
{
|
||||
vfs::OS::setCurrectDirectory(pcDirectory);
|
||||
}
|
||||
catch(vfs::Exception& ex)
|
||||
{
|
||||
SGP_ERROR(ex.what());
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory )
|
||||
{
|
||||
try
|
||||
{
|
||||
vfs::Path sDir;
|
||||
vfs::OS::getCurrentDirectory(sDir);
|
||||
strncpy(pcDirectory, sDir.to_string().c_str(), 512);
|
||||
}
|
||||
catch(vfs::Exception& ex)
|
||||
{
|
||||
SGP_ERROR(ex.what());
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Removes ALL FILES in the specified directory (and all subdirectories with their files if fRecursive is TRUE)
|
||||
// Use EraseDirectory() to simply delete directory contents without deleting the directory itself
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive )
|
||||
{
|
||||
// ignore 'recursive' flag, just delete every file in that subtree (but leave the directories)
|
||||
return getVFS()->removeDirectoryFromFS(pcDirectory);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Removes ALL FILES in the specified directory but leaves the directory alone. Does not affect any subdirectories!
|
||||
// Use RemoveFilemanDirectory() to also delete the directory itself, or to recursively delete subdirectories.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
BOOLEAN EraseDirectory( STRING512 pcDirectory)
|
||||
{
|
||||
// ignore 'recursive' flag, just delete every file in that subtree (but leave the directories)
|
||||
return getVFS()->removeDirectoryFromFS(pcDirectory);
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN GetExecutableDirectory( STRING512 pcDirectory )
|
||||
{
|
||||
vfs::Path exe_dir, exe_file;
|
||||
vfs::OS::getExecutablePath(exe_dir, exe_file);
|
||||
strncpy(pcDirectory, exe_dir.to_string().c_str(), 512);
|
||||
return true;
|
||||
}
|
||||
|
||||
static vfs::CVirtualFileSystem::Iterator file_iter;
|
||||
BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct )
|
||||
{
|
||||
CHECKF( pSpec != NULL );
|
||||
CHECKF( pGFStruct != NULL );
|
||||
|
||||
file_iter = getVFS()->begin(pSpec);
|
||||
if(!file_iter.end())
|
||||
{
|
||||
vfs::Path const& path = file_iter.value()->getName();
|
||||
std::string s = path.to_string();
|
||||
::size_t size = s.length();
|
||||
size = std::min< ::size_t>(size,260-1);
|
||||
sprintf( pGFStruct->zFileName, s.c_str());
|
||||
pGFStruct->zFileName[size] = 0;
|
||||
|
||||
pGFStruct->iFindHandle = 0;
|
||||
pGFStruct->uiFileSize = file_iter.value()->getSize();
|
||||
pGFStruct->uiFileAttribs = ( file_iter.value()->implementsWritable() ? FILE_IS_NORMAL : FILE_IS_READONLY );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct )
|
||||
{
|
||||
if(!file_iter.end())
|
||||
{
|
||||
file_iter.next();
|
||||
}
|
||||
if(!file_iter.end())
|
||||
{
|
||||
vfs::Path const& path = file_iter.value()->getName();
|
||||
std::string s = path.to_string();
|
||||
::size_t size = s.length();
|
||||
size = std::min< ::size_t>(size,260-1);
|
||||
sprintf( pGFStruct->zFileName, s.c_str());
|
||||
pGFStruct->zFileName[size] = 0;
|
||||
|
||||
pGFStruct->iFindHandle = 0;
|
||||
pGFStruct->uiFileSize = file_iter.value()->getSize();
|
||||
pGFStruct->uiFileAttribs = ( file_iter.value()->implementsWritable() ? FILE_IS_NORMAL : FILE_IS_READONLY );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void GetFileClose( GETFILESTRUCT *pGFStruct )
|
||||
{
|
||||
file_iter = vfs::CVirtualFileSystem::Iterator();
|
||||
}
|
||||
|
||||
|
||||
//returns true if at end of file, else false
|
||||
BOOLEAN FileCheckEndOfFile( HWFILE hFile )
|
||||
{
|
||||
vfs::size_t current_position, max_position;
|
||||
vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile;
|
||||
|
||||
if(pFile && (s_mapFiles[pFile].op == SOperation::WRITE))
|
||||
{
|
||||
vfs::tWritableFile *pWF = vfs::tWritableFile::cast(pFile);
|
||||
if(pWF)
|
||||
{
|
||||
current_position = pWF->getWritePosition();
|
||||
max_position = pWF->getSize();
|
||||
return current_position >= max_position;
|
||||
}
|
||||
}
|
||||
else if(pFile && (s_mapFiles[pFile].op == SOperation::READ))
|
||||
{
|
||||
vfs::tReadableFile *pRF = vfs::tReadableFile::cast(pFile);
|
||||
if(pRF)
|
||||
{
|
||||
current_position = pRF->getReadPosition();
|
||||
max_position = pRF->getSize();
|
||||
return current_position >= max_position;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
UINT32 FileSize(STR strFilename)
|
||||
{
|
||||
vfs::IBaseFile *pFile = getVFS()->getFile(vfs::Path(strFilename));
|
||||
if(pFile)
|
||||
{
|
||||
return pFile->getSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Flugente: simple wrapper to check whether an audio file in mp3/ogg/wav format exists
|
||||
BOOLEAN SoundFileExists( STR strFilename, STR zFoundFilename )
|
||||
{
|
||||
sprintf( zFoundFilename, "%s.mp3", strFilename );
|
||||
if ( !FileExists( zFoundFilename ) )
|
||||
{
|
||||
sprintf( zFoundFilename, "%s.ogg", strFilename );
|
||||
if ( !FileExists( zFoundFilename ) )
|
||||
{
|
||||
sprintf( zFoundFilename, "%s.wav", strFilename );
|
||||
}
|
||||
}
|
||||
|
||||
return FileExists( zFoundFilename );
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
//**************************************************************************
|
||||
//
|
||||
// Filename : FileMan.h
|
||||
//
|
||||
// Purpose : prototypes for the file manager
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 24sep96:HJH - Creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#ifndef _FILEMAN_H
|
||||
#define _FILEMAN_H
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#include "types.h"
|
||||
#include "Windows.h"
|
||||
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#define MAX_FILENAME_LEN 48
|
||||
|
||||
#define FILE_ACCESS_READ 0x01
|
||||
#define FILE_ACCESS_WRITE 0x02
|
||||
#define FILE_ACCESS_READWRITE 0x03
|
||||
|
||||
#define FILE_CREATE_NEW 0x0010 // create new file. fail if exists
|
||||
#define FILE_CREATE_ALWAYS 0x0020 // create new file. overwrite existing
|
||||
#define FILE_OPEN_EXISTING 0x0040 // open a file. fail if doesn't exist
|
||||
#define FILE_OPEN_ALWAYS 0x0080 // open a file, create if doesn't exist
|
||||
#define FILE_TRUNCATE_EXISTING 0x0100 // open a file, truncate to size 0. fail if no exist
|
||||
|
||||
#define FILE_SEEK_FROM_START 0x01 // keep in sync with dbman.h
|
||||
#define FILE_SEEK_FROM_END 0x02 // keep in sync with dbman.h
|
||||
#define FILE_SEEK_FROM_CURRENT 0x04 // keep in sync with dbman.h
|
||||
|
||||
// GetFile file attributes
|
||||
#define FILE_IS_READONLY 1
|
||||
#define FILE_IS_DIRECTORY 2
|
||||
#define FILE_IS_HIDDEN 4
|
||||
#define FILE_IS_NORMAL 8
|
||||
#define FILE_IS_ARCHIVE 16
|
||||
#define FILE_IS_SYSTEM 32
|
||||
#define FILE_IS_TEMPORARY 64
|
||||
#define FILE_IS_COMPRESSED 128
|
||||
#define FILE_IS_OFFLINE 256
|
||||
|
||||
|
||||
// Snap, Kaiden: This define duplicates a standard MFC define
|
||||
// Added to resolve some intractable issue with MSVC6
|
||||
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
|
||||
|
||||
typedef FILETIME SGP_FILETIME;
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
//**************************************************************************
|
||||
extern BOOLEAN InitializeFileManager( STR strIndexFilename );
|
||||
|
||||
extern void ShutdownFileManager( void );
|
||||
|
||||
|
||||
BOOLEAN FileExists( STR strFilename );
|
||||
extern BOOLEAN FileExistsNoDB( STR strFilename );
|
||||
extern BOOLEAN FileDelete( STR strFilename );
|
||||
extern HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose=FALSE, STR strProfilename=NULL );//dnl ch81 021213
|
||||
|
||||
extern void FileClose( HWFILE );
|
||||
|
||||
extern BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead );
|
||||
extern BOOLEAN FileReadLine( HWFILE hFile, std::string* pDest );
|
||||
extern BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBytesWritten );
|
||||
extern BOOLEAN FileLoad( STR filename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead );
|
||||
|
||||
extern BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... );
|
||||
|
||||
extern BOOLEAN FileSeek( HWFILE, UINT32 uiDistance, UINT8 uiHow );
|
||||
extern INT32 FileGetPos( HWFILE );
|
||||
|
||||
extern UINT32 FileGetSize( HWFILE );
|
||||
extern UINT32 FileSize(STR strFilename);
|
||||
|
||||
BOOLEAN SetFileManCurrentDirectory( STR pcDirectory );
|
||||
BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory );
|
||||
BOOLEAN GetExecutableDirectory( STRING512 pcDirectory );
|
||||
|
||||
// WARNING: THESE DELETE ALL FILES IN THE DIRECTORY ( and all subdirectories if fRecursive is TRUE!! )
|
||||
BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive);
|
||||
BOOLEAN EraseDirectory( STRING512 pcDirectory);
|
||||
|
||||
typedef struct _GETFILESTRUCT_TAG {
|
||||
INT32 iFindHandle;
|
||||
CHAR8 zFileName[ 260 ]; // changed from UINT16, Alex Meduna, Mar-20'98
|
||||
UINT32 uiFileSize;
|
||||
UINT32 uiFileAttribs;
|
||||
} GETFILESTRUCT;
|
||||
|
||||
BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct );
|
||||
|
||||
BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct );
|
||||
void GetFileClose( GETFILESTRUCT *pGFStruct );
|
||||
|
||||
//returns true if at end of file, else false
|
||||
BOOLEAN FileCheckEndOfFile( HWFILE hFile );
|
||||
|
||||
// Flugente: simple wrapper to check whether an audio file in mp3/ogg/wav format exists
|
||||
BOOLEAN SoundFileExists( STR strFilename, STR zFoundFilename );
|
||||
#endif
|
||||
+2989
File diff suppressed because it is too large
Load Diff
+166
@@ -0,0 +1,166 @@
|
||||
#ifndef __FONT_H_
|
||||
#define __FONT_H_
|
||||
|
||||
#include "Types.h"
|
||||
#include "himage.h"
|
||||
#include "vobject.h"
|
||||
//#ifdef WINFONTS
|
||||
#include "WinFont.h"
|
||||
//#endif
|
||||
#include "Font Control.h"
|
||||
|
||||
#define MAX_FONTS 25
|
||||
|
||||
#define DEFAULT_SHADOW 2
|
||||
#define MILITARY_SHADOW 67
|
||||
#define NO_SHADOW 0
|
||||
|
||||
|
||||
// these are bogus! No palette is set yet!
|
||||
// font foreground color symbols
|
||||
#define FONT_FCOLOR_WHITE 208
|
||||
#define FONT_FCOLOR_RED 162
|
||||
#define FONT_FCOLOR_NICERED 164
|
||||
#define FONT_FCOLOR_BLUE 203
|
||||
#define FONT_FCOLOR_GREEN 184
|
||||
#define FONT_FCOLOR_YELLOW 144
|
||||
#define FONT_FCOLOR_BROWN 184
|
||||
#define FONT_FCOLOR_ORANGE 76
|
||||
#define FONT_FCOLOR_PURPLE 160
|
||||
|
||||
// font background color symbols
|
||||
#define FONT_BCOLOR_WHITE 208
|
||||
#define FONT_BCOLOR_RED 162
|
||||
#define FONT_BCOLOR_BLUE 203
|
||||
#define FONT_BCOLOR_GREEN 184
|
||||
#define FONT_BCOLOR_YELLOW 144
|
||||
#define FONT_BCOLOR_BROWN 80
|
||||
#define FONT_BCOLOR_ORANGE 76
|
||||
#define FONT_BCOLOR_PURPLE 160
|
||||
|
||||
|
||||
|
||||
// typedefs
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT16 usNumberOfSymbols;
|
||||
UINT16 *DynamicArrayOf16BitValues;
|
||||
|
||||
} FontTranslationTable;
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
extern INT32 FontDefault;
|
||||
extern UINT32 FontDestBuffer;
|
||||
extern UINT32 FontDestPitch;
|
||||
extern UINT32 FontDestBPP;
|
||||
extern SGPRect FontDestRegion;
|
||||
extern BOOLEAN FontDestWrap;
|
||||
|
||||
#define SetFontDestObject(x) (SetFontDestBuffer(x, \
|
||||
FontDestRegion.left, \
|
||||
FontDestRegion.top, \
|
||||
FontDestRegion.right, \
|
||||
FontDestRegion.bottom,\
|
||||
FontDestWrap))
|
||||
|
||||
#define SetFontDestClip(x1, y1, x2, y2) (SetFontDestBuffer(FontDestBuffer, \
|
||||
x1, y1, \
|
||||
x2, y2, \
|
||||
FontDestWrap))
|
||||
#define SetFontDestWrap(x) (SetFontDestBuffer(FontDestBuffer, \
|
||||
FontDestRegion.left, \
|
||||
FontDestRegion.top, \
|
||||
FontDestRegion.right, \
|
||||
FontDestRegion.bottom,\
|
||||
x))
|
||||
// functions
|
||||
|
||||
void SetFontColors(UINT16 usColors);
|
||||
void SetFontForeground(UINT8 ubForeground);
|
||||
void SetFontBackground(UINT8 ubBackground);
|
||||
void SetFontShadow(UINT8 ubBackground);
|
||||
|
||||
//Kris: added these
|
||||
void SetRGBFontForeground( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue );
|
||||
void SetRGBFontBackground( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue );
|
||||
void SetRGBFontShadow( UINT32 uiRed, UINT32 uiGreen, UINT32 uiBlue );
|
||||
|
||||
// Flugente: set 16 bit colour directly
|
||||
void SetRGBFontForeground( UINT16 usFontForeground16 );
|
||||
void SetRGBFontShadow( UINT16 usFontShadow16 );
|
||||
|
||||
BOOLEAN ResetFontObjectPalette(INT32 iFont);
|
||||
UINT16 *SetFontObjectPalette8BPP(INT32 iFont, SGPPaletteEntry *pPal8);
|
||||
UINT16 *SetFontObjectPalette16BPP(INT32 iFont, UINT16 *pPal16);
|
||||
UINT16 *GetFontObjectPalette16BPP(INT32 iFont);
|
||||
|
||||
void DestroyEnglishTransTable( void );
|
||||
|
||||
extern BOOLEAN IsFontLoaded(INT32 iFont);
|
||||
extern HVOBJECT GetFontObject(INT32 iFont);
|
||||
extern UINT32 gprintf(INT32 x, INT32 y, const STR16 pFontString, ...);
|
||||
extern UINT32 gprintfDirty(INT32 x, INT32 y, const STR16 pFontString, ...);
|
||||
extern UINT32 mprintf(INT32 x, INT32 y, const STR16 pFontString, ...);
|
||||
extern UINT32 gprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...);
|
||||
extern UINT32 mprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...);
|
||||
|
||||
// Function for displaying coded test. Since it's slower to do this, it's separate from the normal fuctions
|
||||
#define FONT_CODE_BEGINCOLOR 180
|
||||
#define FONT_CODE_RESETCOLOR 181
|
||||
|
||||
UINT32 mprintf_buffer_coded( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...);
|
||||
UINT32 mprintf_coded( INT32 x, INT32 y, const STR16 pFontString, ...);
|
||||
|
||||
|
||||
extern BOOLEAN SetFontDestBuffer(UINT32 DestBuffer, INT32 x1, INT32 y1, INT32 x2, INT32 y2, BOOLEAN wrap);
|
||||
extern BOOLEAN SetFont(INT32 iFontIndex);
|
||||
|
||||
extern INT32 LoadFontFile(const STR8 pFileName);
|
||||
extern UINT16 GetFontHeight(INT32 FontNum);
|
||||
extern BOOLEAN InitializeFontManager(UINT16 usDefaultPixDepth, FontTranslationTable *pTransTable);
|
||||
extern void ShutdownFontManager(void);
|
||||
extern void UnloadFont(UINT32 FontIndex);
|
||||
|
||||
extern FontTranslationTable *CreateEnglishTransTable( );
|
||||
|
||||
extern INT16 GetIndex(CHAR16 siChar);
|
||||
extern UINT32 GetWidth(HVOBJECT hSrcVObject, INT16 ssIndex);
|
||||
|
||||
extern INT16 StringPixLengthArgFastHelp( INT32 usUseFont, INT32 usBoldFont, UINT32 uiCharCount, STR16 pFontString );
|
||||
extern INT16 StringPixLengthArg(INT32 usUseFont, UINT32 uiCharCount, STR16 pFontString, ...);
|
||||
extern INT16 StringPixLength(const STR16 string,INT32 UseFont);
|
||||
extern INT16 SubstringPixLength(STR16 string, UINT32 iStart, UINT32 iEnd, INT32 UseFont);
|
||||
extern INT16 StringNPixLength(STR16 string, UINT32 uiMaxCount, INT32 UseFont);
|
||||
extern void SaveFontSettings(void);
|
||||
extern void RestoreFontSettings(void);
|
||||
|
||||
void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... );
|
||||
|
||||
void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... );
|
||||
|
||||
void FindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, const STR16 pStr, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY );
|
||||
|
||||
void FindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, const STR16 pStr, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY );
|
||||
|
||||
//extern FontBase *LoadFontFile(CHAR8 *pFileName);
|
||||
//extern UINT8 *GetFontPalette(CHAR8 *pFileName);
|
||||
//extern UINT16 GetMaxFontWidth(FontBase *pBase);
|
||||
//extern void UnloadFont(FontBase *pBase);
|
||||
//extern BOOLEAN SetFontPalette(FontBase *pFont, UINT16 siDepthPix, SGPPaletteEntry *pNewPalette);
|
||||
// make sure the pFontString is terminated by 0
|
||||
//extern BOOLEAN PrintFontString(STR16 pFontString, UINT8 *pDestBuffer, UINT16 siDestWidth, UINT16 siDestPixelDepth, UINT16 siDestPitch, UINT16 siDestHeight, UINT16 siX, UINT16 siY, UINT16 siTotalWidth, UINT16 siTotalHeight, BOOLEAN MultiLine, FontBase *pFontBase);
|
||||
//extern BOOLEAN SetFont16BitData(FontBase *pFontBase, UINT16 *pData16);
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
CHAR16 GetUnicodeChar(CHAR16 siChar);
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "LibraryDataBase.h"
|
||||
LibraryInitHeader gGameLibaries[ ] =
|
||||
{
|
||||
//Library Name Can be Init at start
|
||||
// on cd
|
||||
{ "Data.slf", FALSE, TRUE },
|
||||
{ "Editor.slf", FALSE, FALSE },
|
||||
{ "Ambient.slf", FALSE, TRUE },
|
||||
{ "Anims.slf", FALSE, TRUE },
|
||||
{ "BattleSnds.slf", FALSE, TRUE },
|
||||
{ "BigItems.slf", FALSE, TRUE },
|
||||
{ "BinaryData.slf", FALSE, TRUE },
|
||||
{ "Cursors.slf", FALSE, TRUE },
|
||||
{ "Faces.slf", FALSE, TRUE },
|
||||
{ "Fonts.slf", FALSE, TRUE },
|
||||
{ "Interface.slf", FALSE, TRUE },
|
||||
{ "Laptop.slf", FALSE, TRUE },
|
||||
{ "Maps.slf", TRUE, TRUE },
|
||||
{ "MercEdt.slf", FALSE, TRUE },
|
||||
{ "Music.slf", TRUE, TRUE },
|
||||
{ "Npc_Speech.slf", TRUE, TRUE },
|
||||
{ "NpcData.slf", FALSE, TRUE },
|
||||
{ "RadarMaps.slf", FALSE, TRUE },
|
||||
{ "Sounds.slf", FALSE, TRUE },
|
||||
{ "Speech.slf", TRUE, TRUE },
|
||||
// { "TileCache.slf", FALSE, TRUE },
|
||||
{ "TileSets.slf", TRUE, TRUE },
|
||||
{ "LoadScreens.slf", TRUE, TRUE },
|
||||
{ "Intro.slf", TRUE, TRUE },
|
||||
|
||||
#ifdef GERMAN
|
||||
{ "German.slf", FALSE, TRUE },
|
||||
#endif
|
||||
|
||||
#ifdef POLISH
|
||||
{ "Polish.slf", FALSE, TRUE },
|
||||
#endif
|
||||
|
||||
#ifdef DUTCH
|
||||
{ "Dutch.slf", FALSE, TRUE },
|
||||
#endif
|
||||
|
||||
#ifdef ITALIAN
|
||||
{ "Italian.slf", FALSE, TRUE },
|
||||
#endif
|
||||
|
||||
#ifdef RUSSIAN
|
||||
{ "Russian.slf", FALSE, TRUE },
|
||||
#endif
|
||||
|
||||
#ifdef FRENCH
|
||||
{ "French.slf", FALSE, TRUE },
|
||||
#endif
|
||||
|
||||
#ifdef CHINESE
|
||||
{ "Chinese.slf", FALSE, TRUE },
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef _JA2_LIBS_H_
|
||||
#define _JA2_LIBS_H_
|
||||
|
||||
|
||||
//enums used for accessing the libraries
|
||||
enum
|
||||
{
|
||||
LIBRARY_DATA,
|
||||
LIBRARY_EDITOR,
|
||||
LIBRARY_AMBIENT,
|
||||
LIBRARY_ANIMS,
|
||||
LIBRARY_BATTLESNDS,
|
||||
LIBRARY_BIGITEMS,
|
||||
LIBRARY_BINARY_DATA,
|
||||
LIBRARY_CURSORS,
|
||||
LIBRARY_FACES,
|
||||
LIBRARY_FONTS,
|
||||
LIBRARY_INTERFACE,
|
||||
LIBRARY_LAPTOP,
|
||||
LIBRARY_MAPS,
|
||||
LIBRARY_MERCEDT,
|
||||
LIBRARY_MUSIC,
|
||||
LIBRARY_NPC_SPEECH,
|
||||
LIBRARY_NPC_DATA,
|
||||
LIBRARY_RADAR_MAPS,
|
||||
LIBRARY_SOUNDS,
|
||||
LIBRARY_SPEECH,
|
||||
// LIBRARY_TILE_CACHE,
|
||||
LIBRARY_TILESETS,
|
||||
LIBRARY_LOADSCREENS,
|
||||
LIBRARY_INTRO,
|
||||
|
||||
#ifdef GERMAN
|
||||
LIBRARY_GERMAN_DATA,
|
||||
#endif
|
||||
|
||||
#ifdef DUTCH
|
||||
LIBRARY_DUTCH_DATA,
|
||||
#endif
|
||||
|
||||
#ifdef POLISH
|
||||
LIBRARY_POLISH_DATA,
|
||||
#endif
|
||||
|
||||
#ifdef ITALIAN
|
||||
LIBRARY_ITALIAN_DATA,
|
||||
#endif
|
||||
|
||||
#ifdef RUSSIAN
|
||||
LIBRARY_RUSSIAN_DATA,
|
||||
#endif
|
||||
|
||||
#ifdef FRENCH
|
||||
LIBRARY_FRENCH_DATA,
|
||||
#endif
|
||||
|
||||
NUMBER_OF_LIBRARIES
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,208 @@
|
||||
#ifndef _LIBRARY_DATABASE_H
|
||||
#define _LIBRARY_DATABASE_H
|
||||
|
||||
#include "Types.h"
|
||||
#include "windows.h"
|
||||
#include "FileMan.h"
|
||||
|
||||
#define FILENAME_SIZE 256
|
||||
|
||||
//#define FILENAME_SIZE 40 + PATH_SIZE
|
||||
#define PATH_SIZE 80
|
||||
|
||||
|
||||
#define NUM_FILES_TO_ADD_AT_A_TIME 20
|
||||
#define INITIAL_NUM_HANDLES 20
|
||||
|
||||
|
||||
#define REAL_FILE_LIBRARY_ID 1022
|
||||
|
||||
#define DB_BITS_FOR_LIBRARY 10
|
||||
#define DB_BITS_FOR_FILE_ID 22
|
||||
|
||||
#define DB_EXTRACT_LIBRARY( exp ) ( exp >> DB_BITS_FOR_FILE_ID )
|
||||
#define DB_EXTRACT_FILE_ID( exp ) ( exp & 0x3FFFFF )
|
||||
|
||||
#define DB_ADD_LIBRARY_ID( exp ) ( exp << DB_BITS_FOR_FILE_ID )
|
||||
#define DB_ADD_FILE_ID( exp ) ( exp & 0xC00000 )
|
||||
|
||||
typedef UINT32 HWFILE;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CHAR8 sLibraryName[ FILENAME_SIZE ]; // The name of the library file on the disk
|
||||
BOOLEAN fOnCDrom; // A flag specifying if its a cdrom library ( not implemented yet )
|
||||
BOOLEAN fInitOnStart; // Flag specifying if the library is to Initialized at the begining of the game
|
||||
|
||||
} LibraryInitHeader;
|
||||
|
||||
|
||||
|
||||
|
||||
#include "Ja2 Libs.h"
|
||||
|
||||
extern LibraryInitHeader gGameLibaries[];
|
||||
extern CHAR8 gzCdDirectory[ SGPFILENAME_LEN ];
|
||||
|
||||
|
||||
#define REAL_LIBRARY_FILE "RealFiles.slf"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT32 uiFileID; // id of the file ( they start at 1 )
|
||||
HANDLE hRealFileHandle; // if the file is a Real File, this its handle
|
||||
} RealFileOpenStruct;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
STR pFileName;
|
||||
UINT32 uiFileLength;
|
||||
UINT32 uiFileOffset;
|
||||
} FileHeaderStruct;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT32 uiFileID; // id of the file ( they start at 1 )
|
||||
UINT32 uiFilePosInFile; // current position in the file
|
||||
UINT32 uiActualPositionInLibrary; // Current File pointer position in actuall library
|
||||
FileHeaderStruct *pFileHeader;
|
||||
} FileOpenStruct;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
STR sLibraryPath;
|
||||
HANDLE hLibraryHandle;
|
||||
UINT16 usNumberOfEntries;
|
||||
BOOLEAN fLibraryOpen;
|
||||
// BOOLEAN fAnotherFileAlreadyOpenedLibrary; //this variable is set when a file is opened from the library and reset when the file is close. No 2 files can have access to the library at 1 time.
|
||||
UINT32 uiIdOfOtherFileAlreadyOpenedLibrary; //this variable is set when a file is opened from the library and reset when the file is close. No 2 files can have access to the library at 1 time.
|
||||
INT32 iNumFilesOpen;
|
||||
INT32 iSizeOfOpenFileArray;
|
||||
FileHeaderStruct *pFileHeader;
|
||||
FileOpenStruct *pOpenFiles;
|
||||
|
||||
//
|
||||
// Temp: Total memory used for each library ( all memory allocated
|
||||
//
|
||||
#ifdef JA2TESTVERSION
|
||||
UINT32 uiTotalMemoryAllocatedForLibrary;
|
||||
#endif
|
||||
|
||||
} LibraryHeaderStruct;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
INT32 iNumFilesOpen;
|
||||
INT32 iSizeOfOpenFileArray;
|
||||
RealFileOpenStruct *pRealFilesOpen;
|
||||
|
||||
} RealFileHeaderStruct;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
STR sManagerName;
|
||||
LibraryHeaderStruct *pLibraries;
|
||||
UINT16 usNumberOfLibraries;
|
||||
BOOLEAN fInitialized;
|
||||
RealFileHeaderStruct RealFiles;
|
||||
} DatabaseManagerHeaderStruct;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//typedef UINT32 HLIBFILE;
|
||||
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
// NOTE! The following structs are also used by the datalib98 utility
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
||||
#define FILE_OK 0
|
||||
#define FILE_DELETED 0xff
|
||||
#define FILE_OLD 1
|
||||
#define FILE_DOESNT_EXIST 0xfe
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CHAR8 sLibName[ FILENAME_SIZE ];
|
||||
CHAR8 sPathToLibrary[ FILENAME_SIZE ];
|
||||
INT32 iEntries;
|
||||
INT32 iUsed;
|
||||
UINT16 iSort;
|
||||
UINT16 iVersion;
|
||||
BOOLEAN fContainsSubDirectories;
|
||||
INT32 iReserved;
|
||||
} LIBHEADER;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CHAR8 sFileName[ FILENAME_SIZE ];
|
||||
UINT32 uiOffset;
|
||||
UINT32 uiLength;
|
||||
UINT8 ubState;
|
||||
UINT8 ubReserved;
|
||||
FILETIME sFileTime;
|
||||
UINT16 usReserved2;
|
||||
} DIRENTRY;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//The FileDatabaseHeader
|
||||
extern DatabaseManagerHeaderStruct gFileDataBase;
|
||||
|
||||
|
||||
|
||||
//Function Prototypes
|
||||
|
||||
BOOLEAN CheckForLibraryExistence( STR pLibraryName );
|
||||
BOOLEAN InitializeLibrary( STR pLibraryName, LibraryHeaderStruct *pLibheader, BOOLEAN fCanBeOnCDrom );
|
||||
|
||||
BOOLEAN InitializeFileDatabase( );
|
||||
BOOLEAN ReopenCDLibraries(void);
|
||||
BOOLEAN ShutDownFileDatabase( );
|
||||
BOOLEAN CheckIfFileExistInLibrary( STR pFileName );
|
||||
INT16 GetLibraryIDFromFileName( STR pFileName );
|
||||
HWFILE OpenFileFromLibrary( STR pName );
|
||||
HWFILE CreateRealFileHandle( HANDLE hFile );
|
||||
BOOLEAN CloseLibraryFile( INT16 sLibraryID, UINT32 uiFileID );
|
||||
BOOLEAN GetLibraryAndFileIDFromLibraryFileHandle( HWFILE hlibFile, INT16 *pLibraryID, UINT32 *pFileNum );
|
||||
BOOLEAN LoadDataFromLibrary( INT16 sLibraryID, UINT32 uiFileIndex, PTR pData, UINT32 uiBytesToRead, UINT32 *pBytesRead );
|
||||
BOOLEAN LibraryFileSeek( INT16 sLibraryID, UINT32 uiFileNum, UINT32 uiDistance, UINT8 uiHowToSeek );
|
||||
|
||||
|
||||
//used to open and close libraries during the game
|
||||
BOOLEAN CloseLibrary( INT16 sLibraryID );
|
||||
BOOLEAN OpenLibrary( INT16 sLibraryID );
|
||||
|
||||
BOOLEAN IsLibraryOpened( INT16 sLibraryID );
|
||||
|
||||
BOOLEAN GetLibraryFileTime( INT16 sLibraryID, UINT32 uiFileNum, SGP_FILETIME *pLastWriteTime );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
+742
@@ -0,0 +1,742 @@
|
||||
//**************************************************************************
|
||||
//
|
||||
// Filename : MemMan.cpp
|
||||
//
|
||||
// Purpose : function definitions for the memory manager
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 11sep96:HJH - Creation
|
||||
// 29may97:ARM - Fix & improve MemDebugCounter handling, logging of
|
||||
// MemAlloc/MemFree, and reporting of any errors
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#include "types.h"
|
||||
#include <windows.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "MemMan.h"
|
||||
#include "Debug.h"
|
||||
#include <stdio.h>
|
||||
#include "sgp_logger.h"
|
||||
#ifdef _DEBUG
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
//#define DEBUG_MEM_LEAKS // turns on tracking of every MemAlloc and MemFree!
|
||||
#endif
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Variables
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#include "MessageBoxScreen.h"
|
||||
STR16 gzJA2ScreenNames[] =
|
||||
{
|
||||
L"EDIT_SCREEN",
|
||||
L"SAVING_SCREEN",
|
||||
L"LOADING_SCREEN",
|
||||
L"ERROR_SCREEN",
|
||||
L"INIT_SCREEN",
|
||||
L"GAME_SCREEN",
|
||||
L"ANIEDIT_SCREEN",
|
||||
L"PALEDIT_SCREEN",
|
||||
L"DEBUG_SCREEN",
|
||||
L"MAP_SCREEN",
|
||||
L"LAPTOP_SCREEN",
|
||||
L"LOADSAVE_SCREEN",
|
||||
L"MAPUTILITY_SCREEN",
|
||||
L"FADE_SCREEN",
|
||||
L"MSG_BOX_SCREEN",
|
||||
L"MAINMENU_SCREEN",
|
||||
L"AUTORESOLVE_SCREEN",
|
||||
L"SAVE_LOAD_SCREEN",
|
||||
L"OPTIONS_SCREEN",
|
||||
L"SHOPKEEPER_SCREEN",
|
||||
L"SEX_SCREEN",
|
||||
L"GAME_INIT_OPTIONS_SCREEN",
|
||||
L"DEMO_EXIT_SCREEN",
|
||||
L"INTRO_SCREEN",
|
||||
L"CREDIT_SCREEN",
|
||||
#ifdef JA2BETAVERSION
|
||||
L"AIVIEWER_SCREEN",
|
||||
L"QUEST_DEBUG_SCREEN",
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef EXTREME_MEMORY_DEBUGGING
|
||||
typedef struct MEMORY_NODE
|
||||
{
|
||||
PTR pBlock;
|
||||
struct MEMORY_NODE *next, *prev;
|
||||
UINT8 *pCode;
|
||||
UINT32 uiSize;
|
||||
}MEMORY_NODE;
|
||||
|
||||
MEMORY_NODE *gpMemoryHead = NULL;
|
||||
MEMORY_NODE *gpMemoryTail = NULL;
|
||||
UINT32 guiMemoryNodes = 0;
|
||||
UINT32 guiTotalMemoryNodes = 0;
|
||||
#endif
|
||||
|
||||
static BOOLEAN gfMemDebug = TRUE;
|
||||
// debug variable for total memory currently allocated
|
||||
UINT32 guiMemTotal = 0;
|
||||
UINT32 guiMemAlloced = 0;
|
||||
UINT32 guiMemFreed = 0;
|
||||
UINT32 MemDebugCounter = 0;
|
||||
BOOLEAN fMemManagerInit = FALSE;
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
void DebugPrint( void );
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// MemInit
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 12sep96:HJH ->modified for use by Wizardry
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN InitializeMemoryManager( void )
|
||||
{
|
||||
// Register the memory manager with the debugger
|
||||
RegisterDebugTopic(TOPIC_MEMORY_MANAGER, "Memory Manager");
|
||||
MemDebugCounter = 0;
|
||||
guiMemTotal = 0;
|
||||
guiMemAlloced = 0;
|
||||
guiMemFreed = 0;
|
||||
fMemManagerInit = TRUE;
|
||||
|
||||
#ifdef EXTREME_MEMORY_DEBUGGING
|
||||
gpMemoryHead = NULL;
|
||||
gpMemoryTail = NULL;
|
||||
guiMemoryNodes = 0;
|
||||
guiTotalMemoryNodes = 0;
|
||||
#endif
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// MemDebug
|
||||
//
|
||||
// To set whether or not we should print debug info.
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 12sep96:HJH ->modified for use by Wizardry
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
void MemDebug( BOOLEAN f )
|
||||
{
|
||||
gfMemDebug = f;
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// MemShutdown
|
||||
//
|
||||
// Shuts down the memory manager.
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 12sep96:HJH ->modified for use by Wizardry
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
void ShutdownMemoryManager( void )
|
||||
{
|
||||
if ( MemDebugCounter != 0 )
|
||||
{
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" "));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" "));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" >>>>> MEMORY LEAK DETECTED!!! <<<<< "));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d memory blocks still allocated", MemDebugCounter ));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total STILL allocated", guiMemTotal ));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total was allocated", guiMemAlloced));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("%d bytes memory total was freed", guiMemFreed));
|
||||
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" "));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("***** WARNING - WARNING - WARNING *****"));
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String(" "));
|
||||
|
||||
#ifndef EXTREME_MEMORY_DEBUGGING
|
||||
#ifdef JA2BETAVERSION
|
||||
{
|
||||
sgp::Logger_ID log_id = sgp::Logger::instance().createLogger();
|
||||
sgp::Logger::LogInstance memLeak = SGP_LOG(log_id);
|
||||
memLeak << sgp::endl << sgp::endl;
|
||||
memLeak << ">>>>> MEMORY LEAK DETECTED!!! <<<<<" << sgp::endl;
|
||||
memLeak << " " << guiMemAlloced << " bytes memory total was allocated" << sgp::endl;
|
||||
memLeak << "- " << guiMemFreed << " bytes memory total was freed" << sgp::endl;
|
||||
memLeak << "_______________________________________________" << sgp::endl;
|
||||
memLeak << guiMemTotal << " bytes memory total STILL allocated" << sgp::endl;
|
||||
memLeak << MemDebugCounter << " memory blocks still allocated" << sgp::endl;
|
||||
memLeak << "guiScreenExitedFrom = " << gzJA2ScreenNames[ gMsgBox.uiExitScreen ] << sgp::endl;
|
||||
memLeak << sgp::endl << sgp::endl;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
UnRegisterDebugTopic( TOPIC_MEMORY_MANAGER, "Memory Manager Un-initialized" );
|
||||
|
||||
fMemManagerInit = FALSE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
PTR MemAllocReal( UINT32 uiSize, const STR8 pcFile, INT32 iLine )
|
||||
{
|
||||
PTR ptr;
|
||||
|
||||
if( !uiSize )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( !fMemManagerInit )
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAlloc: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) );
|
||||
|
||||
|
||||
ptr = _malloc_dbg( uiSize, _NORMAL_BLOCK, pcFile, iLine );
|
||||
if (ptr != NULL)
|
||||
{
|
||||
guiMemTotal += uiSize;
|
||||
guiMemAlloced += uiSize;
|
||||
MemDebugCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAlloc failed: %d bytes (line %d file %s)", uiSize, iLine, pcFile) );
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEM_LEAKS
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemAlloc %p: %d bytes (line %d file %s)", ptr, uiSize, iLine, pcFile) );
|
||||
#endif
|
||||
|
||||
return( ptr );
|
||||
}
|
||||
|
||||
|
||||
void MemFreeReal( PTR ptr, const STR8 pcFile, INT32 iLine )
|
||||
{
|
||||
UINT32 uiSize;
|
||||
|
||||
if ( !fMemManagerInit )
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFree: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) );
|
||||
|
||||
if (ptr != NULL)
|
||||
{
|
||||
uiSize = _msize(ptr);
|
||||
guiMemTotal -= uiSize;
|
||||
guiMemFreed += uiSize;
|
||||
_free_dbg( ptr, _NORMAL_BLOCK );
|
||||
|
||||
#ifdef DEBUG_MEM_LEAKS
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemFree %p: %d bytes (line %d file %s)", ptr, uiSize, iLine, pcFile) );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFree ERROR: NULL ptr received (line %d file %s)", iLine, pcFile) );
|
||||
}
|
||||
|
||||
// count even a NULL ptr as a MemFree, not because it's really a memory leak, but because it is still an error of some
|
||||
// sort (nobody should ever be freeing NULL pointers), and this will help in tracking it down if the above DbgMessage
|
||||
// is not noticed.
|
||||
MemDebugCounter--;
|
||||
}
|
||||
|
||||
|
||||
PTR MemReallocReal( PTR ptr, UINT32 uiSize, const STR8 pcFile, INT32 iLine )
|
||||
{
|
||||
PTR ptrNew;
|
||||
UINT32 uiOldSize = 0;
|
||||
|
||||
|
||||
if ( !fMemManagerInit )
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemRealloc: Warning -- Memory manager not initialized -- Line %d in %s", iLine, pcFile) );
|
||||
|
||||
if(ptr != NULL)
|
||||
{
|
||||
uiOldSize = _msize(ptr);
|
||||
guiMemTotal -= uiOldSize;
|
||||
guiMemFreed += uiOldSize;
|
||||
MemDebugCounter--;
|
||||
}
|
||||
|
||||
// Note that the ptr changes to ptrNew...
|
||||
ptrNew = _realloc_dbg( ptr, uiSize, _NORMAL_BLOCK, pcFile, iLine );
|
||||
if (ptrNew == NULL)
|
||||
{
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemReAlloc failed: ptr %d, %d->%d bytes (line %d file %s)", ptr, uiOldSize, uiSize, iLine, pcFile) );
|
||||
if ( uiSize != 0 )
|
||||
{
|
||||
// ptr is left untouched, so undo the math above
|
||||
guiMemTotal += uiOldSize;
|
||||
guiMemFreed -= uiOldSize;
|
||||
MemDebugCounter++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_MEM_LEAKS
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemRealloc %p: Resizing %d bytes to %d bytes (line %d file %s) - New ptr %p", ptr, uiOldSize, uiSize, iLine, pcFile, ptrNew ) );
|
||||
#endif
|
||||
|
||||
guiMemTotal += uiSize;
|
||||
guiMemAlloced += uiSize;
|
||||
MemDebugCounter++;
|
||||
}
|
||||
|
||||
return( ptrNew );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
PTR MemAllocLocked( UINT32 uiSize )
|
||||
{
|
||||
PTR ptr;
|
||||
|
||||
if ( !fMemManagerInit )
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAllocLocked: Warning -- Memory manager not initialized!!! ") );
|
||||
|
||||
|
||||
ptr = VirtualAlloc( NULL, uiSize, MEM_COMMIT, PAGE_READWRITE );
|
||||
|
||||
if ( ptr )
|
||||
{
|
||||
VirtualLock( ptr, uiSize );
|
||||
|
||||
guiMemTotal += uiSize;
|
||||
guiMemAlloced += uiSize;
|
||||
MemDebugCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAllocLocked failed: %d bytes", uiSize) );
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEM_LEAKS
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemAllocLocked %p: %d bytes", ptr, uiSize) );
|
||||
#endif
|
||||
|
||||
return( ptr );
|
||||
}
|
||||
|
||||
|
||||
void MemFreeLocked( PTR ptr, UINT32 uiSize )
|
||||
{
|
||||
if ( !fMemManagerInit )
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFreeLocked: Warning -- Memory manager not initialized!!! ") );
|
||||
|
||||
|
||||
if (ptr != NULL)
|
||||
{
|
||||
VirtualUnlock( ptr, uiSize );
|
||||
VirtualFree( ptr, 0, MEM_RELEASE );
|
||||
|
||||
guiMemTotal -= uiSize;
|
||||
guiMemFreed += uiSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemFreeLocked ERROR: NULL ptr received, size %d", uiSize) );
|
||||
}
|
||||
|
||||
// count even a NULL ptr as a MemFree, not because it's really a memory leak, but because it is still an error of some
|
||||
// sort (nobody should ever be freeing NULL pointers), and this will help in tracking it down if the above DbgMessage
|
||||
// is not noticed.
|
||||
MemDebugCounter--;
|
||||
|
||||
#ifdef DEBUG_MEM_LEAKS
|
||||
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemFreeLocked %p", ptr) );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// MemGetFree
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// ??sep96:HJH ->modified for use by Wizardry
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
UINT32 MemGetFree( void )
|
||||
{
|
||||
MEMORYSTATUS ms;
|
||||
|
||||
ms.dwLength = sizeof(MEMORYSTATUS);
|
||||
GlobalMemoryStatus( &ms );
|
||||
|
||||
return( ms.dwAvailPhys );
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// MemGetTotalSystem
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// May98:HJH ->Carter
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
UINT32 MemGetTotalSystem( void )
|
||||
{
|
||||
MEMORYSTATUS ms;
|
||||
|
||||
ms.dwLength = sizeof(MEMORYSTATUS);
|
||||
GlobalMemoryStatus( &ms );
|
||||
|
||||
return( ms.dwTotalPhys );
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// MemCheckPool
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 23sep96:HJH ->modified for use by Wizardry
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN MemCheckPool( void )
|
||||
{
|
||||
BOOLEAN fRet = TRUE;
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
fRet = _CrtCheckMemory();
|
||||
Assert( fRet );
|
||||
|
||||
#endif
|
||||
|
||||
return(fRet);
|
||||
}
|
||||
|
||||
#ifdef EXTREME_MEMORY_DEBUGGING
|
||||
|
||||
PTR MemAllocXDebug( UINT32 size, const STR8 szCodeString, INT32 iLineNum, void *pSpecial )
|
||||
{
|
||||
PTR ptr;
|
||||
UINT16 usLength;
|
||||
CHAR8 str[70];
|
||||
STR8 pStr;
|
||||
|
||||
if( !size )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( !pSpecial )
|
||||
{
|
||||
ptr = malloc( size );
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = pSpecial;
|
||||
}
|
||||
|
||||
if( ptr )
|
||||
{
|
||||
// Set into video object list
|
||||
if( gpMemoryHead )
|
||||
{ //Add node after tail
|
||||
gpMemoryTail->next = (MEMORY_NODE*)malloc( sizeof( MEMORY_NODE ) );
|
||||
Assert( gpMemoryTail->next ); //out of memory?
|
||||
gpMemoryTail->next->prev = gpMemoryTail;
|
||||
gpMemoryTail->next->next = NULL;
|
||||
gpMemoryTail = gpMemoryTail->next;
|
||||
}
|
||||
else
|
||||
{ //new list
|
||||
gpMemoryHead = (MEMORY_NODE*)malloc( sizeof( MEMORY_NODE ) );
|
||||
Assert( gpMemoryHead ); //out of memory?
|
||||
gpMemoryHead->prev = gpMemoryHead->next = NULL;
|
||||
gpMemoryTail = gpMemoryHead;
|
||||
}
|
||||
|
||||
//record the code location of the calling creating function.
|
||||
pStr = strrchr( szCodeString, '\\' );
|
||||
pStr++;
|
||||
sprintf( str, "%s -- line(%d)", pStr, iLineNum );
|
||||
usLength = strlen( str ) + 1;
|
||||
gpMemoryTail->pCode = (UINT8*)malloc( usLength );
|
||||
memset( gpMemoryTail->pCode, 0, usLength );
|
||||
strcpy( (STR8)gpMemoryTail->pCode, str );
|
||||
|
||||
//record the size
|
||||
gpMemoryTail->uiSize = size;
|
||||
|
||||
//Set the hVObject into the node.
|
||||
gpMemoryTail->pBlock = ptr;
|
||||
|
||||
guiMemoryNodes++;
|
||||
guiTotalMemoryNodes++;
|
||||
}
|
||||
return( ptr );
|
||||
}
|
||||
|
||||
void MemFreeXDebug( PTR ptr, const STR8 szCodeString, INT32 iLineNum, void *pSpecial )
|
||||
{
|
||||
MEMORY_NODE *curr;
|
||||
|
||||
if( ptr )
|
||||
{
|
||||
curr = gpMemoryHead;
|
||||
while( curr )
|
||||
{
|
||||
if( curr->pBlock == ptr )
|
||||
{ //Found the node, so detach it and delete it.
|
||||
|
||||
if( !pSpecial )
|
||||
{
|
||||
free( ptr );
|
||||
}
|
||||
|
||||
if( curr == gpMemoryHead )
|
||||
{ //Advance the head, because we are going to remove the head node.
|
||||
gpMemoryHead = gpMemoryHead->next;
|
||||
}
|
||||
if( curr == gpMemoryTail )
|
||||
{ //Back up the tail, because we are going to remove the tail node.
|
||||
gpMemoryTail = gpMemoryTail->prev;
|
||||
}
|
||||
//Detach the node from the vobject list
|
||||
if( curr->next )
|
||||
{ //Make the prev node point to the next
|
||||
curr->next->prev = curr->prev;
|
||||
}
|
||||
if( curr->prev )
|
||||
{ //Make the next node point to the prev
|
||||
curr->prev->next = curr->next;
|
||||
}
|
||||
//The node is now detached. Now deallocate it.
|
||||
free( curr );
|
||||
curr = NULL;
|
||||
guiMemoryNodes--;
|
||||
return;
|
||||
}
|
||||
curr = curr->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PTR MemReallocXDebug( PTR ptr, UINT32 size, const STR8 szCodeString, INT32 iLineNum, void *pSpecial )
|
||||
{
|
||||
MEMORY_NODE *curr;
|
||||
PTR ptrNew;
|
||||
UINT16 usLength;
|
||||
CHAR8 str[70];
|
||||
STR8 pStr;
|
||||
|
||||
if( !ptr && size )
|
||||
{
|
||||
return MemAllocXDebug( size, szCodeString, iLineNum, pSpecial );
|
||||
}
|
||||
|
||||
curr = gpMemoryHead;
|
||||
while( curr )
|
||||
{
|
||||
if( curr->pBlock == ptr )
|
||||
{
|
||||
// Note that the ptr changes to ptrNew...
|
||||
if( !pSpecial )
|
||||
{
|
||||
ptrNew = realloc( ptr, size );
|
||||
}
|
||||
else
|
||||
{
|
||||
ptrNew = pSpecial;
|
||||
}
|
||||
|
||||
if( ptrNew )
|
||||
{
|
||||
curr->pBlock = ptrNew;
|
||||
curr->uiSize = size;
|
||||
|
||||
free( curr->pCode );
|
||||
|
||||
//record the code location of the calling creating function.
|
||||
pStr = strrchr( szCodeString, '\\' );
|
||||
pStr++;
|
||||
sprintf( str, "%s -- line(%d)", pStr, iLineNum );
|
||||
usLength = strlen( str ) + 1;
|
||||
curr->pCode = (UINT8*)malloc( usLength );
|
||||
memset( curr->pCode, 0, usLength );
|
||||
strcpy( (STR8)curr->pCode, str );
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = ptr;
|
||||
}
|
||||
return ptrNew;
|
||||
}
|
||||
curr = curr->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct DUMPFILENAME
|
||||
{
|
||||
UINT8 str[70];
|
||||
}DUMPFILENAME;
|
||||
|
||||
void DumpMemoryInfoIntoFile( CHAR8 *filename, BOOLEAN fAppend )
|
||||
{
|
||||
MEMORY_NODE *curr;
|
||||
FILE *fp;
|
||||
DUMPFILENAME *pCode;
|
||||
UINT32 *puiCounter, *puiSize;
|
||||
CHAR8 tempCode[ 70 ];
|
||||
UINT32 i, uiUniqueID, uiTotalKbWasted = 0, uiBytesRemainder = 0;
|
||||
BOOLEAN fFound;
|
||||
|
||||
if( fAppend )
|
||||
{
|
||||
fp = fopen( filename, "a" );
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = fopen( filename, "w" );
|
||||
}
|
||||
Assert( fp );
|
||||
|
||||
if( !guiMemoryNodes )
|
||||
{
|
||||
fprintf( fp, "NO MEMORY LEAKS DETECTED! CONGRATULATIONS!\n" );
|
||||
fclose( fp );
|
||||
return;
|
||||
}
|
||||
|
||||
//Allocate enough strings and counters for each node.
|
||||
pCode = (DUMPFILENAME*)malloc( sizeof( DUMPFILENAME ) * guiMemoryNodes );
|
||||
memset( pCode, 0, sizeof( DUMPFILENAME ) * guiMemoryNodes );
|
||||
puiSize = (UINT32*)malloc( 4 * guiMemoryNodes );
|
||||
memset( puiSize, 0, 4 * guiMemoryNodes );
|
||||
puiCounter = (UINT32*)malloc( 4 * guiMemoryNodes );
|
||||
memset( puiCounter, 0, 4 * guiMemoryNodes );
|
||||
|
||||
//Loop through the list and record every unique filename and count them
|
||||
uiUniqueID = 0;
|
||||
curr = gpMemoryHead;
|
||||
while( curr )
|
||||
{
|
||||
strcpy( tempCode, (CHAR8*)curr->pCode );
|
||||
fFound = FALSE;
|
||||
for( i = 0; i < uiUniqueID; i++ )
|
||||
{
|
||||
if( !_stricmp( tempCode, (CHAR8*)pCode[i].str ) )
|
||||
{ //same string
|
||||
fFound = TRUE;
|
||||
(puiCounter[ i ])++;
|
||||
(puiSize[ i ]) += curr->uiSize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !fFound )
|
||||
{
|
||||
strcpy( (CHAR8*)pCode[i].str, tempCode );
|
||||
(puiSize[ i ]) += curr->uiSize;
|
||||
(puiCounter[ i ])++;
|
||||
uiUniqueID++;
|
||||
}
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
//Now dump the info.
|
||||
fprintf( fp, "--------------------------------------------------------------------------------\n" );
|
||||
fprintf( fp, "%d unique memory allocation locations exist in %d memory nodes\n", uiUniqueID, guiMemoryNodes );
|
||||
fprintf( fp, "--------------------------------------------------------------------------------\n" );
|
||||
for( i = 0; i < uiUniqueID; i++ )
|
||||
{
|
||||
fprintf( fp, "%d occurrences of %s (total size %d bytes)\n", puiCounter[i], pCode[i].str, puiSize[i] );
|
||||
uiBytesRemainder += puiSize[i];
|
||||
if( uiBytesRemainder >= 1024 )
|
||||
{
|
||||
uiTotalKbWasted += uiBytesRemainder/1024;
|
||||
uiBytesRemainder %= 1024;
|
||||
}
|
||||
}
|
||||
fprintf( fp, "--------------------------------------------------------------------------------\n" );
|
||||
fprintf( fp, "%dKB of memory total wasn't cleaned up!\n", uiTotalKbWasted );
|
||||
fprintf( fp, "--------------------------------------------------------------------------------\n" );
|
||||
|
||||
fclose( fp );
|
||||
|
||||
//Free all memory associated with this operation.
|
||||
free( pCode );
|
||||
free( puiCounter );
|
||||
free( puiSize );
|
||||
}
|
||||
|
||||
BOOLEAN _AddAndRecordMemAlloc( UINT32 size, UINT32 uiLineNum, UINT8 *pSourceFile )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
//**************************************************************************
|
||||
//
|
||||
// Filename : MemMan.h
|
||||
//
|
||||
// Purpose : prototypes for the memory manager
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 11sep96:HJH - Creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#ifndef _MEMMAN_H
|
||||
#define _MEMMAN_H
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#include "types.h"
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Typedefs
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern UINT32 MemDebugCounter;
|
||||
extern UINT32 guiMemTotal;
|
||||
extern UINT32 guiMemAlloced;
|
||||
extern UINT32 guiMemFreed;
|
||||
|
||||
extern BOOLEAN InitializeMemoryManager( void );
|
||||
extern void MemDebug( BOOLEAN f );
|
||||
extern void ShutdownMemoryManager( void );
|
||||
|
||||
// Creates and adds a video object to list
|
||||
#ifdef EXTREME_MEMORY_DEBUGGING
|
||||
//This is the most effective way to debug memory leaks. Each memory leak will be recorded in a linked
|
||||
//list containing a string referring to the location in code the memory was allocated in addition to
|
||||
//the number of occurrences. The shutdown code will report all unhandled memory with exact location allocated.
|
||||
void DumpMemoryInfoIntoFile( CHAR8 *filename, BOOLEAN fAppend );
|
||||
BOOLEAN _AddAndRecordMemAlloc( UINT32 size, UINT32 uiLineNum, UINT8 *pSourceFile );
|
||||
#define MemAlloc( size ) MemAllocXDebug( (size), __FILE__, __LINE__, NULL )
|
||||
#define MemFree( ptr ) MemFreeXDebug( (ptr), __FILE__, __LINE__, NULL )
|
||||
#define MemRealloc( ptr, size ) MemReallocXDebug( (ptr), (size), __FILE__, __LINE__, NULL )
|
||||
extern PTR MemAllocXDebug( UINT32 size, const STR8 szCodeString, INT32 iLineNum, void *pSpecial );
|
||||
extern void MemFreeXDebug( PTR ptr, const STR8 szCodeString, INT32 iLineNum, void *pSpecial );
|
||||
extern PTR MemReallocXDebug( PTR ptr, UINT32 size, const STR8 szCodeString, INT32 iLineNum, void *pSpecial );
|
||||
#else
|
||||
#ifdef _DEBUG
|
||||
#include <crtdbg.h>
|
||||
//This is another debug feature. Not as sophistocated, but definately not the pig the extreme system is.
|
||||
//This system reports all memory allocations/deallocations in the debug output.
|
||||
#define MemAlloc( size ) MemAllocReal( (size), __FILE__, __LINE__ )
|
||||
#define MemFree( ptr ) MemFreeReal( (ptr), __FILE__, __LINE__ )
|
||||
#define MemRealloc( ptr, size ) MemReallocReal( (ptr), (size), __FILE__, __LINE__ )
|
||||
extern PTR MemAllocReal( UINT32 size, const STR8 , INT32 );
|
||||
extern void MemFreeReal( PTR ptr, const STR8 , INT32 );
|
||||
extern PTR MemReallocReal( PTR ptr, UINT32 size, const STR8 , INT32 );
|
||||
//void* ::operator new( size_t sz, const char* file, int line);
|
||||
//void* ::operator new[]( size_t sz, const char *file, int line);
|
||||
#define NEW new
|
||||
#define new NEW(_NORMAL_BLOCK, __FILE__, __LINE__)
|
||||
#else
|
||||
//Release build verison
|
||||
#include <malloc.h>
|
||||
#define MemAlloc( size ) malloc( (size) )
|
||||
#define MemFree( ptr ) free( (ptr) )
|
||||
#define MemRealloc( ptr, size ) realloc( (ptr), (size) )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
extern PTR MemAllocLocked( UINT32 size );
|
||||
extern void MemFreeLocked( PTR, UINT32 size );
|
||||
|
||||
// get total free on the system at this moment
|
||||
extern UINT32 MemGetFree( void );
|
||||
|
||||
// get the total on the system
|
||||
extern UINT32 MemGetTotalSystem( void );
|
||||
|
||||
extern BOOLEAN MemCheckPool( void );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
+4082
File diff suppressed because it is too large
Load Diff
+375
@@ -0,0 +1,375 @@
|
||||
#include <stdio.h>
|
||||
#include "pcx.h"
|
||||
#include "memman.h"
|
||||
#include "fileman.h"
|
||||
|
||||
// Local typedefs
|
||||
|
||||
#define PCX_NORMAL 1
|
||||
#define PCX_RLE 2
|
||||
#define PCX_256COLOR 4
|
||||
#define PCX_TRANSPARENT 8
|
||||
#define PCX_CLIPPED 16
|
||||
#define PCX_REALIZEPALETTE 32
|
||||
#define PCX_X_CLIPPING 64
|
||||
#define PCX_Y_CLIPPING 128
|
||||
#define PCX_NOTLOADED 256
|
||||
|
||||
#define PCX_ERROROPENING 1
|
||||
#define PCX_INVALIDFORMAT 2
|
||||
#define PCX_INVALIDLEN 4
|
||||
#define PCX_OUTOFMEMORY 8
|
||||
|
||||
|
||||
BOOLEAN SetPcxPalette( PcxObject *pCurrentPcxObject, HIMAGE hImage );
|
||||
BOOLEAN BlitPcxToBuffer( PcxObject *pCurrentPcxObject, UINT8 *pBuffer, UINT16 usBufferWidth, UINT16 usBufferHeight, UINT16 usX, UINT16 usY, BOOLEAN fTransp);
|
||||
PcxObject *LoadPcx(STR8 pFilename);
|
||||
|
||||
|
||||
BOOLEAN LoadPCXFileToImage( HIMAGE hImage, UINT16 fContents )
|
||||
{
|
||||
PcxObject *pPcxObject;
|
||||
|
||||
// First Load a PCX Image
|
||||
pPcxObject = LoadPcx( hImage->ImageFile );
|
||||
|
||||
if ( pPcxObject == NULL )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Set some header information
|
||||
hImage->usWidth = pPcxObject->usWidth;
|
||||
hImage->usHeight = pPcxObject->usHeight;
|
||||
hImage->ubBitDepth = 8;
|
||||
hImage->fFlags = hImage->fFlags | fContents;
|
||||
|
||||
// Read and allocate bitmap block if requested
|
||||
if ( fContents & IMAGE_BITMAPDATA )
|
||||
{
|
||||
// Allocate memory for buffer
|
||||
hImage->p8BPPData = (UINT8 *) MemAlloc( hImage->usWidth * hImage->usHeight );
|
||||
|
||||
if ( !BlitPcxToBuffer( pPcxObject, hImage->p8BPPData, hImage->usWidth, hImage->usHeight, 0, 0, FALSE ) )
|
||||
{
|
||||
MemFree( hImage->p8BPPData );
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
if ( fContents & IMAGE_PALETTE )
|
||||
{
|
||||
SetPcxPalette( pPcxObject, hImage );
|
||||
|
||||
// Create 16 BPP palette if flags and BPP justify
|
||||
hImage->pui16BPPPalette = Create16BPPPalette( hImage->pPalette );
|
||||
|
||||
}
|
||||
|
||||
// Free and remove pcx object
|
||||
MemFree( pPcxObject->pPcxBuffer );
|
||||
MemFree( pPcxObject );
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
|
||||
PcxObject *LoadPcx(STR8 pFilename)
|
||||
{
|
||||
PcxHeader Header;
|
||||
PcxObject *pCurrentPcxObject;
|
||||
HWFILE hFileHandle;
|
||||
UINT32 uiFileSize;
|
||||
UINT8 *pPcxBuffer;
|
||||
|
||||
// Open and read in the file
|
||||
if ((hFileHandle = FileOpen(pFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE)) == 0)
|
||||
{ // damn we failed to open the file
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uiFileSize = FileGetSize(hFileHandle);
|
||||
if (uiFileSize == 0)
|
||||
{ // we failed to size up the file
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create enw pCX object
|
||||
pCurrentPcxObject = (PcxObject *) MemAlloc( sizeof( PcxObject ) );
|
||||
|
||||
if ( pCurrentPcxObject == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
pCurrentPcxObject->pPcxBuffer = (UINT8 *) MemAlloc( uiFileSize - (sizeof(PcxHeader) + 768) );
|
||||
|
||||
if ( pCurrentPcxObject->pPcxBuffer == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
// Ok we now have a file handle, so let's read in the data
|
||||
FileRead(hFileHandle, &Header, sizeof(PcxHeader), NULL);
|
||||
if ((Header.ubManufacturer != 10)||(Header.ubEncoding != 1))
|
||||
{ // We have an invalid pcx format
|
||||
// Delete the object
|
||||
MemFree( pCurrentPcxObject->pPcxBuffer );
|
||||
MemFree( pCurrentPcxObject );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if (Header.ubBitsPerPixel == 8)
|
||||
{
|
||||
pCurrentPcxObject->usPcxFlags = PCX_256COLOR;
|
||||
} else
|
||||
{
|
||||
pCurrentPcxObject->usPcxFlags = 0;
|
||||
}
|
||||
|
||||
pCurrentPcxObject->usWidth = 1 + (Header.usRight - Header.usLeft);
|
||||
pCurrentPcxObject->usHeight = 1 + (Header.usBottom - Header.usTop);
|
||||
pCurrentPcxObject->uiBufferSize = uiFileSize - 768 - sizeof(PcxHeader);
|
||||
|
||||
// We are ready to read in the pcx buffer data. Therefore we must lock the buffer
|
||||
pPcxBuffer = pCurrentPcxObject->pPcxBuffer;
|
||||
|
||||
FileRead(hFileHandle, pPcxBuffer, pCurrentPcxObject->uiBufferSize, NULL);
|
||||
|
||||
// Read in the palette
|
||||
FileRead(hFileHandle, &(pCurrentPcxObject->ubPalette[0]), 768, NULL);
|
||||
|
||||
// Close file
|
||||
FileClose( hFileHandle );
|
||||
|
||||
return pCurrentPcxObject;
|
||||
}
|
||||
|
||||
BOOLEAN BlitPcxToBuffer( PcxObject *pCurrentPcxObject, UINT8 *pBuffer, UINT16 usBufferWidth, UINT16 usBufferHeight, UINT16 usX, UINT16 usY, BOOLEAN fTransp)
|
||||
{
|
||||
UINT8 *pPcxBuffer;
|
||||
UINT8 ubRepCount;
|
||||
UINT16 usMaxX, usMaxY;
|
||||
UINT32 uiImageSize;
|
||||
UINT8 ubCurrentByte = 0;
|
||||
UINT8 ubMode;
|
||||
UINT16 usCurrentX, usCurrentY;
|
||||
UINT32 uiOffset, uiIndex;
|
||||
UINT32 uiNextLineOffset, uiStartOffset, uiCurrentOffset;
|
||||
|
||||
pPcxBuffer = pCurrentPcxObject->pPcxBuffer;
|
||||
|
||||
if (((pCurrentPcxObject->usWidth + usX) == usBufferWidth)&&((pCurrentPcxObject->usHeight + usY)== usBufferHeight))
|
||||
{ // Pre-compute PCX blitting aspects.
|
||||
uiImageSize = usBufferWidth * usBufferHeight;
|
||||
ubMode = PCX_NORMAL;
|
||||
uiOffset = 0;
|
||||
ubRepCount = 0;
|
||||
|
||||
// Blit Pcx object. Two main cases, one for transparency (0's are skipped and for without transparency.
|
||||
if (fTransp == TRUE)
|
||||
{
|
||||
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
|
||||
{
|
||||
if (ubMode == PCX_NORMAL)
|
||||
{
|
||||
ubCurrentByte = *(pPcxBuffer + uiOffset++);
|
||||
if (ubCurrentByte > 0x0BF)
|
||||
{
|
||||
ubRepCount = ubCurrentByte & 0x03F;
|
||||
ubCurrentByte = *(pPcxBuffer + uiOffset++);
|
||||
if (--ubRepCount > 0)
|
||||
{
|
||||
ubMode = PCX_RLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (--ubRepCount == 0)
|
||||
{
|
||||
ubMode = PCX_NORMAL;
|
||||
}
|
||||
}
|
||||
if (ubCurrentByte != 0)
|
||||
{
|
||||
*(pBuffer + uiIndex) = ubCurrentByte;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
|
||||
{
|
||||
if (ubMode == PCX_NORMAL)
|
||||
{
|
||||
ubCurrentByte = *(pPcxBuffer + uiOffset++);
|
||||
if (ubCurrentByte > 0x0BF)
|
||||
{
|
||||
ubRepCount = ubCurrentByte & 0x03F;
|
||||
ubCurrentByte = *(pPcxBuffer + uiOffset++);
|
||||
if (--ubRepCount > 0)
|
||||
{
|
||||
ubMode = PCX_RLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (--ubRepCount == 0)
|
||||
{ ubMode = PCX_NORMAL;
|
||||
}
|
||||
}
|
||||
*(pBuffer + uiIndex) = ubCurrentByte;
|
||||
}
|
||||
}
|
||||
} else
|
||||
{ // Pre-compute PCX blitting aspects.
|
||||
if ((pCurrentPcxObject->usWidth + usX) >= usBufferWidth)
|
||||
{
|
||||
pCurrentPcxObject->usPcxFlags |= PCX_X_CLIPPING;
|
||||
usMaxX = usBufferWidth - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
usMaxX = pCurrentPcxObject->usWidth + usX;
|
||||
}
|
||||
|
||||
if ((pCurrentPcxObject->usHeight + usY) >= usBufferHeight)
|
||||
{
|
||||
pCurrentPcxObject->usPcxFlags |= PCX_Y_CLIPPING;
|
||||
uiImageSize = pCurrentPcxObject->usWidth * (usBufferHeight - usY);
|
||||
usMaxY = usBufferHeight - 1;
|
||||
}
|
||||
else
|
||||
{ uiImageSize = pCurrentPcxObject->usWidth * pCurrentPcxObject->usHeight;
|
||||
usMaxY = pCurrentPcxObject->usHeight + usY;
|
||||
}
|
||||
|
||||
ubMode = PCX_NORMAL;
|
||||
uiOffset = 0;
|
||||
ubRepCount = 0;
|
||||
usCurrentX = usX;
|
||||
usCurrentY = usY;
|
||||
|
||||
// Blit Pcx object. Two main cases, one for transparency (0's are skipped and for without transparency.
|
||||
if (fTransp == TRUE)
|
||||
{
|
||||
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
|
||||
{
|
||||
if (ubMode == PCX_NORMAL)
|
||||
{
|
||||
ubCurrentByte = *(pPcxBuffer + uiOffset++);
|
||||
if (ubCurrentByte > 0x0BF)
|
||||
{
|
||||
ubRepCount = ubCurrentByte & 0x03F;
|
||||
ubCurrentByte = *(pPcxBuffer + uiOffset++);
|
||||
if (--ubRepCount > 0)
|
||||
{
|
||||
ubMode = PCX_RLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (--ubRepCount == 0)
|
||||
{ ubMode = PCX_NORMAL;
|
||||
}
|
||||
}
|
||||
if (ubCurrentByte != 0)
|
||||
{ *(pBuffer + (usCurrentY*usBufferWidth) + usCurrentX) = ubCurrentByte;
|
||||
}
|
||||
usCurrentX++;
|
||||
if (usCurrentX > usMaxX)
|
||||
{
|
||||
usCurrentX = usX;
|
||||
usCurrentY++;
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
uiStartOffset = (usCurrentY*usBufferWidth) + usCurrentX;
|
||||
uiNextLineOffset = uiStartOffset + usBufferWidth;
|
||||
uiCurrentOffset = uiStartOffset;
|
||||
|
||||
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
|
||||
{
|
||||
|
||||
if (ubMode == PCX_NORMAL)
|
||||
{
|
||||
ubCurrentByte = *(pPcxBuffer + uiOffset++);
|
||||
if (ubCurrentByte > 0x0BF)
|
||||
{
|
||||
ubRepCount = ubCurrentByte & 0x03F;
|
||||
ubCurrentByte = *(pPcxBuffer + uiOffset++);
|
||||
if (--ubRepCount > 0)
|
||||
{
|
||||
ubMode = PCX_RLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (--ubRepCount == 0)
|
||||
{
|
||||
ubMode = PCX_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (usCurrentX < usMaxX)
|
||||
{ // We are within the visible bounds so we write the byte to buffer
|
||||
*(pBuffer + uiCurrentOffset) = ubCurrentByte;
|
||||
uiCurrentOffset++;
|
||||
usCurrentX++;
|
||||
}
|
||||
else
|
||||
{ if ((uiCurrentOffset + 1)< uiNextLineOffset)
|
||||
{ // Increment the uiCurrentOffset
|
||||
uiCurrentOffset++;
|
||||
}
|
||||
else
|
||||
{ // Go to next line
|
||||
usCurrentX = usX;
|
||||
usCurrentY++;
|
||||
if (usCurrentY > usMaxY)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uiStartOffset = (usCurrentY*usBufferWidth) + usCurrentX;
|
||||
uiNextLineOffset = uiStartOffset + usBufferWidth;
|
||||
uiCurrentOffset = uiStartOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
BOOLEAN SetPcxPalette( PcxObject *pCurrentPcxObject, HIMAGE hImage )
|
||||
{
|
||||
UINT16 Index;
|
||||
UINT8 *pubPalette;
|
||||
|
||||
pubPalette = &(pCurrentPcxObject->ubPalette[0]);
|
||||
|
||||
// Allocate memory for palette
|
||||
hImage->pPalette = (SGPPaletteEntry *) MemAlloc( sizeof( SGPPaletteEntry ) * 256 );
|
||||
|
||||
if ( hImage->pPalette == NULL )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Initialize the proper palette entries
|
||||
for (Index = 0; Index < 256; Index++)
|
||||
{
|
||||
hImage->pPalette[ Index ].peRed = *(pubPalette+(Index*3));
|
||||
hImage->pPalette[ Index ].peGreen = *(pubPalette+(Index*3)+1);
|
||||
hImage->pPalette[ Index ].peBlue = *(pubPalette+(Index*3)+2);
|
||||
hImage->pPalette[ Index ].peFlags = 0;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,981 @@
|
||||
#include "PngLoader.h"
|
||||
#include "FileMan.h"
|
||||
#include "DEBUG.H"
|
||||
#include "vobject.h"
|
||||
#include "STIConvert.h"
|
||||
#include "MemMan.h"
|
||||
|
||||
#include <vfs/Core/vfs.h>
|
||||
#include <vfs/Core/vfs_file_raii.h>
|
||||
#include <vfs/Ext/7z/vfs_7z_library.h>
|
||||
#include <vfs/Core/Interface/vfs_location_interface.h>
|
||||
#include <vfs/Core/File/vfs_buffer_file.h>
|
||||
#include <vfs/Core/File/vfs_lib_file.h>
|
||||
|
||||
#include "XML_Parser.h"
|
||||
namespace png
|
||||
{
|
||||
# include <png.h>
|
||||
}
|
||||
|
||||
#include "sgp_auto_memory.h"
|
||||
|
||||
const vfs::String::str_t CONST_DOTPNG(L".png");
|
||||
const vfs::String::str_t CONST_DOTXML(L".xml");
|
||||
|
||||
void Load24bppPNGImage(HIMAGE hImage, png::png_bytepp rows, png::png_infop info);
|
||||
void Load32bppPNGImage(HIMAGE hImage, png::png_bytepp rows, png::png_infop info);
|
||||
void LoadPalettedPNGImage(HIMAGE hImage, png::png_bytepp rows, png::png_infop info);
|
||||
|
||||
|
||||
void user_read_data(png::png_structp png_ptr, png::png_bytep data, png::png_size_t length)
|
||||
{
|
||||
SGP_TRYCATCH_RETHROW( static_cast<vfs::tReadableFile*>(png_ptr->io_ptr)->read((vfs::Byte*)data,length),
|
||||
L"error during png file reading");
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/*******************************************************************************/
|
||||
|
||||
class IndexedSTIImage
|
||||
{
|
||||
public:
|
||||
IndexedSTIImage();
|
||||
~IndexedSTIImage();
|
||||
|
||||
bool setPalette(SGPPaletteEntry *pPal, int iSize);
|
||||
bool setPalette(png::png_colorp pPal, int iSize);
|
||||
bool addImage(UINT8 *data, UINT32 data_size, UINT32 image_width, UINT32 image_height, INT32 image_offset_x, INT32 image_offset_y, UINT8 *original_compressed=NULL, UINT32 original_compressed_size=0);
|
||||
|
||||
bool addCompressedImage(UINT8 *data, UINT32 data_size, UINT32 image_width, UINT32 image_height, INT32 image_offset_x, INT32 image_offset_y);
|
||||
|
||||
bool readAppDataFromXMLFile(HIMAGE hImage, vfs::tReadableFile* pFile);
|
||||
|
||||
bool writeImage(vfs::tWritableFile* pFile);
|
||||
bool writeToHIMAGE(HIMAGE pImage);
|
||||
private:
|
||||
STCIHeader _header;
|
||||
STCIPaletteElement* _palette;
|
||||
int _pal_size;
|
||||
std::vector<STCISubImage> _images;
|
||||
std::vector<std::vector<UINT8> > _compressed_images;
|
||||
};
|
||||
|
||||
IndexedSTIImage::IndexedSTIImage()
|
||||
: _palette(NULL)
|
||||
{
|
||||
memset(&_header, 0, sizeof(STCIHeader));
|
||||
}
|
||||
|
||||
IndexedSTIImage::~IndexedSTIImage()
|
||||
{
|
||||
if(_palette)
|
||||
{
|
||||
delete[] _palette;
|
||||
}
|
||||
for(unsigned int i=0; i < _compressed_images.size(); ++i)
|
||||
{
|
||||
//delete[] _compressed_images[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool IndexedSTIImage::setPalette(SGPPaletteEntry *pPal, int iSize)
|
||||
{
|
||||
if(iSize < 0 ||iSize > 1024)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pal_size = iSize;
|
||||
_palette = new STCIPaletteElement[iSize];
|
||||
for(int i=0; i<iSize;++i)
|
||||
{
|
||||
_palette[i].ubBlue = pPal[i].peBlue;
|
||||
_palette[i].ubGreen = pPal[i].peGreen;
|
||||
_palette[i].ubRed = pPal[i].peRed;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool IndexedSTIImage::setPalette(png::png_colorp pPal, int iSize)
|
||||
{
|
||||
if(iSize < 0 ||iSize > 1024)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pal_size = iSize;
|
||||
_palette = new STCIPaletteElement[iSize];
|
||||
for(int i=0; i<iSize;++i)
|
||||
{
|
||||
_palette[i].ubBlue = pPal[i].blue;
|
||||
_palette[i].ubGreen = pPal[i].green;
|
||||
_palette[i].ubRed = pPal[i].red;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IndexedSTIImage::addCompressedImage(UINT8 *data, UINT32 data_size, UINT32 image_width, UINT32 image_height, INT32 image_offset_x, INT32 image_offset_y)
|
||||
{
|
||||
if(!data || (data_size < 0) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
STCISubImage subimage;
|
||||
subimage.sOffsetX = image_offset_x;
|
||||
subimage.sOffsetY = image_offset_y;
|
||||
subimage.usWidth = image_width;
|
||||
subimage.usHeight = image_height;
|
||||
|
||||
UINT8 *compressed = new UINT8[data_size];
|
||||
memcpy(compressed,data,data_size);
|
||||
|
||||
subimage.uiDataLength = data_size;
|
||||
_header.uiStoredSize += data_size;
|
||||
_images.push_back(subimage);
|
||||
// _compressed_images.push_back(compressed);
|
||||
_header.uiOriginalSize += image_width * image_height;
|
||||
_header.Indexed.usNumberOfSubImages += 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool IndexedSTIImage::addImage(UINT8 *data, UINT32 data_size, UINT32 image_width, UINT32 image_height, INT32 image_offset_x, INT32 image_offset_y, UINT8 *original_compressed, UINT32 original_compressed_size)
|
||||
{
|
||||
if(!data || (data_size != image_width*image_height) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
STCISubImage subimage;
|
||||
memset(&subimage,0,sizeof(STCISubImage));
|
||||
|
||||
UINT32 RESIZE = 3*data_size;
|
||||
|
||||
int comprSize = _compressed_images.size();
|
||||
_compressed_images.resize(comprSize+1);
|
||||
_compressed_images[comprSize].resize(RESIZE);
|
||||
// UINT8 *compressed = new UINT8[2*data_size];
|
||||
UINT8 *compressed = &_compressed_images[comprSize][0];
|
||||
|
||||
UINT8 *compressed_start = compressed;
|
||||
// memset(compressed,0,RESIZE);
|
||||
UINT32 compressed_size = 0;
|
||||
|
||||
subimage.usWidth = image_width;
|
||||
subimage.usHeight = image_height;
|
||||
|
||||
INT32 etrle_size = ETRLECompressSubImage( compressed, RESIZE, data, image_width, image_height, &subimage);
|
||||
SGP_THROW_IFFALSE( etrle_size > 0, L"not enough space reserved for ETRLE compression");
|
||||
subimage.sOffsetX = image_offset_x;
|
||||
subimage.sOffsetY = image_offset_y;
|
||||
|
||||
//subimage.uiDataLength = compressed_size;
|
||||
//_header.uiStoredSize += compressed_size;
|
||||
subimage.uiDataLength = etrle_size;
|
||||
_header.uiStoredSize += etrle_size;
|
||||
_images.push_back(subimage);
|
||||
// _compressed_images.push_back(compressed_start);
|
||||
_header.uiOriginalSize += data_size;
|
||||
_header.Indexed.usNumberOfSubImages += 1;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static inline void setFlag(UINT8 &flags, char const* sFlag)
|
||||
{
|
||||
/*0x01*/ if (strcmp(sFlag, "AUX_FULL_TILE") == 0) flags |= AUX_FULL_TILE;
|
||||
/*0x02*/ else if(strcmp(sFlag, "AUX_ANIMATED_TILE") == 0) flags |= AUX_ANIMATED_TILE;
|
||||
/*0x04*/ else if(strcmp(sFlag, "AUX_DYNAMIC_TILE") == 0) flags |= AUX_DYNAMIC_TILE;
|
||||
/*0x08*/ else if(strcmp(sFlag, "AUX_INTERACTIVE_TILE") == 0) flags |= AUX_INTERACTIVE_TILE;
|
||||
/*0x10*/ else if(strcmp(sFlag, "AUX_IGNORES_HEIGHT") == 0) flags |= AUX_IGNORES_HEIGHT;
|
||||
/*0x20*/ else if(strcmp(sFlag, "AUX_USES_LAND_Z") == 0) flags |= AUX_USES_LAND_Z;
|
||||
else
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Unknown flag [" << vfs::String::as_utf16(sFlag) << L"]";
|
||||
SGP_THROW(wss.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
class CAppDataParser : public IXMLParser
|
||||
{
|
||||
enum DOM_OBJECT
|
||||
{
|
||||
DO_ELEMENT_NONE,
|
||||
DO_ELEMENT_ImageData,
|
||||
DO_ELEMENT_SubImage,
|
||||
DO_ELEMENT_offset,
|
||||
DO_ELEMENT_AuxData,
|
||||
DO_ELEMENT_flags,
|
||||
DO_ELEMENT_properties,
|
||||
};
|
||||
public:
|
||||
CAppDataParser(XML_Parser &parser, IXMLParser* caller=NULL)
|
||||
: IXMLParser("ImageData", &parser, caller),
|
||||
current_state(DO_ELEMENT_NONE),
|
||||
m_hImage(NULL),
|
||||
m_iCurrentIndex(-1)
|
||||
{
|
||||
}
|
||||
virtual ~CAppDataParser() {};
|
||||
|
||||
virtual void onStartElement(const XML_Char* name, const XML_Char** atts);
|
||||
virtual void onEndElement(const XML_Char* name);
|
||||
virtual void onTextElement(const XML_Char *str, int len);
|
||||
|
||||
void setImage(HIMAGE hImage)
|
||||
{
|
||||
m_hImage = hImage;
|
||||
if(m_hImage)
|
||||
{
|
||||
m_vAppData.resize(m_hImage->usNumberOfObjects);
|
||||
}
|
||||
}
|
||||
private:
|
||||
DOM_OBJECT current_state;
|
||||
HIMAGE m_hImage;
|
||||
struct SubImage{
|
||||
SubImage()
|
||||
{
|
||||
memset(&aux,0,sizeof(AuxObjectData));
|
||||
offset._override = false;
|
||||
offset.x = 0;
|
||||
offset.y = 0;
|
||||
};
|
||||
AuxObjectData aux;
|
||||
struct{
|
||||
int x,y;
|
||||
bool _override;
|
||||
} offset;
|
||||
};
|
||||
std::vector<SubImage> m_vAppData;
|
||||
int m_iCurrentIndex;
|
||||
};
|
||||
|
||||
void CAppDataParser::onStartElement(const XML_Char* name, const XML_Char** atts)
|
||||
{
|
||||
if( current_state == DO_ELEMENT_NONE && strcmp(name, this->ElementName) == 0 )
|
||||
{
|
||||
current_state = DO_ELEMENT_ImageData;
|
||||
}
|
||||
else if(current_state == DO_ELEMENT_ImageData && strcmp(name, "SubImage") == 0)
|
||||
{
|
||||
int index = -1;
|
||||
SGP_THROW_IFFALSE(getAttributeAsInt("index",atts,index), L"could not read attribute \"index\"");
|
||||
m_iCurrentIndex = index;
|
||||
if(index >= (int)m_vAppData.size())
|
||||
{
|
||||
m_vAppData.resize(index+1);
|
||||
}
|
||||
current_state = DO_ELEMENT_SubImage;
|
||||
}
|
||||
else if(current_state == DO_ELEMENT_SubImage && strcmp(name, "offset") == 0)
|
||||
{
|
||||
int offset_x = 0, offset_y = 0;
|
||||
if(getAttributeAsInt("x",atts,offset_x))
|
||||
{
|
||||
m_vAppData[m_iCurrentIndex].offset.x = offset_x;
|
||||
m_vAppData[m_iCurrentIndex].offset._override = true;
|
||||
}
|
||||
if(getAttributeAsInt("y",atts,offset_y))
|
||||
{
|
||||
m_vAppData[m_iCurrentIndex].offset.y = offset_y;
|
||||
m_vAppData[m_iCurrentIndex].offset._override = true;
|
||||
}
|
||||
current_state = DO_ELEMENT_offset;
|
||||
}
|
||||
else if(current_state == DO_ELEMENT_SubImage && strcmp(name, "AuxObjectData") == 0)
|
||||
{
|
||||
current_state = DO_ELEMENT_AuxData;
|
||||
}
|
||||
else if(current_state == DO_ELEMENT_AuxData && strcmp(name, "flags") == 0)
|
||||
{
|
||||
current_state = DO_ELEMENT_flags;
|
||||
}
|
||||
else if(current_state == DO_ELEMENT_flags)
|
||||
{
|
||||
setFlag(m_vAppData[m_iCurrentIndex].aux.fFlags, name);
|
||||
}
|
||||
else if(current_state == DO_ELEMENT_AuxData &&
|
||||
( strcmp(name, "ubCurrentFrame") == 0 ||
|
||||
strcmp(name, "ubNumberOfFrames") == 0 ||
|
||||
strcmp(name, "ubNumberOfTiles") == 0 ||
|
||||
strcmp(name, "ubWallOrientation") == 0 ||
|
||||
strcmp(name, "usTileLocIndex") == 0 )
|
||||
)
|
||||
{
|
||||
current_state = DO_ELEMENT_properties;
|
||||
}
|
||||
sCharData = "";
|
||||
}
|
||||
void CAppDataParser::onEndElement(const XML_Char* name)
|
||||
{
|
||||
char *p;
|
||||
if( strcmp(name, "usTileLocIndex") == 0 && current_state == DO_ELEMENT_properties)
|
||||
{
|
||||
m_vAppData[m_iCurrentIndex].aux.usTileLocIndex = (UINT16)strtoul( sCharData.c_str(),&p,10);
|
||||
current_state = DO_ELEMENT_AuxData;
|
||||
}
|
||||
else if( strcmp(name, "ubWallOrientation") == 0 && current_state == DO_ELEMENT_properties)
|
||||
{
|
||||
m_vAppData[m_iCurrentIndex].aux.ubWallOrientation = (UINT8)strtoul(sCharData.c_str(),&p,10);
|
||||
current_state = DO_ELEMENT_AuxData;
|
||||
}
|
||||
else if( strcmp(name, "ubNumberOfTiles") == 0 && current_state == DO_ELEMENT_properties)
|
||||
{
|
||||
m_vAppData[m_iCurrentIndex].aux.ubNumberOfTiles = (UINT8)strtoul(sCharData.c_str(),&p,10);
|
||||
current_state = DO_ELEMENT_AuxData;
|
||||
}
|
||||
else if( strcmp(name, "ubNumberOfFrames") == 0 && current_state == DO_ELEMENT_properties)
|
||||
{
|
||||
m_vAppData[m_iCurrentIndex].aux.ubNumberOfFrames = (UINT)strtoul(sCharData.c_str(),&p,10);
|
||||
current_state = DO_ELEMENT_AuxData;
|
||||
}
|
||||
else if( strcmp(name, "ubCurrentFrame") == 0 && current_state == DO_ELEMENT_properties)
|
||||
{
|
||||
m_vAppData[m_iCurrentIndex].aux.ubCurrentFrame = (UINT8)strtoul(sCharData.c_str(),&p,10);
|
||||
current_state = DO_ELEMENT_AuxData;
|
||||
}
|
||||
else if( strcmp(name, "flags") == 0 && current_state == DO_ELEMENT_flags)
|
||||
{
|
||||
current_state = DO_ELEMENT_AuxData;
|
||||
}
|
||||
else if( strcmp(name, "offset") == 0 && current_state == DO_ELEMENT_offset)
|
||||
{
|
||||
current_state = DO_ELEMENT_SubImage;
|
||||
}
|
||||
else if( strcmp(name, "AuxObjectData") == 0 && current_state == DO_ELEMENT_AuxData)
|
||||
{
|
||||
current_state = DO_ELEMENT_SubImage;
|
||||
}
|
||||
else if( strcmp(name, "SubImage") == 0 && current_state == DO_ELEMENT_SubImage)
|
||||
{
|
||||
current_state = DO_ELEMENT_ImageData;
|
||||
}
|
||||
else if( strcmp(name, this->ElementName) == 0 && current_state == DO_ELEMENT_ImageData)
|
||||
{
|
||||
unsigned int sum_frames = 0;
|
||||
for(unsigned int i = 0; i < m_vAppData.size(); ++i)
|
||||
{
|
||||
sum_frames += m_vAppData[i].aux.ubNumberOfFrames;
|
||||
}
|
||||
SGP_THROW_IFFALSE(sum_frames <= m_vAppData.size(), L"Sum of animation frames doesn't match the total number of frames");
|
||||
int iAppDataSize = m_vAppData.size()*sizeof(AuxObjectData);
|
||||
m_hImage->pAppData = (UINT8*) MemAlloc( iAppDataSize );
|
||||
for(unsigned int i = 0; i < m_vAppData.size(); ++i)
|
||||
{
|
||||
memcpy(&((AuxObjectData*)m_hImage->pAppData)[i],&m_vAppData[i],sizeof(AuxObjectData));
|
||||
}
|
||||
m_hImage->uiAppDataSize = iAppDataSize;
|
||||
unsigned int aaa = std::max<int>(m_hImage->usNumberOfObjects,m_vAppData.size());
|
||||
for(unsigned int i = 0; i < aaa; ++i)
|
||||
{
|
||||
if(m_vAppData[i].offset._override)
|
||||
{
|
||||
m_hImage->pETRLEObject[i].sOffsetX = m_vAppData[i].offset.x;
|
||||
m_hImage->pETRLEObject[i].sOffsetY = m_vAppData[i].offset.y;
|
||||
}
|
||||
}
|
||||
m_hImage->fFlags |= IMAGE_APPDATA;
|
||||
current_state = DO_ELEMENT_NONE;
|
||||
}
|
||||
}
|
||||
void CAppDataParser::onTextElement(const XML_Char *str, int len)
|
||||
{
|
||||
// handle only this special case; everything else does not matter for now
|
||||
if(current_state == DO_ELEMENT_properties)
|
||||
{
|
||||
sCharData.append(str,len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool IndexedSTIImage::readAppDataFromXMLFile(HIMAGE hImage, vfs::tReadableFile* pFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::vector<char> vBuffer;
|
||||
UINT32 uiSize = 0;
|
||||
try
|
||||
{
|
||||
vfs::COpenReadFile oFile(pFile);
|
||||
uiSize = oFile->getSize();
|
||||
vBuffer.resize(uiSize+1);
|
||||
|
||||
SGP_THROW_IFFALSE(uiSize == oFile->read(&vBuffer[0],uiSize), L"Could not read XML file");
|
||||
vBuffer[uiSize] = 0;
|
||||
oFile->close();
|
||||
}
|
||||
catch(std::exception& ex)
|
||||
{
|
||||
SGP_RETHROW(L"", ex);
|
||||
}
|
||||
|
||||
XML_Parser parser = XML_ParserCreate(NULL);
|
||||
|
||||
CAppDataParser adp(parser);
|
||||
adp.grabParser();
|
||||
adp.setImage(hImage);
|
||||
|
||||
try
|
||||
{
|
||||
if(!XML_Parse(parser, &vBuffer[0], uiSize, TRUE))
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"XML Parser Error in Groups.xml: "
|
||||
<< vfs::String(XML_ErrorString(XML_GetErrorCode(parser))).c_wcs()
|
||||
<< L" at line "
|
||||
<< XML_GetCurrentLineNumber(parser);
|
||||
SGP_THROW(wss.str().c_str());
|
||||
}
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
SGP_RETHROW(L"Could not load xml file", ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool IndexedSTIImage::writeToHIMAGE(HIMAGE pImage)
|
||||
{
|
||||
if(!pImage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
pImage->usNumberOfObjects = _compressed_images.size();
|
||||
pImage->usWidth = 640;
|
||||
pImage->usHeight = 480;
|
||||
pImage->ubBitDepth = 8;
|
||||
// pImage->fFlags = STCI_ETRLE_COMPRESSED | STCI_INDEXED | STCI_TRANSPARENT;
|
||||
pImage->fFlags |= IMAGE_TRLECOMPRESSED;
|
||||
pImage->fFlags |= IMAGE_BITMAPDATA;
|
||||
|
||||
//strncat(pImage->ImageFile,"test",4);
|
||||
pImage->iFileLoader = -1;
|
||||
pImage->pui16BPPPalette = NULL;
|
||||
|
||||
|
||||
pImage->pPalette = new SGPPaletteEntry[256];
|
||||
for(int j=0; j<256; ++j)
|
||||
{
|
||||
pImage->pPalette[j].peRed = _palette[j].ubRed;
|
||||
pImage->pPalette[j].peGreen = _palette[j].ubGreen;
|
||||
pImage->pPalette[j].peBlue = _palette[j].ubBlue;
|
||||
pImage->pPalette[j].peFlags = 0;
|
||||
}
|
||||
|
||||
pImage->pETRLEObject = new ETRLEObject[pImage->usNumberOfObjects];
|
||||
UINT32 offset=0; // == size
|
||||
for(unsigned int i=0; i<_images.size(); ++i)
|
||||
{
|
||||
pImage->pETRLEObject[i].sOffsetX = _images[i].sOffsetX;
|
||||
pImage->pETRLEObject[i].sOffsetY = _images[i].sOffsetY;
|
||||
pImage->pETRLEObject[i].usHeight = _images[i].usHeight;
|
||||
pImage->pETRLEObject[i].usWidth = _images[i].usWidth;
|
||||
pImage->pETRLEObject[i].uiDataOffset = offset;
|
||||
pImage->pETRLEObject[i].uiDataLength = _images[i].uiDataLength;
|
||||
offset += _images[i].uiDataLength;
|
||||
}
|
||||
|
||||
pImage->uiSizePixData = offset;
|
||||
pImage->pPixData8 = new UINT8[offset];
|
||||
// write sub-images
|
||||
for(unsigned int i=0; i<_compressed_images.size(); ++i)
|
||||
{
|
||||
memcpy(
|
||||
&pImage->pPixData8[pImage->pETRLEObject[i].uiDataOffset],
|
||||
&_compressed_images[i][0],
|
||||
pImage->pETRLEObject[i].uiDataLength);
|
||||
}
|
||||
|
||||
//pImage->uiAppDataSize = pImage->usNumberOfObjects * sizeof(AuxObjectData);
|
||||
//pImage->pAppData = (UINT8*)(new AuxObjectData[pImage->usNumberOfObjects]);
|
||||
//memset(pImage->pAppData,0,pImage->uiAppDataSize);
|
||||
|
||||
//// write application data
|
||||
//int frames = _compressed_images.size()/8; // 8 = number of directions
|
||||
//for(unsigned int i=0; i<pImage->usNumberOfObjects; ++i)
|
||||
//{
|
||||
// if(i % frames == 0)
|
||||
// {
|
||||
// AuxObjectData &aod = *((AuxObjectData*)(&pImage->pAppData[i*sizeof(AuxObjectData)]));
|
||||
// aod.ubNumberOfFrames = frames;
|
||||
// aod.fFlags = AUX_ANIMATED_TILE;
|
||||
// }
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/*******************************************************************************/
|
||||
|
||||
class LoadPngFile
|
||||
{
|
||||
public:
|
||||
LoadPngFile(vfs::Path const& sFile)
|
||||
: _file(NULL), _struct(NULL), _info(NULL), _row_ptr(NULL)
|
||||
{
|
||||
// Open and read in the file
|
||||
vfs::COpenReadFile oFile(sFile);
|
||||
_file = &oFile.file();
|
||||
oFile.release();
|
||||
}
|
||||
LoadPngFile(vfs::tReadableFile* pFile)
|
||||
: _file(pFile), _struct(NULL), _info(NULL), _row_ptr(NULL)
|
||||
{
|
||||
SGP_THROW_IFFALSE(_file, L"file pointer is NULL");
|
||||
}
|
||||
bool Load()
|
||||
{
|
||||
png::png_error_ptr user_error_ptr = NULL;
|
||||
png::png_error_ptr user_error_fn = NULL;
|
||||
png::png_error_ptr user_warning_fn = NULL;
|
||||
|
||||
_struct = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png::png_voidp)user_error_ptr, user_error_fn, user_warning_fn);
|
||||
if (!_struct)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_info = png_create_info_struct(_struct);
|
||||
if (!_info)
|
||||
{
|
||||
png_destroy_read_struct(&_struct, (png::png_infopp)NULL, (png::png_infopp)NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
png::png_infop end_info = png_create_info_struct(_struct);
|
||||
if (!end_info)
|
||||
{
|
||||
png_destroy_read_struct(&_struct, &_info, (png::png_infopp)NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
// push file handle
|
||||
png_set_read_fn(_struct, _file, user_read_data);
|
||||
|
||||
int png_transforms = PNG_TRANSFORM_IDENTITY;
|
||||
png_read_png(_struct, _info, png_transforms, NULL);
|
||||
|
||||
// png_read_end(_struct,_info);
|
||||
|
||||
_row_ptr = png_get_rows(_struct, _info);
|
||||
|
||||
return _row_ptr != NULL;
|
||||
}
|
||||
~LoadPngFile()
|
||||
{
|
||||
if(_file)
|
||||
{
|
||||
_file->close();
|
||||
}
|
||||
if(_struct && _info)
|
||||
{
|
||||
png_destroy_info_struct(_struct, &_info);
|
||||
_info = NULL;
|
||||
}
|
||||
if(_struct)
|
||||
{
|
||||
png_destroy_read_struct(&_struct, (png::png_infopp)_info, (png::png_infopp)NULL);
|
||||
}
|
||||
//if(_row_ptr)
|
||||
//{
|
||||
// int i=0;
|
||||
//}
|
||||
}
|
||||
|
||||
png::png_bytepp Rows()
|
||||
{
|
||||
return _row_ptr;
|
||||
}
|
||||
png::png_infop Info()
|
||||
{
|
||||
return _info;
|
||||
}
|
||||
private:
|
||||
vfs::tReadableFile* _file;
|
||||
png::png_structp _struct;
|
||||
png::png_infop _info;
|
||||
png::png_bytepp _row_ptr;
|
||||
png::png_bytep _data;
|
||||
};
|
||||
|
||||
bool LoadPNGFileToImage(HIMAGE hImage, UINT16 fContents)
|
||||
{
|
||||
LoadPngFile fpng(hImage->ImageFile);
|
||||
if(!fpng.Load())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(fpng.Info()->channels == 4 && fpng.Info()->bit_depth == 8)
|
||||
{
|
||||
Load32bppPNGImage(hImage, fpng.Rows(), fpng.Info());
|
||||
}
|
||||
else if(fpng.Info()->channels == 3 && fpng.Info()->bit_depth == 8)
|
||||
{
|
||||
Load24bppPNGImage(hImage, fpng.Rows(), fpng.Info());
|
||||
}
|
||||
else if(fpng.Info()->channels == 1 && fpng.Info()->bit_depth == 8)
|
||||
{
|
||||
LoadPalettedPNGImage(hImage, fpng.Rows(), fpng.Info());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Unknown image datatype : channels = " << (int)(fpng.Info()->channels)
|
||||
<< L", bit depth = " << (int)(fpng.Info()->bit_depth);
|
||||
SGP_THROW(wss.str().c_str());
|
||||
}
|
||||
|
||||
// data was copied to hImage, need to clean up here
|
||||
// ...
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool LoadJPCFileToImage(HIMAGE hImage, UINT16 fContents)
|
||||
{
|
||||
if(!getVFS()->fileExists(hImage->ImageFile))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vfs::CBufferFile oBuffer("");
|
||||
|
||||
vfs::COpenReadFile oFile(hImage->ImageFile);
|
||||
SGP_TRYCATCH_RETHROW(oBuffer.copyToBuffer(oFile.file()), L"Could not copy file to buffer");
|
||||
oBuffer.close();
|
||||
|
||||
//vfs::CUncompressed7zLibrary oLib(&oFile.file(),"");
|
||||
vfs::ObjBlockAllocator<vfs::CLibFile> allocator(128);
|
||||
vfs::CUncompressed7zLibrary oLib(vfs::tReadableFile::cast(&oBuffer),"",false, &allocator);
|
||||
|
||||
if(!oLib.init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IndexedSTIImage image;
|
||||
|
||||
std::vector<vfs::IBaseFile*> vFiles;
|
||||
int count_files = 0;
|
||||
vfs::CUncompressed7zLibrary::Iterator it = oLib.begin();
|
||||
for(; !it.end(); it.next())
|
||||
{
|
||||
count_files++;
|
||||
}
|
||||
vFiles.resize(count_files);
|
||||
it = oLib.begin();
|
||||
vfs::tReadableFile* appdata_file = NULL;
|
||||
for(; !it.end(); it.next())
|
||||
{
|
||||
// check extension
|
||||
vfs::String::str_t const& fname = it.value()->getName().c_wcs();
|
||||
vfs::String::size_t dot = fname.find_last_of(vfs::Const::DOT());
|
||||
if(dot != vfs::String::str_t::npos)
|
||||
{
|
||||
if( vfs::StrCmp::Equal(fname.substr(dot,fname.length()-dot), CONST_DOTPNG) )
|
||||
{
|
||||
std::wstringstream bss;
|
||||
bss.str( fname.substr(0,dot) );
|
||||
int index;
|
||||
bss >> index;
|
||||
if(index >= 0 && index < count_files)
|
||||
{
|
||||
vFiles[index] = it.value();
|
||||
}
|
||||
else
|
||||
{
|
||||
SGP_THROW(L"invalid index");
|
||||
}
|
||||
}
|
||||
else if (vfs::StrCmp::Equal(fname.substr(dot,fname.length()-dot), CONST_DOTXML) )
|
||||
{
|
||||
appdata_file = vfs::tReadableFile::cast(it.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool bHasPalette = false;
|
||||
std::vector<vfs::IBaseFile*>::iterator fit = vFiles.begin();
|
||||
if(vFiles.size() == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
// VR r2348 fix - loading .jpc.7z with a single image would cause exception as file was not considered open (by anv)
|
||||
//LoadPngFile lpng(vfs::tReadableFile::cast(vFiles[0]));
|
||||
vfs::CBufferFile oTempFile("");
|
||||
oTempFile.copyToBuffer(*vfs::tReadableFile::cast(vFiles[0]));
|
||||
LoadPngFile lpng(vfs::tReadableFile::cast(&oTempFile));
|
||||
|
||||
bool bLoadS = lpng.Load();
|
||||
|
||||
if(bLoadS)
|
||||
{
|
||||
if(lpng.Info()->channels == 4 && lpng.Info()->bit_depth == 8)
|
||||
{
|
||||
Load32bppPNGImage(hImage, lpng.Rows(), lpng.Info());
|
||||
}
|
||||
else if(lpng.Info()->channels == 3 && lpng.Info()->bit_depth == 8)
|
||||
{
|
||||
Load24bppPNGImage(hImage, lpng.Rows(), lpng.Info());
|
||||
}
|
||||
else if(lpng.Info()->channels == 1 && lpng.Info()->bit_depth == 8)
|
||||
{
|
||||
LoadPalettedPNGImage(hImage, lpng.Rows(), lpng.Info());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Unknown image datatype : channels = " << (int)(lpng.Info()->channels)
|
||||
<< L", bit depth = " << (int)(lpng.Info()->bit_depth);
|
||||
SGP_THROW(wss.str().c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Loading PNG image from file '"
|
||||
<< oFile->getPath().c_wcs()
|
||||
<< L"' failed";
|
||||
SGP_RETHROW(wss.str().c_str(), ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int findex = 0; fit != vFiles.end(); ++fit, ++findex)
|
||||
{
|
||||
if(*fit == NULL)
|
||||
{
|
||||
// probably not a PNG file
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
vfs::CBufferFile oTempFile("");
|
||||
oTempFile.copyToBuffer( *vfs::tReadableFile::cast(*fit) );
|
||||
|
||||
// LoadPngFile lpng( vfs::tReadableFile::cast(*fit) );
|
||||
LoadPngFile lpng( vfs::tReadableFile::cast(&oTempFile) );
|
||||
|
||||
bool bLoadS = lpng.Load();
|
||||
if(bLoadS)
|
||||
{
|
||||
if(lpng.Info()->channels == 1 && lpng.Info()->bit_depth == 8)
|
||||
{
|
||||
if(!bHasPalette)
|
||||
{
|
||||
SGP_THROW_IFFALSE(lpng.Info()->num_palette == 256, L"size of palette is not 256");
|
||||
image.setPalette(lpng.Info()->palette, lpng.Info()->num_palette);
|
||||
bHasPalette = true;
|
||||
}
|
||||
UINT32 SIZE = lpng.Info()->height * lpng.Info()->width;
|
||||
std::vector<UINT8> data(SIZE,0);
|
||||
for(unsigned int i = 0; i < lpng.Info()->height; ++i)
|
||||
{
|
||||
memcpy(&data[i*lpng.Info()->width],lpng.Rows()[i],lpng.Info()->width);
|
||||
}
|
||||
image.addImage(&data[0], SIZE, lpng.Info()->width, lpng.Info()->height, lpng.Info()->x_offset, lpng.Info()->y_offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"PNG file '" << (*fit)->getName()() << L" @ " << oFile->getPath()() << L"' is not a paletted image";
|
||||
SGP_THROW(wss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(std::exception& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Loading PNG image [" << findex << L"] from file '" << oFile->getPath().c_wcs() << L"' failed";
|
||||
SGP_RETHROW(wss.str().c_str(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool success = image.writeToHIMAGE(hImage);
|
||||
if(appdata_file)
|
||||
{
|
||||
success &= image.readAppDataFromXMLFile(hImage, appdata_file);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
void Load32bppPNGImage(HIMAGE hImage, png::png_bytepp rows, png::png_infop info)
|
||||
{
|
||||
hImage->pETRLEObject = (ETRLEObject*)MemAlloc(1 * sizeof(ETRLEObject));
|
||||
if(!hImage->pETRLEObject)
|
||||
{
|
||||
SGP_THROW(L"bad alloc");
|
||||
}
|
||||
memset(hImage->pETRLEObject, 0, sizeof(ETRLEObject));
|
||||
hImage->usNumberOfObjects = 1;
|
||||
|
||||
hImage->pETRLEObject[0].usHeight = (UINT16)info->height;
|
||||
hImage->pETRLEObject[0].usWidth = (UINT16)info->width;
|
||||
|
||||
hImage->pETRLEObject[0].sOffsetX = (INT16)info->x_offset;
|
||||
hImage->pETRLEObject[0].sOffsetY = (INT16)info->y_offset;
|
||||
|
||||
hImage->usHeight = (UINT16)info->height;
|
||||
hImage->usWidth = (UINT16)info->width;
|
||||
hImage->ubBitDepth = 32;
|
||||
|
||||
UINT32 SIZE = info->height * info->width * sizeof(UINT32);
|
||||
hImage->p32BPPData = (UINT32*)MemAlloc(SIZE);
|
||||
if(!hImage->p32BPPData)
|
||||
{
|
||||
MemFree(hImage->pETRLEObject);
|
||||
SGP_THROW(L"bad alloc");
|
||||
}
|
||||
memset(hImage->p32BPPData, 0, SIZE);
|
||||
|
||||
UINT32* dest_row = NULL;
|
||||
UINT32 rgbcolor = 0;
|
||||
for(unsigned int i=0; i<info->height; ++i)
|
||||
{
|
||||
dest_row = &(hImage->p32BPPData[i*info->width]);
|
||||
png::png_bytep row_i = rows[i];
|
||||
memcpy(dest_row,row_i,info->width * sizeof(UINT32));
|
||||
}
|
||||
|
||||
hImage->fFlags |= IMAGE_BITMAPDATA;
|
||||
}
|
||||
|
||||
|
||||
void Load24bppPNGImage(HIMAGE hImage, png::png_bytepp rows, png::png_infop info)
|
||||
{
|
||||
hImage->pETRLEObject = (ETRLEObject*)MemAlloc(1 * sizeof(ETRLEObject));
|
||||
if(!hImage->pETRLEObject)
|
||||
{
|
||||
SGP_THROW(L"bad alloc");
|
||||
}
|
||||
memset(hImage->pETRLEObject, 0, sizeof(ETRLEObject));
|
||||
hImage->usNumberOfObjects = 1;
|
||||
|
||||
hImage->pETRLEObject[0].usHeight = (UINT16)info->height;
|
||||
hImage->pETRLEObject[0].usWidth = (UINT16)info->width;
|
||||
|
||||
hImage->pETRLEObject[0].sOffsetX = (UINT16)info->x_offset;
|
||||
hImage->pETRLEObject[0].sOffsetY = (UINT16)info->y_offset;
|
||||
|
||||
hImage->usHeight = (UINT16)info->height;
|
||||
hImage->usWidth = (UINT16)info->width;
|
||||
hImage->ubBitDepth = 16;
|
||||
|
||||
UINT32 SIZE = info->height * info->width * sizeof(UINT16);
|
||||
hImage->p16BPPData = (UINT16*)MemAlloc(SIZE);
|
||||
if(!hImage->p16BPPData)
|
||||
{
|
||||
MemFree(hImage->pETRLEObject);
|
||||
SGP_THROW(L"bad alloc");
|
||||
}
|
||||
memset(hImage->p16BPPData, 0, SIZE);
|
||||
|
||||
UINT16* dest_row = NULL;
|
||||
UINT32 rgbcolor = 0;
|
||||
for(unsigned int i=0; i<info->height; ++i)
|
||||
{
|
||||
dest_row = &(hImage->p16BPPData[i*info->width]);
|
||||
png::png_bytep row_i = rows[i];
|
||||
for(unsigned int sx = 0, dx = 0; sx < 3*info->width; sx+=3, dx+=1)
|
||||
{
|
||||
dest_row[dx] = Get16BPPColor( FROMRGB(row_i[sx], row_i[sx+1], row_i[sx+2]) );
|
||||
}
|
||||
}
|
||||
hImage->fFlags |= IMAGE_BITMAPDATA;
|
||||
}
|
||||
|
||||
void LoadPalettedPNGImage(HIMAGE hImage, png::png_bytepp rows, png::png_infop info)
|
||||
{
|
||||
UINT32 SIZE = info->height * info->width * sizeof(UINT8);
|
||||
UINT8 *data = (UINT8*)MemAlloc(SIZE);
|
||||
if(!data)
|
||||
{
|
||||
SGP_THROW(L"bad alloc");
|
||||
}
|
||||
memset(data,0,SIZE);
|
||||
for(unsigned int i = 0; i < info->height; ++i)
|
||||
{
|
||||
memcpy(&data[i*info->width],rows[i],info->width);
|
||||
}
|
||||
|
||||
hImage->usNumberOfObjects = 1;
|
||||
hImage->pETRLEObject = (ETRLEObject*)MemAlloc(hImage->usNumberOfObjects * sizeof(ETRLEObject));
|
||||
if(!hImage->pETRLEObject)
|
||||
{
|
||||
MemFree(data);
|
||||
SGP_THROW(L"bad alloc");
|
||||
}
|
||||
memset(hImage->pETRLEObject,0, hImage->usNumberOfObjects * sizeof(ETRLEObject));
|
||||
|
||||
ETRLEObject &subimage = hImage->pETRLEObject[0];
|
||||
subimage.sOffsetX = (INT16) info->x_offset;;
|
||||
subimage.sOffsetY = (INT16) info->y_offset;
|
||||
subimage.usWidth = (UINT16) info->width;
|
||||
subimage.usHeight = (UINT16) info->height;
|
||||
|
||||
// why allocate so much? because in in the worst case we need one TAG and one DATAVALUE per pixel
|
||||
UINT32 RESIZE = 3*SIZE;
|
||||
hImage->p8BPPData = (UINT8*)MemAlloc( RESIZE );
|
||||
if(!hImage->p8BPPData)
|
||||
{
|
||||
MemFree(hImage->pETRLEObject);
|
||||
MemFree(data);
|
||||
SGP_THROW(L"bad alloc");
|
||||
}
|
||||
UINT8 *compressed = hImage->p8BPPData;
|
||||
memset(hImage->p8BPPData,0,RESIZE);
|
||||
UINT32 compressed_size = 0;
|
||||
|
||||
STCISubImage subim;
|
||||
memset(&subim,0,sizeof(STCISubImage));
|
||||
|
||||
subim.uiDataLength = subimage.uiDataLength;
|
||||
subim.uiDataOffset = subimage.uiDataOffset;
|
||||
subim.usHeight = subimage.usHeight;
|
||||
subim.usWidth = subimage.usWidth;
|
||||
|
||||
UINT32 etrle_size = ETRLECompressSubImage( hImage->p8BPPData, RESIZE, data, (UINT16)info->width, (UINT16)info->height, &subim);
|
||||
SGP_THROW_IFFALSE( etrle_size > 0, L"ETRLE compression of PNG image failed" );
|
||||
subim.sOffsetX = subimage.sOffsetX;
|
||||
subim.sOffsetY = subimage.sOffsetY;
|
||||
//subimage.uiDataLength = compressed_size;
|
||||
subimage.uiDataLength = etrle_size;
|
||||
subimage.uiDataOffset = 0;
|
||||
|
||||
hImage->ubBitDepth = 8;
|
||||
//hImage->uiSizePixData = compressed_size;
|
||||
hImage->uiSizePixData = etrle_size;
|
||||
|
||||
hImage->usHeight = (UINT16)info->height;
|
||||
hImage->usWidth = (UINT16)info->width;
|
||||
|
||||
hImage->fFlags |= IMAGE_TRLECOMPRESSED;
|
||||
hImage->fFlags |= IMAGE_BITMAPDATA;
|
||||
|
||||
// palette
|
||||
SGP_THROW_IFFALSE(info->num_palette == 256, L"palette has size != 256");
|
||||
|
||||
hImage->pPalette = (SGPPaletteEntry*)MemAlloc(sizeof(SGPPaletteEntry) *256);
|
||||
for(int i=0; i<256; ++i)
|
||||
{
|
||||
hImage->pPalette[i].peRed = info->palette[i].red;
|
||||
hImage->pPalette[i].peGreen = info->palette[i].green;
|
||||
hImage->pPalette[i].peBlue = info->palette[i].blue;
|
||||
hImage->pPalette[i].peFlags = 0;
|
||||
}
|
||||
hImage->fFlags |= IMAGE_PALETTE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef _PNGLOADER_H_
|
||||
#define _PNGLOADER_H_
|
||||
|
||||
#include "types.h"
|
||||
#include "himage.h"
|
||||
|
||||
bool LoadPNGFileToImage(HIMAGE hImage, UINT16 fContents);
|
||||
|
||||
bool LoadJPCFileToImage(HIMAGE hImage, UINT16 fContents);
|
||||
|
||||
|
||||
#endif // _PNGLOADER_H_
|
||||
|
||||
@@ -0,0 +1,638 @@
|
||||
#ifndef __RAD__
|
||||
#define __RAD__
|
||||
|
||||
#define RADCOPYRIGHT "Copyright (C) 1994-98 RAD Game Tools, Inc."
|
||||
|
||||
#ifndef __RADRES__
|
||||
|
||||
// __RADDOS__ means DOS code (16 or 32 bit)
|
||||
// __RAD16__ means 16 bit code (Win16)
|
||||
// __RAD32__ means 32 bit code (DOS, Win386, Win32s, Mac)
|
||||
// __RADWIN__ means Windows code (Win16, Win386, Win32s)
|
||||
// __RADWINEXT__ means Windows 386 extender (Win386)
|
||||
// __RADNT__ means Win32s code
|
||||
// __RADMAC__ means Macintosh
|
||||
// __RAD68K__ means 68K Macintosh
|
||||
// __RADPPC__ means PowerMac
|
||||
|
||||
|
||||
#if (defined(__MWERKS__) && !defined(__INTEL__)) || defined(THINK_C) || defined(powerc) || defined(macintosh) || defined(__powerc)
|
||||
|
||||
#define __RADMAC__
|
||||
#if defined(powerc) || defined(__powerc)
|
||||
#define __RADPPC__
|
||||
#else
|
||||
#define __RAD68K__
|
||||
#endif
|
||||
|
||||
#define __RAD32__
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __DOS__
|
||||
#define __RADDOS__
|
||||
#endif
|
||||
|
||||
#ifdef __386__
|
||||
#define __RAD32__
|
||||
#endif
|
||||
|
||||
#ifdef _Windows //For Borland
|
||||
#ifdef __WIN32__
|
||||
#define WIN32
|
||||
#else
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WINDOWS //For MS
|
||||
#ifndef _WIN32
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define __RADWIN__
|
||||
#define __RADNT__
|
||||
#define __RAD32__
|
||||
#else
|
||||
#ifdef __NT__
|
||||
#define __RADWIN__
|
||||
#define __RADNT__
|
||||
#define __RAD32__
|
||||
#else
|
||||
#ifdef __WINDOWS_386__
|
||||
#define __RADWIN__
|
||||
#define __RADWINEXT__
|
||||
#define __RAD32__
|
||||
#else
|
||||
#ifdef __WINDOWS__
|
||||
#define __RADWIN__
|
||||
#define __RAD16__
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#define __RADWIN__
|
||||
#define __RADNT__
|
||||
#define __RAD32__
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if (!defined(__RADDOS__) && !defined(__RADWIN__) && !defined(__RADMAC__))
|
||||
#error RAD.H did not detect your platform. Define __DOS__, __WINDOWS__, WIN32, macintosh, or powerc.
|
||||
#endif
|
||||
|
||||
#ifdef __RADMAC__
|
||||
|
||||
// this define is for CodeWarrior 11's stupid new libs (even though
|
||||
// we don't use longlong's).
|
||||
|
||||
#define __MSL_LONGLONG_SUPPORT__
|
||||
|
||||
#define RADLINK
|
||||
#define RADEXPLINK
|
||||
|
||||
#ifdef __CFM68K__
|
||||
#ifdef __RADINDLL__
|
||||
#define RADEXPFUNC RADDEFFUNC __declspec(export)
|
||||
#else
|
||||
#define RADEXPFUNC RADDEFFUNC __declspec(import)
|
||||
#endif
|
||||
#else
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
#define RADASMLINK
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __RADNT__
|
||||
#ifndef _WIN32
|
||||
#define _WIN32
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
#define WIN32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __RADWIN__
|
||||
#ifdef __RAD32__
|
||||
#ifdef __RADNT__
|
||||
|
||||
#define RADLINK __stdcall
|
||||
#define RADEXPLINK __stdcall
|
||||
|
||||
#ifdef __RADINEXE__
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#else
|
||||
#ifndef __RADINDLL__
|
||||
#define RADEXPFUNC RADDEFFUNC __declspec(dllimport)
|
||||
#ifdef __BORLANDC__
|
||||
#if __BORLANDC__<=0x460
|
||||
#undef RADEXPFUNC
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define RADEXPFUNC RADDEFFUNC __declspec(dllexport)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define RADLINK __pascal
|
||||
#define RADEXPLINK __far __pascal
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
#else
|
||||
#define RADLINK __pascal
|
||||
#define RADEXPLINK __far __pascal __export
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
#else
|
||||
#define RADLINK __pascal
|
||||
#define RADEXPLINK __pascal
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
|
||||
#define RADASMLINK __cdecl
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __RADWIN__
|
||||
#ifndef _WINDOWS
|
||||
#define _WINDOWS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define RADDEFFUNC extern "C"
|
||||
#define RADDEFSTART extern "C" {
|
||||
#define RADDEFEND }
|
||||
#else
|
||||
#define RADDEFFUNC
|
||||
#define RADDEFSTART
|
||||
#define RADDEFEND
|
||||
#endif
|
||||
|
||||
|
||||
RADDEFSTART
|
||||
|
||||
#define s8 signed char
|
||||
#define u8 unsigned char
|
||||
#define u32 unsigned long
|
||||
#define s32 signed long
|
||||
#define u64 unsigned __int64
|
||||
#define s64 signed __int64
|
||||
|
||||
#ifdef __RAD32__
|
||||
#define PTR4
|
||||
|
||||
#define u16 unsigned short
|
||||
#define s16 signed short
|
||||
|
||||
#ifdef __RADMAC__
|
||||
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <OSUtils.h>
|
||||
|
||||
#define radstrlen strlen
|
||||
|
||||
#define radmemset memset
|
||||
|
||||
#define radmemcmp memcmp
|
||||
|
||||
#define radmemcpy(dest,source,size) BlockMoveData((Ptr)(source),(Ptr)(dest),size)
|
||||
|
||||
#define radmemcpydb(dest,source,size) BlockMoveData((Ptr)(source),(Ptr)(dest),size)
|
||||
|
||||
#define radstrcat strcat
|
||||
|
||||
#define radstrcpy strcpy
|
||||
|
||||
static u32 inline radsqr(s32 a) { return(a*a); }
|
||||
|
||||
#ifdef __RAD68K__
|
||||
|
||||
#pragma parameter __D0 mult64anddiv(__D0,__D1,__D2)
|
||||
u32 mult64anddiv(u32 m1,u32 m2,u32 d) ={0x4C01,0x0C01,0x4C42,0x0C01};
|
||||
// muls.l d1,d1:d0 divs.l d2,d1:d0
|
||||
|
||||
#pragma parameter radconv32a(__A0,__D0)
|
||||
void radconv32a(void* p,u32 n) ={0x4A80,0x600C,0x2210,0xE059,0x4841,0xE059,0x20C1,0x5380,0x6EF2};
|
||||
// tst.l d0 bra.s @loope @loop: move.l (a0),d1 ror.w #8,d1 swap d1 ror.w #8,d1 move.l d1,(a0)+ sub.l #1,d0 bgt.s @loop @loope:
|
||||
|
||||
#else
|
||||
|
||||
u32 mult64anddiv(u32 m1,u32 m2,u32 d);
|
||||
|
||||
void radconv32a(void* p,u32 n);
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
|
||||
u32 radsqr(s32 a);
|
||||
#pragma aux radsqr = "mul eax" parm [eax] modify [EDX eax];
|
||||
|
||||
u32 mult64anddiv(u32 m1,u32 m2,u32 d);
|
||||
#pragma aux mult64anddiv = "mul ecx" "div ebx" parm [eax] [ecx] [ebx] modify [EDX eax];
|
||||
|
||||
s32 radabs(s32 ab);
|
||||
#pragma aux radabs = "test eax,eax" "jge skip" "neg eax" "skip:" parm [eax];
|
||||
|
||||
#define radabs32 radabs
|
||||
|
||||
u32 DOSOut(const char* str);
|
||||
#pragma aux DOSOut = "cld" "mov ecx,0xffffffff" "xor eax,eax" "mov edx,edi" "repne scasb" "not ecx" "dec ecx" "mov ebx,1" "mov ah,0x40" "int 0x21" parm [EDI] modify [EAX EBX ECX EDX EDI] value [ecx];
|
||||
|
||||
void DOSOutNum(const char* str,u32 len);
|
||||
#pragma aux DOSOutNum = "mov ah,0x40" "mov ebx,1" "int 0x21" parm [edx] [ecx] modify [eax ebx];
|
||||
|
||||
u32 ErrOut(const char* str);
|
||||
#pragma aux ErrOut = "cld" "mov ecx,0xffffffff" "xor eax,eax" "mov edx,edi" "repne scasb" "not ecx" "dec ecx" "xor ebx,ebx" "mov ah,0x40" "int 0x21" parm [EDI] modify [EAX EBX ECX EDX EDI] value [ecx];
|
||||
|
||||
void ErrOutNum(const char* str,u32 len);
|
||||
#pragma aux ErrOutNum = "mov ah,0x40" "xor ebx,ebx" "int 0x21" parm [edx] [ecx] modify [eax ebx];
|
||||
|
||||
void radmemset16(void* dest,u16 value,u32 size);
|
||||
#pragma aux radmemset16 = "cld" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,1" "rep stosd" "mov cl,bl" "and cl,1" "rep stosw" parm [EDI] [EAX] [ECX] modify [EAX EDX EBX ECX EDI];
|
||||
|
||||
void radmemset(void* dest,u8 value,u32 size);
|
||||
#pragma aux radmemset = "cld" "mov ah,al" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,2" "and bl,3" "rep stosd" "mov cl,bl" "rep stosb" parm [EDI] [AL] [ECX] modify [EAX EDX EBX ECX EDI];
|
||||
|
||||
void radmemset32(void* dest,u32 value,u32 size);
|
||||
#pragma aux radmemset32 = "cld" "rep stosd" parm [EDI] [EAX] [ECX] modify [EAX EDX EBX ECX EDI];
|
||||
|
||||
void radmemcpy(void* dest,const void* source,u32 size);
|
||||
#pragma aux radmemcpy = "cld" "mov bl,cl" "shr ecx,2" "rep movsd" "mov cl,bl" "and cl,3" "rep movsb" parm [EDI] [ESI] [ECX] modify [EBX ECX EDI ESI];
|
||||
|
||||
void __far *radfmemcpy(void __far* dest,const void __far* source,u32 size);
|
||||
#pragma aux radfmemcpy = "cld" "push es" "push ds" "mov es,cx" "mov ds,dx" "mov ecx,eax" "shr ecx,2" "rep movsd" "mov cl,al" "and cl,3" "rep movsb" "pop ds" "pop es" parm [CX EDI] [DX ESI] [EAX] modify [ECX EDI ESI] value [CX EDI];
|
||||
|
||||
void radmemcpydb(void* dest,const void* source,u32 size); //Destination bigger
|
||||
#pragma aux radmemcpydb = "std" "mov bl,cl" "lea esi,[esi+ecx-4]" "lea edi,[edi+ecx-4]" "shr ecx,2" "rep movsd" "and bl,3" "jz dne" "add esi,3" "add edi,3" "mov cl,bl" "rep movsb" "dne:" "cld" parm [EDI] [ESI] [ECX] modify [EBX ECX EDI ESI];
|
||||
|
||||
char* radstrcpy(void* dest,const void* source);
|
||||
#pragma aux radstrcpy = "cld" "mov edx,edi" "lp:" "mov al,[esi]" "inc esi" "mov [edi],al" "inc edi" "cmp al,0" "jne lp" parm [EDI] [ESI] modify [EAX EDX EDI ESI] value [EDX];
|
||||
|
||||
char __far* radfstrcpy(void __far* dest,const void __far* source);
|
||||
#pragma aux radfstrcpy = "cld" "push es" "push ds" "mov es,cx" "mov ds,dx" "mov edx,edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" "pop es" parm [CX EDI] [DX ESI] modify [EAX EDX EDI ESI] value [CX EDX];
|
||||
|
||||
char* radstpcpy(void* dest,const void* source);
|
||||
#pragma aux radstpcpy = "cld" "lp:" "mov al,[esi]" "inc esi" "mov [edi],al" "inc edi" "cmp al,0" "jne lp" "dec edi" parm [EDI] [ESI] modify [EAX EDI ESI] value [EDI];
|
||||
|
||||
char* radstpcpyrs(void* dest,const void* source);
|
||||
#pragma aux radstpcpyrs = "cld" "lp:" "mov al,[esi]" "inc esi" "mov [edi],al" "inc edi" "cmp al,0" "jne lp" "dec esi" parm [EDI] [ESI] modify [EAX EDI ESI] value [ESI];
|
||||
|
||||
u32 radstrlen(const void* dest);
|
||||
#pragma aux radstrlen = "cld" "mov ecx,0xffffffff" "xor eax,eax" "repne scasb" "not ecx" "dec ecx" parm [EDI] modify [EAX ECX EDI] value [ECX];
|
||||
|
||||
char* radstrcat(void* dest,const void* source);
|
||||
#pragma aux radstrcat = "cld" "mov ecx,0xffffffff" "mov edx,edi" "xor eax,eax" "repne scasb" "dec edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" \
|
||||
parm [EDI] [ESI] modify [EAX ECX EDI ESI] value [EDX];
|
||||
|
||||
char* radstrchr(const void* dest,char chr);
|
||||
#pragma aux radstrchr = "cld" "lp:" "lodsb" "cmp al,dl" "je fnd" "cmp al,0" "jnz lp" "mov esi,1" "fnd:" "dec esi" parm [ESI] [DL] modify [EAX ESI] value [esi];
|
||||
|
||||
s8 radmemcmp(const void* s1,const void* s2,u32 len);
|
||||
#pragma aux radmemcmp = "cld" "rep cmpsb" "setne al" "jbe end" "neg al" "end:" parm [EDI] [ESI] [ECX] modify [ECX EDI ESI];
|
||||
|
||||
s8 radstrcmp(const void* s1,const void* s2);
|
||||
#pragma aux radstrcmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,ah" "jne set" "cmp al,0" "je set" "inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
|
||||
parm [EDI] [ESI] modify [EAX EDI ESI];
|
||||
|
||||
s8 radstricmp(const void* s1,const void* s2);
|
||||
#pragma aux radstricmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" "cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
|
||||
"inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
|
||||
parm [EDI] [ESI] modify [EAX EDI ESI];
|
||||
|
||||
s8 radstrnicmp(const void* s1,const void* s2,u32 len);
|
||||
#pragma aux radstrnicmp = "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" "cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
|
||||
"dec ecx" "jz set" "inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" \
|
||||
parm [EDI] [ESI] [ECX] modify [EAX ECX EDI ESI];
|
||||
|
||||
char* radstrupr(void* s1);
|
||||
#pragma aux radstrupr = "mov ecx,edi" "lp:" "mov al,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub [edi],32" "c1:" "inc edi" "cmp al,0" "jne lp" parm [EDI] modify [EAX EDI] value [ecx];
|
||||
|
||||
char* radstrlwr(void* s1);
|
||||
#pragma aux radstrlwr = "mov ecx,edi" "lp:" "mov al,[edi]" "cmp al,'A'" "jb c1" "cmp al,'Z'" "ja c1" "add [edi],32" "c1:" "inc edi" "cmp al,0" "jne lp" parm [EDI] modify [EAX EDI] value [ecx];
|
||||
|
||||
u32 radstru32(const void* dest);
|
||||
#pragma aux radstru32 = "cld" "xor ecx,ecx" "xor ebx,ebx" "xor edi,edi" "lodsb" "cmp al,45" "jne skip2" "mov edi,1" "jmp skip" "lp:" "mov eax,10" "mul ecx" "lea ecx,[eax+ebx]" \
|
||||
"skip:" "lodsb" "skip2:" "cmp al,0x39" "ja dne" "cmp al,0x30" "jb dne" "mov bl,al" "sub bl,0x30" "jmp lp" "dne:" "test edi,1" "jz pos" "neg ecx" "pos:" \
|
||||
parm [ESI] modify [EAX EBX EDX EDI ESI] value [ecx];
|
||||
|
||||
u16 GetDS();
|
||||
#pragma aux GetDS = "mov ax,ds" value [ax];
|
||||
|
||||
#ifdef __RADWINEXT__
|
||||
|
||||
#define _16To32(ptr16) ((void*)(((GetSelectorBase((u16)(((u32)(ptr16))>>16))+((u16)(u32)(ptr16)))-GetSelectorBase(GetDS()))))
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __RADWIN__
|
||||
#define int86 int386
|
||||
#define int86x int386x
|
||||
#endif
|
||||
|
||||
#define u32regs x
|
||||
#define u16regs w
|
||||
|
||||
#else
|
||||
|
||||
#define radstrcpy strcpy
|
||||
#define radstrcat strcat
|
||||
#define radmemcpy memcpy
|
||||
#define radmemcpydb memmove
|
||||
#define radmemcmp memcmp
|
||||
#define radmemset memset
|
||||
#define radstrlen strlen
|
||||
#define radstrchr strchr
|
||||
#define radtoupper toupper
|
||||
#define radstru32(s) ((u32)atol(s))
|
||||
#define radstricmp _stricmp
|
||||
#define radstrcmp strcmp
|
||||
#define radstrupr _strupr
|
||||
#define radstrlwr _strlwr
|
||||
#define BreakPoint() _asm {int 3}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#pragma warning( disable : 4035)
|
||||
|
||||
typedef char* RADPCHAR;
|
||||
|
||||
u32 __inline radsqr(u32 m) {
|
||||
_asm {
|
||||
mov eax,[m]
|
||||
mul eax
|
||||
}
|
||||
}
|
||||
|
||||
u32 __inline mult64anddiv(u32 m1,u32 m2, u32 d) {
|
||||
_asm {
|
||||
mov eax,[m1]
|
||||
mov ecx,[m2]
|
||||
mul ecx
|
||||
mov ecx,[d]
|
||||
div ecx
|
||||
}
|
||||
}
|
||||
|
||||
s32 __inline radabs(s32 ab) {
|
||||
_asm {
|
||||
mov eax,[ab]
|
||||
test eax,eax
|
||||
jge skip
|
||||
neg eax
|
||||
skip:
|
||||
}
|
||||
}
|
||||
|
||||
u8 __inline radinp(u16 p) {
|
||||
_asm {
|
||||
mov dx,[p]
|
||||
in al,dx
|
||||
}
|
||||
}
|
||||
|
||||
void __inline radoutp(u16 p,u8 v) {
|
||||
_asm {
|
||||
mov dx,[p]
|
||||
mov al,[v]
|
||||
out dx,al
|
||||
}
|
||||
}
|
||||
|
||||
RADPCHAR __inline radstpcpy(char* p1, char* p2) {
|
||||
_asm {
|
||||
mov edx,[p1]
|
||||
mov ecx,[p2]
|
||||
cld
|
||||
lp:
|
||||
mov al,[ecx]
|
||||
inc ecx
|
||||
mov [edx],al
|
||||
inc edx
|
||||
cmp al,0
|
||||
jne lp
|
||||
dec edx
|
||||
mov eax,edx
|
||||
}
|
||||
}
|
||||
|
||||
RADPCHAR __inline radstpcpyrs(char* p1, char* p2) {
|
||||
_asm {
|
||||
mov edx,[p1]
|
||||
mov ecx,[p2]
|
||||
cld
|
||||
lp:
|
||||
mov al,[ecx]
|
||||
inc ecx
|
||||
mov [edx],al
|
||||
inc edx
|
||||
cmp al,0
|
||||
jne lp
|
||||
dec ecx
|
||||
mov eax,ecx
|
||||
}
|
||||
}
|
||||
|
||||
void __inline radmemset16(void* dest,u16 value,u32 sizeb) {
|
||||
_asm {
|
||||
mov edi,[dest]
|
||||
mov ax,[value]
|
||||
mov ecx,[sizeb]
|
||||
shl eax,16
|
||||
cld
|
||||
mov ax,[value]
|
||||
mov bl,cl
|
||||
shr ecx,1
|
||||
rep stosd
|
||||
mov cl,bl
|
||||
and cl,1
|
||||
rep stosw
|
||||
}
|
||||
}
|
||||
|
||||
void __inline radmemset32(void* dest,u32 value,u32 sizeb) {
|
||||
_asm {
|
||||
mov edi,[dest]
|
||||
mov eax,[value]
|
||||
mov ecx,[sizeb]
|
||||
cld
|
||||
rep stosd
|
||||
}
|
||||
}
|
||||
|
||||
u32 __inline __stdcall RADsqrt(u32 sq) {
|
||||
_asm {
|
||||
fild dword ptr [sq]
|
||||
fsqrt
|
||||
fistp word ptr [sq]
|
||||
movzx eax,word ptr [sq]
|
||||
}
|
||||
}
|
||||
|
||||
void __inline RADCycleTimerStartAddr(u32* addr)
|
||||
{
|
||||
_asm {
|
||||
mov ecx,[addr]
|
||||
__asm __emit 0fh __asm __emit 031h
|
||||
mov [ecx],eax
|
||||
}
|
||||
}
|
||||
|
||||
u32 __inline RADCycleTimerDeltaAddr(u32* addr)
|
||||
{
|
||||
_asm {
|
||||
__asm __emit 0fh __asm __emit 031h
|
||||
mov ecx,[addr]
|
||||
sub eax,[ecx]
|
||||
}
|
||||
}
|
||||
|
||||
#define RADCycleTimerStart(var) RADCycleTimerStartAddr(&var)
|
||||
#define RADCycleTimerDelta(var) RADCycleTimerDeltaAddr(&var)
|
||||
|
||||
#pragma warning( default : 4035)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define PTR4 __far
|
||||
|
||||
#define u16 unsigned int
|
||||
#define s16 signed int
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
|
||||
u32 radsqr(s32 a);
|
||||
#pragma aux radsqr = "shl edx,16" "mov dx,ax" "mov eax,edx" "xor edx,edx" "mul eax" "shld edx,eax,16" parm [dx ax] modify [DX ax] value [dx ax];
|
||||
|
||||
s16 radabs(s16 ab);
|
||||
#pragma aux radabs = "test ax,ax" "jge skip" "neg ax" "skip:" parm [ax] value [ax];
|
||||
|
||||
s32 radabs32(s32 ab);
|
||||
#pragma aux radabs32 = "test dx,dx" "jge skip" "neg dx" "neg ax" "sbb dx,0" "skip:" parm [dx ax] value [dx ax];
|
||||
|
||||
u32 DOSOut(const char far* dest);
|
||||
#pragma aux DOSOut = "cld" "and edi,0xffff" "mov dx,di" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "mov bx,1" "push ds" "push es" "pop ds" "mov ah,0x40" "int 0x21" "pop ds" "movzx eax,cx" "shr ecx,16" \
|
||||
parm [ES DI] modify [AX BX CX DX DI ES] value [CX AX];
|
||||
|
||||
void DOSOutNum(const char far* str,u16 len);
|
||||
#pragma aux DOSOutNum = "push ds" "mov ds,cx" "mov cx,bx" "mov ah,0x40" "mov bx,1" "int 0x21" "pop ds" parm [cx dx] [bx] modify [ax bx cx];
|
||||
|
||||
u32 ErrOut(const char far* dest);
|
||||
#pragma aux ErrOut = "cld" "and edi,0xffff" "mov dx,di" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "xor bx,bx" "push ds" "push es" "pop ds" "mov ah,0x40" "int 0x21" "pop ds" "movzx eax,cx" "shr ecx,16" \
|
||||
parm [ES DI] modify [AX BX CX DX DI ES] value [CX AX];
|
||||
|
||||
void ErrOutNum(const char far* str,u16 len);
|
||||
#pragma aux ErrOutNum = "push ds" "mov ds,cx" "mov cx,bx" "mov ah,0x40" "xor bx,bx" "int 0x21" "pop ds" parm [cx dx] [bx] modify [ax bx cx];
|
||||
|
||||
void radmemset(void far *dest,u8 value,u32 size);
|
||||
#pragma aux radmemset = "cld" "and edi,0ffffh" "shl ecx,16" "mov cx,bx" "mov ah,al" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,2" 0x67 "rep stosd" "mov cl,bl" "and cl,3" "rep stosb" parm [ES DI] [AL] [CX BX];
|
||||
|
||||
void radmemset16(void far* dest,u16 value,u32 size);
|
||||
#pragma aux radmemset16 = "cld" "and edi,0ffffh" "shl ecx,16" "mov cx,bx" "mov bx,ax" "shl eax,16" "mov ax,bx" "mov bl,cl" "shr ecx,1" "rep stosd" "mov cl,bl" "and cl,1" "rep stosw" parm [ES DI] [AX] [CX BX];
|
||||
|
||||
void radmemcpy(void far* dest,const void far* source,u32 size);
|
||||
#pragma aux radmemcpy = "cld" "push ds" "mov ds,dx" "and esi,0ffffh" "and edi,0ffffh" "shl ecx,16" "mov cx,bx" "shr ecx,2" 0x67 "rep movsd" "mov cl,bl" "and cl,3" "rep movsb" "pop ds" parm [ES DI] [DX SI] [CX BX] modify [CX SI DI ES];
|
||||
|
||||
s8 radmemcmp(const void far* s1,const void far* s2,u32 len);
|
||||
#pragma aux radmemcmp = "cld" "push ds" "mov ds,dx" "shl ecx,16" "mov cx,bx" "rep cmpsb" "setne al" "jbe end" "neg al" "end:" "pop ds" parm [ES DI] [DX SI] [CX BX] modify [CX SI DI ES];
|
||||
|
||||
char far* radstrcpy(void far* dest,const void far* source);
|
||||
#pragma aux radstrcpy = "cld" "push ds" "mov ds,dx" "and esi,0xffff" "and edi,0xffff" "mov dx,di" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" parm [ES DI] [DX SI] modify [AX DX DI SI ES] value [es dx];
|
||||
|
||||
char far* radstpcpy(void far* dest,const void far* source);
|
||||
#pragma aux radstpcpy = "cld" "push ds" "mov ds,dx" "and esi,0xffff" "and edi,0xffff" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "dec di" "pop ds" parm [ES DI] [DX SI] modify [DI SI ES] value [es di];
|
||||
|
||||
u32 radstrlen(const void far* dest);
|
||||
#pragma aux radstrlen = "cld" "and edi,0xffff" "mov ecx,0xffffffff" "xor eax,eax" 0x67 "repne scasb" "not ecx" "dec ecx" "movzx eax,cx" "shr ecx,16" parm [ES DI] modify [AX CX DI ES] value [CX AX];
|
||||
|
||||
char far* radstrcat(void far* dest,const void far* source);
|
||||
#pragma aux radstrcat = "cld" "and edi,0xffff" "mov ecx,0xffffffff" "and esi,0xffff" "push ds" "mov ds,dx" "mov dx,di" "xor eax,eax" 0x67 "repne scasb" "dec edi" "lp:" "lodsb" "stosb" "test al,0xff" "jnz lp" "pop ds" \
|
||||
parm [ES DI] [DX SI] modify [AX CX DI SI ES] value [es dx];
|
||||
|
||||
char far* radstrchr(const void far* dest,char chr);
|
||||
#pragma aux radstrchr = "cld" "lp:" 0x26 "lodsb" "cmp al,dl" "je fnd" "cmp al,0" "jnz lp" "xor ax,ax" "mov es,ax" "mov si,1" "fnd:" "dec si" parm [ES SI] [DL] modify [AX SI ES] value [es si];
|
||||
|
||||
s8 radstricmp(const void far* s1,const void far* s2);
|
||||
#pragma aux radstricmp = "and edi,0xffff" "push ds" "mov ds,dx" "and esi,0xffff" "lp:" "mov al,[esi]" "mov ah,[edi]" "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" \
|
||||
"cmp ah,'a'" "jb c2" "cmp ah,'z'" "ja c2" "sub ah,32" "c2:" "cmp al,ah" "jne set" "cmp al,0" "je set" \
|
||||
"inc esi" "inc edi" "jmp lp" "set:" "setne al" "jbe end" "neg al" "end:" "pop ds" \
|
||||
parm [ES DI] [DX SI] modify [AX DI SI];
|
||||
|
||||
u32 radstru32(const void far* dest);
|
||||
#pragma aux radstru32 = "cld" "xor ecx,ecx" "xor ebx,ebx" "xor edi,edi" 0x26 "lodsb" "cmp al,45" "jne skip2" "mov edi,1" "jmp skip" "lp:" "mov eax,10" "mul ecx" "lea ecx,[eax+ebx]" \
|
||||
"skip:" 0x26 "lodsb" "skip2:" "cmp al,0x39" "ja dne" "cmp al,0x30" "jb dne" "mov bl,al" "sub bl,0x30" "jmp lp" "dne:" "test edi,1" "jz pos" "neg ecx" "pos:" \
|
||||
"movzx eax,cx" "shr ecx,16" parm [ES SI] modify [AX BX DX DI SI] value [cx ax];
|
||||
|
||||
u32 mult64anddiv(u32 m1,u32 m2,u32 d);
|
||||
#pragma aux mult64anddiv = "shl ecx,16" "mov cx,ax" "shrd eax,edx,16" "mov ax,si" "mul ecx" "shl edi,16" "mov di,bx" "div edi" "shld edx,eax,16" "and edx,0xffff" "and eax,0xffff" parm [cx ax] [dx si] [di bx] \
|
||||
modify [ax bx cx dx si di] value [dx ax];
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
RADDEFEND
|
||||
|
||||
#define u32neg1 ((u32)(s32)-1)
|
||||
#define RAD_align(var) var; u8 junk##var[4-(sizeof(var)&3)];
|
||||
#define RAD_align_after(var) u8 junk##var[4-(sizeof(var)&3)]={0};
|
||||
#define RAD_align_init(var,val) var=val; u8 junk##var[4-(sizeof(var)&3)]={0};
|
||||
#define RAD_align_array(var,num) var[num]; u8 junk##var[4-(sizeof(var)&3)];
|
||||
#define RAD_align_string(var,str) char var[]=str; u8 junk##var[4-(sizeof(var)&3)]={0};
|
||||
|
||||
RADEXPFUNC void PTR4* RADEXPLINK radmalloc(u32 numbytes);
|
||||
RADEXPFUNC void RADEXPLINK radfree(void PTR4* ptr);
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
|
||||
char bkbhit();
|
||||
#pragma aux bkbhit = "mov ah,1" "int 0x16" "lahf" "shr eax,14" "and eax,1" "xor al,1" ;
|
||||
|
||||
char bgetch();
|
||||
#pragma aux bgetch = "xor ah,ah" "int 0x16" "test al,0xff" "jnz done" "mov al,ah" "or al,0x80" "done:" modify [AX];
|
||||
|
||||
void BreakPoint();
|
||||
#pragma aux BreakPoint = "int 3";
|
||||
|
||||
u8 radinp(u16 p);
|
||||
#pragma aux radinp = "in al,dx" parm [DX];
|
||||
|
||||
u8 radtoupper(u8 p);
|
||||
#pragma aux radtoupper = "cmp al,'a'" "jb c1" "cmp al,'z'" "ja c1" "sub al,32" "c1:" parm [al] value [al];
|
||||
|
||||
void radoutp(u16 p,u8 v);
|
||||
#pragma aux radoutp = "out dx,al" parm [DX] [AL];
|
||||
|
||||
#endif
|
||||
|
||||
// for multi-processor machines
|
||||
|
||||
#ifdef __RADNT__
|
||||
#define LockedIncrement(var) _asm { lock inc [var] }
|
||||
#define LockedDecrement(var) _asm { lock dec [var] }
|
||||
#else
|
||||
#define LockedIncrement(var) _asm { inc [var] }
|
||||
#define LockedDecrement(var) _asm { dec [var] }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
#include "Random.h"
|
||||
#include "debug control.h"
|
||||
|
||||
extern bool is_client;
|
||||
extern bool is_server;
|
||||
extern bool is_networked;
|
||||
|
||||
bool gfMPDebugOutputRandoms = false;
|
||||
|
||||
// OJW - 091024 - MP random syncing
|
||||
// need to syncronise the randomness of events in a multiplayer game on all clients
|
||||
UINT32 MPPreRandom( UINT32 uiRange )
|
||||
{
|
||||
UINT32 uiNum;
|
||||
if( uiRange == 0 )
|
||||
return 0;
|
||||
//Extract the current pregenerated number
|
||||
uiNum = guiPreRandomNums[ guiPreRandomIndex ] * uiRange / RAND_MAX % uiRange;
|
||||
|
||||
if (gfMPDebugOutputRandoms)
|
||||
{
|
||||
char tmpMPDbgString[512];
|
||||
sprintf(tmpMPDbgString,"MPPreRandom ( uiRange : %i , uiPreRandomIndex : %i , uiResult : %i )\n",uiRange, guiPreRandomIndex , uiNum );
|
||||
MPDebugMsg(tmpMPDbgString);
|
||||
}
|
||||
|
||||
//Go to the next index.
|
||||
guiPreRandomIndex++;
|
||||
|
||||
if (guiPreRandomIndex >= MAX_PREGENERATED_NUMS)
|
||||
guiPreRandomIndex = 0;
|
||||
|
||||
return uiNum;
|
||||
}
|
||||
|
||||
#ifdef BMP_RANDOM//dnl ch55 111009
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
UINT32 guiPreRandomIndex;
|
||||
UINT32 guiPreRandomNums[MAX_PREGENERATED_NUMS];
|
||||
|
||||
#include <random>
|
||||
|
||||
std::random_device gRandomDevice; // only used once to initialize (seed) engine
|
||||
std::mt19937 gRandomNumberGenerator(gRandomDevice()); // random-number engine used (Mersenne-Twister in this case)
|
||||
|
||||
UINT32 NewRandom(UINT32 max)
|
||||
{
|
||||
if (is_networked && is_client)
|
||||
return MPPreRandom(max);
|
||||
|
||||
if (max <= 1)
|
||||
return 0;
|
||||
|
||||
UINT32 min = 0;
|
||||
|
||||
std::uniform_int_distribution<int> uni(min, max - 1); // guaranteed unbiased
|
||||
|
||||
auto random_integer = uni(gRandomNumberGenerator);
|
||||
return random_integer;
|
||||
}
|
||||
|
||||
UINT32 GetRndNum(UINT32 maxnum)
|
||||
{
|
||||
if (is_networked && is_client)
|
||||
return MPPreRandom(maxnum);
|
||||
|
||||
static UINT32 rnd=0, cnt=0;
|
||||
POINT pt;
|
||||
|
||||
if(!(cnt++%RAND_MAX))
|
||||
{
|
||||
GetCursorPos(&pt);// Get cursor location
|
||||
srand(maxnum ^ rnd ^ pt.x ^ pt.y ^ GetTickCount());
|
||||
}
|
||||
if(maxnum == 0)
|
||||
return(0);
|
||||
rnd = rand();
|
||||
rnd <<= 11;
|
||||
rnd ^= rand();
|
||||
rnd <<= 7;
|
||||
rnd ^= rand();
|
||||
return(rnd % maxnum);
|
||||
}
|
||||
|
||||
void InitializeRandom(void)
|
||||
{
|
||||
// Pregenerate all of the random numbers.
|
||||
for(guiPreRandomIndex = 0; guiPreRandomIndex<MAX_PREGENERATED_NUMS; guiPreRandomIndex++)
|
||||
guiPreRandomNums[guiPreRandomIndex] = GetRndNum(0xFFFFFFFF);
|
||||
guiPreRandomIndex = 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
UINT32 guiPreRandomIndex = 0;
|
||||
std::vector<UINT32> guiPreRandomNums(MAX_PREGENERATED_NUMS, 0);
|
||||
|
||||
void InitializeRandom()
|
||||
{
|
||||
// Seed the random-number generator with current time so that
|
||||
// the numbers will be different every time we run.
|
||||
srand( (unsigned) time(NULL) );
|
||||
|
||||
//Pregenerate all of the random numbers.
|
||||
for( guiPreRandomIndex = 0; guiPreRandomIndex < MAX_PREGENERATED_NUMS; guiPreRandomIndex++ )
|
||||
{
|
||||
guiPreRandomNums[ guiPreRandomIndex ] = rand();
|
||||
}
|
||||
guiPreRandomIndex = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
+434
@@ -0,0 +1,434 @@
|
||||
#ifndef SMACKH
|
||||
#define SMACKH
|
||||
|
||||
#define SMACKVERSION "3.2f"
|
||||
|
||||
#ifndef __RADRES__
|
||||
|
||||
#include "rad.h"
|
||||
|
||||
RADDEFSTART
|
||||
|
||||
typedef struct SmackTag {
|
||||
u32 Version; // SMK2 only right now
|
||||
u32 Width; // Width (1 based, 640 for example)
|
||||
u32 Height; // Height (1 based, 480 for example)
|
||||
u32 Frames; // Number of frames (1 based, 100 = 100 frames)
|
||||
u32 MSPerFrame; // Frame Rate
|
||||
u32 SmackerType; // bit 0 set=ring frame
|
||||
u32 LargestInTrack[7]; // Largest single size for each track
|
||||
u32 tablesize; // Size of the init tables
|
||||
u32 codesize; // Compression info
|
||||
u32 absize; // ditto
|
||||
u32 detailsize; // ditto
|
||||
u32 typesize; // ditto
|
||||
u32 TrackType[7]; // high byte=0x80-Comp,0x40-PCM data,0x20-16 bit,0x10-stereo
|
||||
u32 extra; // extra value (should be zero)
|
||||
u32 NewPalette; // set to one if the palette changed
|
||||
u8 Palette[772]; // palette data
|
||||
u32 PalType; // type of palette
|
||||
u32 FrameNum; // Frame Number to be displayed
|
||||
u32 FrameSize; // The current frame's size in bytes
|
||||
u32 SndSize; // The current frame sound tracks' size in bytes
|
||||
s32 LastRectx; // Rect set in from SmackToBufferRect (X coord)
|
||||
s32 LastRecty; // Rect set in from SmackToBufferRect (Y coord)
|
||||
s32 LastRectw; // Rect set in from SmackToBufferRect (Width)
|
||||
s32 LastRecth; // Rect set in from SmackToBufferRect (Height)
|
||||
u32 OpenFlags; // flags used on open
|
||||
u32 LeftOfs; // Left Offset used in SmackTo
|
||||
u32 TopOfs; // Top Offset used in SmackTo
|
||||
u32 LargestFrameSize; // Largest frame size
|
||||
u32 Highest1SecRate; // Highest 1 sec data rate
|
||||
u32 Highest1SecFrame; // Highest 1 sec data rate starting frame
|
||||
u32 ReadError; // Set to non-zero if a read error has ocurred
|
||||
u32 addr32; // translated address for 16 bit interface
|
||||
} Smack;
|
||||
|
||||
#define SmackHeaderSize(smk) ((((u8*)&((smk)->extra))-((u8*)(smk)))+4)
|
||||
|
||||
typedef struct SmackSumTag {
|
||||
u32 TotalTime; // total time
|
||||
u32 MS100PerFrame; // MS*100 per frame (100000/MS100PerFrame=Frames/Sec)
|
||||
u32 TotalOpenTime; // Time to open and prepare for decompression
|
||||
u32 TotalFrames; // Total Frames displayed
|
||||
u32 SkippedFrames; // Total number of skipped frames
|
||||
u32 SoundSkips; // Total number of sound skips
|
||||
u32 TotalBlitTime; // Total time spent blitting
|
||||
u32 TotalReadTime; // Total time spent reading
|
||||
u32 TotalDecompTime; // Total time spent decompressing
|
||||
u32 TotalBackReadTime; // Total time spent reading in background
|
||||
u32 TotalReadSpeed; // Total io speed (bytes/second)
|
||||
u32 SlowestFrameTime; // Slowest single frame time
|
||||
u32 Slowest2FrameTime; // Second slowest single frame time
|
||||
u32 SlowestFrameNum; // Slowest single frame number
|
||||
u32 Slowest2FrameNum; // Second slowest single frame number
|
||||
u32 AverageFrameSize; // Average size of the frame
|
||||
u32 HighestMemAmount; // Highest amount of memory allocated
|
||||
u32 TotalExtraMemory; // Total extra memory allocated
|
||||
u32 HighestExtraUsed; // Highest extra memory actually used
|
||||
} SmackSum;
|
||||
|
||||
|
||||
//=======================================================================
|
||||
#define SMACKNEEDPAN 0x00020L // Will be setting the pan
|
||||
#define SMACKNEEDVOLUME 0x00040L // Will be setting the volume
|
||||
#define SMACKFRAMERATE 0x00080L // Override fr (call SmackFrameRate first)
|
||||
#define SMACKLOADEXTRA 0x00100L // Load the extra buffer during SmackOpen
|
||||
#define SMACKPRELOADALL 0x00200L // Preload the entire animation
|
||||
#define SMACKNOSKIP 0x00400L // Don't skip frames if falling behind
|
||||
#define SMACKSIMULATE 0x00800L // Simulate the speed (call SmackSim first)
|
||||
#define SMACKFILEHANDLE 0x01000L // Use when passing in a file handle
|
||||
#define SMACKTRACK1 0x02000L // Play audio track 1
|
||||
#define SMACKTRACK2 0x04000L // Play audio track 2
|
||||
#define SMACKTRACK3 0x08000L // Play audio track 3
|
||||
#define SMACKTRACK4 0x10000L // Play audio track 4
|
||||
#define SMACKTRACK5 0x20000L // Play audio track 5
|
||||
#define SMACKTRACK6 0x40000L // Play audio track 6
|
||||
#define SMACKTRACK7 0x80000L // Play audio track 7
|
||||
#define SMACKTRACKS (SMACKTRACK1|SMACKTRACK2|SMACKTRACK3|SMACKTRACK4|SMACKTRACK5|SMACKTRACK6|SMACKTRACK7)
|
||||
|
||||
#define SMACKBUFFERREVERSED 0x00000001
|
||||
#define SMACKBUFFER555 0x80000000
|
||||
#define SMACKBUFFER565 0xc0000000
|
||||
#define SMACKBUFFER16 (SMACKBUFFER555|SMACKBUFFER565)
|
||||
|
||||
#define SMACKYINTERLACE 0x100000L // Force interleaving Y scaling
|
||||
#define SMACKYDOUBLE 0x200000L // Force doubling Y scaling
|
||||
#define SMACKYNONE (SMACKYINTERLACE|SMACKYDOUBLE) // Force normal Y scaling
|
||||
#define SMACKFILEISSMK 0x2000000L // Internal flag for 16 to 32 bit thunking
|
||||
|
||||
#define SMACKAUTOEXTRA 0xffffffffL // NOT A FLAG! - Use as extrabuf param
|
||||
//=======================================================================
|
||||
|
||||
#define SMACKSURFACEFAST 0
|
||||
#define SMACKSURFACESLOW 1
|
||||
#define SMACKSURFACEDIRECT 2
|
||||
|
||||
RADEXPFUNC Smack PTR4* RADEXPLINK SmackOpen(const char PTR4* name,u32 flags,u32 extrabuf);
|
||||
|
||||
#ifdef __RADMAC__
|
||||
#include <files.h>
|
||||
|
||||
RADEXPFUNC Smack PTR4* RADEXPLINK SmackMacOpen(FSSpec* fsp,u32 flags,u32 extrabuf);
|
||||
#endif
|
||||
|
||||
RADEXPFUNC u32 RADEXPLINK SmackDoFrame(Smack PTR4* smk);
|
||||
RADEXPFUNC void RADEXPLINK SmackNextFrame(Smack PTR4* smk);
|
||||
RADEXPFUNC u32 RADEXPLINK SmackWait(Smack PTR4* smk);
|
||||
RADEXPFUNC void RADEXPLINK SmackClose(Smack PTR4* smk);
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackVolumePan(Smack PTR4* smk, u32 trackflag,u32 volume,u32 pan);
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackSummary(Smack PTR4* smk,SmackSum PTR4* sum);
|
||||
|
||||
RADEXPFUNC u32 RADEXPLINK SmackSoundInTrack(Smack PTR4* smk,u32 trackflags);
|
||||
RADEXPFUNC u32 RADEXPLINK SmackSoundOnOff(Smack PTR4* smk,u32 on);
|
||||
|
||||
#ifndef __RADMAC__
|
||||
RADEXPFUNC void RADEXPLINK SmackToScreen(Smack PTR4* smk,u32 left,u32 top,u32 BytePS,const u16 PTR4* WinTbl,void* SetBank,u32 Flags);
|
||||
#endif
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackToBuffer(Smack PTR4* smk,u32 left,u32 top,u32 Pitch,u32 destheight,const void PTR4* buf,u32 Flags);
|
||||
RADEXPFUNC u32 RADEXPLINK SmackToBufferRect(Smack PTR4* smk, u32 SmackSurface);
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackGoto(Smack PTR4* smk,u32 frame);
|
||||
RADEXPFUNC void RADEXPLINK SmackColorRemapWithTrans(Smack PTR4* smk,const void PTR4* remappal,u32 numcolors,u32 paltype,u32 transindex);
|
||||
#define SmackColorRemap(smk,remappal,numcolors,paltype) SmackColorRemapWithTrans(smk,remappal,numcolors,paltype,1000)
|
||||
RADEXPFUNC void RADEXPLINK SmackColorTrans(Smack PTR4* smk,const void PTR4* trans);
|
||||
RADEXPFUNC void RADEXPLINK SmackFrameRate(u32 forcerate);
|
||||
RADEXPFUNC void RADEXPLINK SmackSimulate(u32 sim);
|
||||
|
||||
RADEXPFUNC u32 RADEXPLINK SmackGetTrackData(Smack PTR4* smk,void PTR4* dest,u32 trackflag);
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackSoundCheck(void);
|
||||
|
||||
|
||||
//======================================================================
|
||||
|
||||
// the functions for the new SmackBlit API
|
||||
|
||||
typedef struct _SMACKBLIT PTR4* HSMACKBLIT;
|
||||
|
||||
typedef struct _SMACKBLIT {
|
||||
u32 Flags;
|
||||
u8 PTR4* Palette;
|
||||
u32 PalType;
|
||||
u16 PTR4* SmoothTable;
|
||||
u16 PTR4* Conv8to16Table;
|
||||
u32 whichmode;
|
||||
u32 palindex;
|
||||
u32 t16index;
|
||||
u32 smoothindex;
|
||||
u32 smoothtype;
|
||||
u32 firstpalette;
|
||||
} SMACKBLIT;
|
||||
|
||||
#define SMACKBLIT1X 1
|
||||
#define SMACKBLIT2X 2
|
||||
#define SMACKBLIT2XSMOOTHING 4
|
||||
#define SMACKBLIT2XINTERLACE 8
|
||||
|
||||
RADEXPFUNC HSMACKBLIT RADEXPLINK SmackBlitOpen(u32 flags);
|
||||
RADEXPFUNC void RADEXPLINK SmackBlitSetPalette(HSMACKBLIT sblit, void PTR4* Palette,u32 PalType);
|
||||
RADEXPFUNC u32 RADEXPLINK SmackBlitSetFlags(HSMACKBLIT sblit,u32 flags);
|
||||
RADEXPFUNC void RADEXPLINK SmackBlit(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, void PTR4* src, u32 srcpitch, u32 srcx, u32 srcy, u32 srcw, u32 srch);
|
||||
RADEXPFUNC void RADEXPLINK SmackBlitClear(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, u32 destw, u32 desth, s32 color);
|
||||
RADEXPFUNC void RADEXPLINK SmackBlitClose(HSMACKBLIT sblit);
|
||||
RADEXPFUNC void RADEXPLINK SmackBlitTrans(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, void PTR4* src, u32 srcpitch, u32 srcx, u32 srcy, u32 srcw, u32 srch, u32 trans);
|
||||
RADEXPFUNC void RADEXPLINK SmackBlitMask(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, void PTR4* src, u32 srcpitch, u32 srcx, u32 srcy, u32 srcw, u32 srch, u32 trans,void PTR4* mask);
|
||||
RADEXPFUNC void RADEXPLINK SmackBlitMerge(HSMACKBLIT sblit,void PTR4* dest, u32 destpitch, u32 destx, u32 desty, void PTR4* src, u32 srcpitch, u32 srcx, u32 srcy, u32 srcw, u32 srch, u32 trans,void PTR4* back);
|
||||
RADEXPFUNC char PTR4* RADEXPLINK SmackBlitString(HSMACKBLIT sblit,char PTR4* dest);
|
||||
|
||||
#ifndef __RADMAC__
|
||||
RADEXPFUNC u32 RADEXPLINK SmackUseMMX(u32 flag); //0=off, 1=on, 2=query current
|
||||
#endif
|
||||
|
||||
//======================================================================
|
||||
#ifdef __RADDOS__
|
||||
|
||||
#define SMACKSOUNDNONE -1
|
||||
|
||||
extern void* SmackTimerSetupAddr;
|
||||
extern void* SmackTimerReadAddr;
|
||||
extern void* SmackTimerDoneAddr;
|
||||
|
||||
typedef void RADEXPLINK (*SmackTimerSetupType)(void);
|
||||
typedef u32 RADEXPLINK (*SmackTimerReadType)(void);
|
||||
typedef void RADEXPLINK (*SmackTimerDoneType)(void);
|
||||
|
||||
#define SmackTimerSetup() ((SmackTimerSetupType)(SmackTimerSetupAddr))()
|
||||
#define SmackTimerRead() ((SmackTimerReadType)(SmackTimerReadAddr))()
|
||||
#define SmackTimerDone() ((SmackTimerDoneType)(SmackTimerDoneAddr))()
|
||||
|
||||
RADEXPFUNC u8 RADEXPLINK SmackSoundUseMSS(void* DigDriver);
|
||||
|
||||
#ifndef AIL_startup
|
||||
#ifdef __SW_3R
|
||||
extern s32 cdecl AIL_startup_reg(void);
|
||||
#define AIL_startup AIL_startup_reg
|
||||
#else
|
||||
extern s32 cdecl AIL_startup_stack(void);
|
||||
#define AIL_startup AIL_startup_stack
|
||||
#endif
|
||||
#endif
|
||||
#define SmackSoundMSSLiteInit() SmackSoundMSSLiteInitWithStart(&AIL_startup);
|
||||
RADEXPFUNC void RADEXPLINK SmackSoundMSSLiteInitWithStart(void* start);
|
||||
RADEXPFUNC void RADEXPLINK SmackSoundMSSLiteDone(void);
|
||||
|
||||
RADEXPFUNC u8 RADEXPLINK SmackSoundUseSOS3r(u32 SOSDriver,u32 MaxTimerSpeed);
|
||||
RADEXPFUNC u8 RADEXPLINK SmackSoundUseSOS3s(u32 SOSDriver,u32 MaxTimerSpeed);
|
||||
RADEXPFUNC u8 RADEXPLINK SmackSoundUseSOS4r(u32 SOSDriver,u32 MaxTimerSpeed);
|
||||
RADEXPFUNC u8 RADEXPLINK SmackSoundUseSOS4s(u32 SOSDriver,u32 MaxTimerSpeed);
|
||||
|
||||
#ifdef __SW_3R
|
||||
#define SmackSoundUseSOS3 SmackSoundUseSOS3r
|
||||
#define SmackSoundUseSOS4 SmackSoundUseSOS4r
|
||||
#else
|
||||
#define SmackSoundUseSOS3 SmackSoundUseSOS3s
|
||||
#define SmackSoundUseSOS4 SmackSoundUseSOS4s
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define SMACKRESRESET 0
|
||||
#define SMACKRES640X400 1
|
||||
#define SMACKRES640X480 2
|
||||
#define SMACKRES800X600 3
|
||||
#define SMACKRES1024X768 4
|
||||
|
||||
RADEXPFUNC u32 RADEXPLINK SmackSetSystemRes(u32 mode); // use SMACKRES* values
|
||||
|
||||
#define SMACKNOCUSTOMBLIT 128
|
||||
#define SMACKSMOOTHBLIT 256
|
||||
#define SMACKINTERLACEBLIT 512
|
||||
|
||||
#ifdef __RADMAC__
|
||||
|
||||
#include <windows.h>
|
||||
#include <palettes.h>
|
||||
#include <qdoffscreen.h>
|
||||
|
||||
#define SmackTimerSetup()
|
||||
#define SmackTimerDone()
|
||||
RADEXPFUNC u32 RADEXPLINK SmackTimerRead(void);
|
||||
|
||||
RADEXPFUNC s32 RADEXPLINK SmackGDSurfaceType( GDHandle gd );
|
||||
|
||||
#define SMACKAUTOBLIT 0
|
||||
#define SMACKDIRECTBLIT 1
|
||||
#define SMACKGWORLDBLIT 2
|
||||
|
||||
typedef struct SmackBufTag {
|
||||
u32 Reversed;
|
||||
u32 SurfaceType; // SMACKSURFACExxxxxx
|
||||
u32 BlitType; // SMACKxxxxxBLIT
|
||||
u32 Width;
|
||||
u32 Height;
|
||||
u32 Pitch;
|
||||
u32 Zoomed;
|
||||
u32 ZWidth;
|
||||
u32 ZHeight;
|
||||
u32 DispColors; // colors on screen
|
||||
u32 MaxPalColors;
|
||||
u32 PalColorsInUse;
|
||||
u32 StartPalColor;
|
||||
u32 EndPalColor;
|
||||
void* Buffer;
|
||||
void* Palette;
|
||||
u32 PalType;
|
||||
u32 SoftwareCursor;
|
||||
|
||||
WindowPtr wp;
|
||||
GWorldPtr gwp;
|
||||
CTabHandle cth;
|
||||
PaletteHandle palh;
|
||||
|
||||
GDHandle gd;
|
||||
u32 gdSurfaceType;
|
||||
HSMACKBLIT sblit;
|
||||
void * ScreenAddr;
|
||||
u32 ScreenPitch;
|
||||
|
||||
s32 manyblits;
|
||||
s32 PTR4* blitrects;
|
||||
s32 PTR4* rectsptr;
|
||||
s32 maxrects;
|
||||
s32 numrects;
|
||||
|
||||
} SmackBuf;
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __RADWIN__
|
||||
|
||||
#define INCLUDE_MMSYSTEM_H
|
||||
#include "windows.h"
|
||||
#include "windowsx.h"
|
||||
|
||||
#ifdef __RADNT__ // to combat WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include "mmsystem.h"
|
||||
|
||||
RADEXPFUNC s32 RADEXPLINK SmackDDSurfaceType(void* lpDDS);
|
||||
|
||||
#endif
|
||||
|
||||
#define SMACKAUTOBLIT 0
|
||||
#define SMACKFULL320X240BLIT 1
|
||||
#define SMACKFULL320X200BLIT 2
|
||||
#define SMACKFULL320X200DIRECTBLIT 3
|
||||
#define SMACKSTANDARDBLIT 4
|
||||
#define SMACKWINGBLIT 5
|
||||
#define SMACKDIBSECTIONBLIT 5
|
||||
|
||||
#define WM_SMACKACTIVATE WM_USER+0x5678
|
||||
|
||||
typedef struct SmackBufTag {
|
||||
u32 Reversed; // 1 if the buffer is upside down
|
||||
u32 SurfaceType; // SMACKSURFACExxxx defines
|
||||
u32 BlitType; // SMACKxxxxBLIT defines
|
||||
u32 FullScreen; // 1 if full-screen
|
||||
u32 Width;
|
||||
u32 Height;
|
||||
u32 Pitch;
|
||||
u32 Zoomed;
|
||||
u32 ZWidth;
|
||||
u32 ZHeight;
|
||||
u32 DispColors; // colors on the screen
|
||||
u32 MaxPalColors; // total possible colors in palette (usually 256)
|
||||
u32 PalColorsInUse; // Used colors in palette (usually 236)
|
||||
u32 StartPalColor; // first usable color index (usually 10)
|
||||
u32 EndPalColor; // last usable color index (usually 246)
|
||||
RGBQUAD Palette[256];
|
||||
u32 PalType;
|
||||
u32 forceredraw; // force a complete redraw on next blit (for >8bit)
|
||||
u32 didapalette; // force an invalidate on the next palette change
|
||||
|
||||
void PTR4* Buffer;
|
||||
void PTR4* DIBRestore;
|
||||
u32 OurBitmap;
|
||||
u32 OrigBitmap;
|
||||
u32 OurPalette;
|
||||
u32 WinGDC;
|
||||
u32 FullFocused;
|
||||
u32 ParentHwnd;
|
||||
u32 OldParWndProc;
|
||||
u32 OldDispWndProc;
|
||||
u32 DispHwnd;
|
||||
u32 WinGBufHandle;
|
||||
void PTR4* lpDD;
|
||||
void PTR4* lpDDSP;
|
||||
u32 DDSurfaceType;
|
||||
HSMACKBLIT DDblit;
|
||||
s32 ddSoftwarecur;
|
||||
s32 didaddblit;
|
||||
s32 lastwasdd;
|
||||
RECT ddscreen;
|
||||
s32 manyblits;
|
||||
s32 PTR4* blitrects;
|
||||
s32 PTR4* rectsptr;
|
||||
s32 maxrects;
|
||||
s32 numrects;
|
||||
HDC lastdc;
|
||||
} SmackBuf;
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackGet(Smack PTR4* smk,void PTR4* dest);
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferGet( SmackBuf PTR4* sbuf, void PTR4* dest);
|
||||
|
||||
RADEXPFUNC u8 RADEXPLINK SmackSoundUseMSS(void PTR4* dd);
|
||||
RADEXPFUNC u8 RADEXPLINK SmackSoundUseDirectSound(void PTR4* dd); // NULL=Create
|
||||
RADEXPFUNC void RADEXPLINK SmackSoundSetDirectSoundHWND(HWND hw);
|
||||
RADEXPFUNC u8 RADEXPLINK SmackSoundUseDW(u32 openfreq, u32 openbits, u32 openchans);
|
||||
|
||||
#define SmackTimerSetup()
|
||||
#define SmackTimerDone()
|
||||
#define SmackTimerRead timeGetTime
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __RADMAC__
|
||||
RADEXPFUNC SmackBuf PTR4* RADEXPLINK SmackBufferOpen( WindowPtr wp, u32 BlitType, u32 width, u32 height, u32 ZoomW, u32 ZoomH );
|
||||
RADEXPFUNC u32 RADEXPLINK SmackBufferBlit( SmackBuf PTR4* sbuf, s32 hwndx, s32 hwndy, s32 subx, s32 suby, s32 subw, s32 subh );
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferFromScreen( SmackBuf PTR4* destbuf, s32 x, s32 y);
|
||||
|
||||
RADEXPFUNC s32 RADEXPLINK SmackIsSoftwareCursor(GDHandle gd);
|
||||
RADEXPFUNC s32 RADEXPLINK SmackCheckCursor(WindowPtr wp,s32 x,s32 y,s32 w,s32 h);
|
||||
RADEXPFUNC void RADEXPLINK SmackRestoreCursor(s32 checkcount);
|
||||
#else
|
||||
RADEXPFUNC SmackBuf PTR4* RADEXPLINK SmackBufferOpen( HWND wnd, u32 BlitType, u32 width, u32 height, u32 ZoomW, u32 ZoomH );
|
||||
RADEXPFUNC u32 RADEXPLINK SmackBufferBlit( SmackBuf PTR4* sbuf, HDC dc, s32 hwndx, s32 hwndy, s32 subx, s32 suby, s32 subw, s32 subh );
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferFromScreen( SmackBuf PTR4* destbuf, HWND hw, s32 x, s32 y);
|
||||
|
||||
RADEXPFUNC s32 RADEXPLINK SmackIsSoftwareCursor(void* lpDDSP,HCURSOR cur);
|
||||
RADEXPFUNC s32 RADEXPLINK SmackCheckCursor(HWND wnd,s32 x,s32 y,s32 w,s32 h);
|
||||
RADEXPFUNC void RADEXPLINK SmackRestoreCursor(s32 checkcount);
|
||||
#endif
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferStartMultipleBlits( SmackBuf PTR4* sbuf );
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferEndMultipleBlits( SmackBuf PTR4* sbuf );
|
||||
|
||||
RADEXPFUNC char PTR4* RADEXPLINK SmackBufferString(SmackBuf PTR4* sb,char PTR4* dest);
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferNewPalette( SmackBuf PTR4* sbuf, const void PTR4* pal, u32 paltype );
|
||||
RADEXPFUNC u32 RADEXPLINK SmackBufferSetPalette( SmackBuf PTR4* sbuf );
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferClose( SmackBuf PTR4* sbuf );
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferClear( SmackBuf PTR4* destbuf, u32 color);
|
||||
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferToBuffer( SmackBuf PTR4* destbuf, s32 destx, s32 desty, const SmackBuf PTR4* sourcebuf,s32 sourcex,s32 sourcey,s32 sourcew,s32 sourceh);
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferToBufferTrans( SmackBuf PTR4* destbuf, s32 destx, s32 desty, const SmackBuf PTR4* sourcebuf,s32 sourcex,s32 sourcey,s32 sourcew,s32 sourceh,u32 TransColor);
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferToBufferMask( SmackBuf PTR4* destbuf, s32 destx, s32 desty, const SmackBuf PTR4* sourcebuf,s32 sourcex,s32 sourcey,s32 sourcew,s32 sourceh,u32 TransColor,const SmackBuf PTR4* maskbuf);
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferToBufferMerge( SmackBuf PTR4* destbuf, s32 destx, s32 desty, const SmackBuf PTR4* sourcebuf,s32 sourcex,s32 sourcey,s32 sourcew,s32 sourceh,u32 TransColor,const SmackBuf PTR4* mergebuf);
|
||||
RADEXPFUNC void RADEXPLINK SmackBufferCopyPalette( SmackBuf PTR4* destbuf, SmackBuf PTR4* sourcebuf, u32 remap);
|
||||
|
||||
RADEXPFUNC u32 RADEXPLINK SmackBufferFocused( SmackBuf PTR4* sbuf);
|
||||
|
||||
#endif
|
||||
|
||||
RADDEFEND
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+394
@@ -0,0 +1,394 @@
|
||||
#include <string.h>
|
||||
#include "MemMan.h"
|
||||
#include "FileMan.h"
|
||||
#include "imgfmt.h"
|
||||
#include "himage.h"
|
||||
#include "Types.h"
|
||||
#include "Debug.h"
|
||||
#include "WCheck.h"
|
||||
|
||||
BOOLEAN STCILoadRGB( HIMAGE hImage, UINT16 fContents, HWFILE hFile, STCIHeader * pHeader );
|
||||
BOOLEAN STCILoadIndexed( HIMAGE hImage, UINT16 fContents, HWFILE hFile, STCIHeader * pHeader );
|
||||
BOOLEAN STCISetPalette( PTR pSTCIPalette, HIMAGE hImage );
|
||||
|
||||
BOOLEAN LoadSTCIFileToImage( HIMAGE hImage, UINT16 fContents )
|
||||
{
|
||||
HWFILE hFile;
|
||||
STCIHeader Header;
|
||||
UINT32 uiBytesRead;
|
||||
image_type TempImage;
|
||||
|
||||
// Check that hImage is valid, and that the file in question exists
|
||||
Assert( hImage != NULL );
|
||||
|
||||
TempImage = *hImage;
|
||||
|
||||
CHECKF( FileExists( TempImage.ImageFile ) );
|
||||
|
||||
// Open the file and read the header
|
||||
hFile = FileOpen( TempImage.ImageFile, FILE_ACCESS_READ, FALSE );
|
||||
CHECKF( hFile );
|
||||
|
||||
if (!FileRead( hFile, &Header, STCI_HEADER_SIZE, &uiBytesRead ) || uiBytesRead != STCI_HEADER_SIZE || memcmp( Header.cID, STCI_ID_STRING, STCI_ID_LEN ) != 0 )
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem reading STCI header." );
|
||||
FileClose( hFile );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Determine from the header the data stored in the file. and run the appropriate loader
|
||||
if (Header.fFlags & STCI_RGB)
|
||||
{
|
||||
if( !STCILoadRGB( &TempImage, fContents, hFile, &Header ) )
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem loading RGB image." );
|
||||
FileClose( hFile );
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
else if (Header.fFlags & STCI_INDEXED)
|
||||
{
|
||||
if( !STCILoadIndexed( &TempImage, fContents, hFile, &Header ) )
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem loading palettized image." );
|
||||
FileClose( hFile );
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // unsupported type of data, or the right flags weren't set!
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Unknown data organization in STCI file." );
|
||||
FileClose( hFile );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Requested data loaded successfully.
|
||||
FileClose( hFile );
|
||||
|
||||
// Set some more flags in the temporary image structure, copy it so that hImage points
|
||||
// to it, and return.
|
||||
if (Header.fFlags & STCI_ZLIB_COMPRESSED)
|
||||
{
|
||||
TempImage.fFlags |= IMAGE_COMPRESSED;
|
||||
}
|
||||
TempImage.usWidth = Header.usWidth;
|
||||
TempImage.usHeight = Header.usHeight;
|
||||
TempImage.ubBitDepth = Header.ubDepth;
|
||||
*hImage = TempImage;
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
BOOLEAN STCILoadRGB( HIMAGE hImage, UINT16 fContents, HWFILE hFile, STCIHeader * pHeader )
|
||||
{
|
||||
UINT32 uiBytesRead;
|
||||
|
||||
if (fContents & IMAGE_PALETTE && !(fContents & IMAGE_ALLIMAGEDATA))
|
||||
{ // RGB doesn't have a palette!
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
if (fContents & IMAGE_BITMAPDATA)
|
||||
{
|
||||
// Allocate memory for the image data and read it in
|
||||
hImage->pImageData = MemAlloc( pHeader->uiStoredSize );
|
||||
if (hImage->pImageData == NULL)
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
else if (!FileRead( hFile, hImage->pImageData, pHeader->uiStoredSize, &uiBytesRead ) || uiBytesRead != pHeader->uiStoredSize)
|
||||
{
|
||||
MemFree( hImage->pImageData );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
hImage->fFlags |= IMAGE_BITMAPDATA;
|
||||
|
||||
if( pHeader->ubDepth == 16)
|
||||
{
|
||||
// ASSUMPTION: file data is 565 R,G,B
|
||||
|
||||
if (gusRedMask != (UINT16) pHeader->RGB.uiRedMask || gusGreenMask != (UINT16) pHeader->RGB.uiGreenMask || gusBlueMask != (UINT16) pHeader->RGB.uiBlueMask )
|
||||
{
|
||||
// colour distribution of the file is different from hardware! We have to change it!
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Converting to current RGB distribution!" );
|
||||
// Convert the image to the current hardware's specifications
|
||||
if (gusRedMask > gusGreenMask && gusGreenMask > gusBlueMask)
|
||||
{
|
||||
// hardware wants RGB!
|
||||
if (gusRedMask == 0x7C00 && gusGreenMask == 0x03E0 && gusBlueMask == 0x001F)
|
||||
{ // hardware is 555
|
||||
ConvertRGBDistribution565To555( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
|
||||
return( TRUE );
|
||||
}
|
||||
else if (gusRedMask == 0xFC00 && gusGreenMask == 0x03E0 && gusBlueMask == 0x001F)
|
||||
{
|
||||
ConvertRGBDistribution565To655( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
|
||||
return( TRUE );
|
||||
}
|
||||
else if (gusRedMask == 0xF800 && gusGreenMask == 0x07C0 && gusBlueMask == 0x003F)
|
||||
{
|
||||
ConvertRGBDistribution565To556( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
|
||||
return( TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
// take the long route
|
||||
ConvertRGBDistribution565ToAny( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
|
||||
return( TRUE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// hardware distribution is not R-G-B so we have to take the long route!
|
||||
ConvertRGBDistribution565ToAny( hImage->p16BPPData, pHeader->usWidth * pHeader->usHeight );
|
||||
return( TRUE );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN STCILoadIndexed( HIMAGE hImage, UINT16 fContents, HWFILE hFile, STCIHeader * pHeader )
|
||||
{
|
||||
UINT32 uiFileSectionSize;
|
||||
UINT32 uiBytesRead;
|
||||
PTR pSTCIPalette;
|
||||
|
||||
if (fContents & IMAGE_PALETTE)
|
||||
{ // Allocate memory for reading in the palette
|
||||
if (pHeader->Indexed.uiNumberOfColours != 256)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Palettized image has bad palette size." );
|
||||
return( FALSE );
|
||||
}
|
||||
uiFileSectionSize = pHeader->Indexed.uiNumberOfColours * STCI_PALETTE_ELEMENT_SIZE;
|
||||
pSTCIPalette = MemAlloc( uiFileSectionSize );
|
||||
if (pSTCIPalette == NULL)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Out of memory!" );
|
||||
FileClose( hFile );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// ATE: Memset: Jan 16/99
|
||||
memset( pSTCIPalette, 0, uiFileSectionSize );
|
||||
|
||||
// Read in the palette
|
||||
if (!FileRead( hFile, pSTCIPalette, uiFileSectionSize, &uiBytesRead ) || uiBytesRead != uiFileSectionSize)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem loading palette!" );
|
||||
FileClose( hFile );
|
||||
MemFree( pSTCIPalette );
|
||||
return( FALSE );
|
||||
}
|
||||
else if (!STCISetPalette( pSTCIPalette, hImage ))
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem setting hImage-format palette!" );
|
||||
FileClose( hFile );
|
||||
MemFree( pSTCIPalette );
|
||||
return( FALSE );
|
||||
}
|
||||
hImage->fFlags |= IMAGE_PALETTE;
|
||||
// Free the temporary buffer
|
||||
MemFree( pSTCIPalette );
|
||||
}
|
||||
else if (fContents & (IMAGE_BITMAPDATA | IMAGE_APPDATA))
|
||||
{ // seek past the palette
|
||||
uiFileSectionSize = pHeader->Indexed.uiNumberOfColours * STCI_PALETTE_ELEMENT_SIZE;
|
||||
if (FileSeek( hFile, uiFileSectionSize, FILE_SEEK_FROM_CURRENT) == FALSE)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem seeking past palette!" );
|
||||
FileClose( hFile );
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
if (fContents & IMAGE_BITMAPDATA)
|
||||
{
|
||||
if (pHeader->fFlags & STCI_ETRLE_COMPRESSED)
|
||||
{
|
||||
// load data for the subimage (object) structures
|
||||
Assert( sizeof( ETRLEObject ) == STCI_SUBIMAGE_SIZE );
|
||||
hImage->usNumberOfObjects = pHeader->Indexed.usNumberOfSubImages;
|
||||
uiFileSectionSize = hImage->usNumberOfObjects * STCI_SUBIMAGE_SIZE;
|
||||
hImage->pETRLEObject = (ETRLEObject *) MemAlloc( uiFileSectionSize );
|
||||
if (hImage->pETRLEObject == NULL)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Out of memory!" );
|
||||
FileClose( hFile );
|
||||
if (fContents & IMAGE_PALETTE)
|
||||
{
|
||||
MemFree( hImage->pPalette );
|
||||
}
|
||||
return( FALSE );
|
||||
}
|
||||
if (!FileRead( hFile, hImage->pETRLEObject, uiFileSectionSize, &uiBytesRead ) || uiBytesRead != uiFileSectionSize)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Error loading subimage structures!" );
|
||||
FileClose( hFile );
|
||||
if (fContents & IMAGE_PALETTE)
|
||||
{
|
||||
MemFree( hImage->pPalette );
|
||||
}
|
||||
MemFree( hImage->pETRLEObject );
|
||||
return( FALSE );
|
||||
}
|
||||
hImage->uiSizePixData = pHeader->uiStoredSize;
|
||||
hImage->fFlags |= IMAGE_TRLECOMPRESSED;
|
||||
}
|
||||
// allocate memory for and read in the image data
|
||||
hImage->pImageData = MemAlloc( pHeader->uiStoredSize );
|
||||
if (hImage->pImageData == NULL)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Out of memory!" );
|
||||
FileClose( hFile );
|
||||
if (fContents & IMAGE_PALETTE)
|
||||
{
|
||||
MemFree( hImage->pPalette );
|
||||
}
|
||||
if (hImage->usNumberOfObjects > 0)
|
||||
{
|
||||
MemFree( hImage->pETRLEObject );
|
||||
}
|
||||
return( FALSE );
|
||||
}
|
||||
else if (!FileRead( hFile, hImage->pImageData, pHeader->uiStoredSize, &uiBytesRead ) || uiBytesRead != pHeader->uiStoredSize)
|
||||
{ // Problem reading in the image data!
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Error loading image data!" );
|
||||
FileClose( hFile );
|
||||
MemFree( hImage->pImageData );
|
||||
if (fContents & IMAGE_PALETTE)
|
||||
{
|
||||
MemFree( hImage->pPalette );
|
||||
}
|
||||
if (hImage->usNumberOfObjects > 0)
|
||||
{
|
||||
MemFree( hImage->pETRLEObject );
|
||||
}
|
||||
return( FALSE );
|
||||
}
|
||||
hImage->fFlags |= IMAGE_BITMAPDATA;
|
||||
}
|
||||
else if (fContents & IMAGE_APPDATA) // then there's a point in seeking ahead
|
||||
{
|
||||
if (FileSeek( hFile, pHeader->uiStoredSize, FILE_SEEK_FROM_CURRENT) == FALSE)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem seeking past image data!" );
|
||||
FileClose( hFile );
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
if (fContents & IMAGE_APPDATA && pHeader->uiAppDataSize > 0)
|
||||
{
|
||||
// load application-specific data
|
||||
hImage->pAppData = (UINT8 *) MemAlloc( pHeader->uiAppDataSize );
|
||||
if (hImage->pAppData == NULL)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Out of memory!" );
|
||||
FileClose( hFile );
|
||||
MemFree( hImage->pAppData );
|
||||
if (fContents & IMAGE_PALETTE)
|
||||
{
|
||||
MemFree( hImage->pPalette );
|
||||
}
|
||||
if (fContents & IMAGE_BITMAPDATA)
|
||||
{
|
||||
MemFree( hImage->pImageData );
|
||||
}
|
||||
if (hImage->usNumberOfObjects > 0)
|
||||
{
|
||||
MemFree( hImage->pETRLEObject );
|
||||
}
|
||||
return( FALSE );
|
||||
}
|
||||
if (!FileRead( hFile, hImage->pAppData, pHeader->uiAppDataSize, &uiBytesRead ) || uiBytesRead != pHeader->uiAppDataSize)
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Error loading application-specific data!" );
|
||||
FileClose( hFile );
|
||||
MemFree( hImage->pAppData );
|
||||
if (fContents & IMAGE_PALETTE)
|
||||
{
|
||||
MemFree( hImage->pPalette );
|
||||
}
|
||||
if (fContents & IMAGE_BITMAPDATA)
|
||||
{
|
||||
MemFree( hImage->pImageData );
|
||||
}
|
||||
if (hImage->usNumberOfObjects > 0)
|
||||
{
|
||||
MemFree( hImage->pETRLEObject );
|
||||
}
|
||||
return( FALSE );
|
||||
}
|
||||
hImage->uiAppDataSize = pHeader->uiAppDataSize;;
|
||||
hImage->fFlags |= IMAGE_APPDATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
hImage->pAppData = NULL;
|
||||
hImage->uiAppDataSize = 0;
|
||||
}
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN STCISetPalette( PTR pSTCIPalette, HIMAGE hImage )
|
||||
{
|
||||
UINT16 usIndex;
|
||||
STCIPaletteElement * pubPalette;
|
||||
|
||||
pubPalette = (STCIPaletteElement *) pSTCIPalette;
|
||||
|
||||
// Allocate memory for palette
|
||||
hImage->pPalette = (SGPPaletteEntry *) MemAlloc( sizeof( SGPPaletteEntry ) * 256 );
|
||||
memset( hImage->pPalette, 0, ( sizeof( SGPPaletteEntry ) * 256 ) );
|
||||
|
||||
if ( hImage->pPalette == NULL )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Initialize the proper palette entries
|
||||
for (usIndex = 0; usIndex < 256; usIndex++)
|
||||
{
|
||||
hImage->pPalette[ usIndex ].peRed = pubPalette->ubRed;
|
||||
hImage->pPalette[ usIndex ].peGreen = pubPalette->ubGreen;
|
||||
hImage->pPalette[ usIndex ].peBlue = pubPalette->ubBlue;
|
||||
hImage->pPalette[ usIndex ].peFlags = 0;
|
||||
pubPalette ++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN IsSTCIETRLEFile( CHAR8 * ImageFile )
|
||||
{
|
||||
HWFILE hFile;
|
||||
STCIHeader Header;
|
||||
UINT32 uiBytesRead;
|
||||
|
||||
CHECKF( FileExists( ImageFile ) );
|
||||
|
||||
// Open the file and read the header
|
||||
hFile = FileOpen( ImageFile, FILE_ACCESS_READ, FALSE );
|
||||
CHECKF( hFile );
|
||||
|
||||
if (!FileRead( hFile, &Header, STCI_HEADER_SIZE, &uiBytesRead ) || uiBytesRead != STCI_HEADER_SIZE || memcmp( Header.cID, STCI_ID_STRING, STCI_ID_LEN ) != 0 )
|
||||
{
|
||||
DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem reading STCI header." );
|
||||
FileClose( hFile );
|
||||
return( FALSE );
|
||||
}
|
||||
FileClose( hFile );
|
||||
if (Header.fFlags & STCI_ETRLE_COMPRESSED)
|
||||
{
|
||||
return( TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "types.h"
|
||||
|
||||
BOOLEAN LoadSTCIFileToImage( HIMAGE hImage, UINT16 fContents );
|
||||
|
||||
BOOLEAN IsSTCIETRLEFile( CHAR8 * ImageFile );
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef _TOPICIDS_H
|
||||
#define _TOPICIDS_H
|
||||
|
||||
const unsigned INVALID_TOPIC = 0xffff;
|
||||
|
||||
const unsigned TOPIC_DECISIONS = 25;
|
||||
const unsigned TOPIC_MEMORY_MANAGER = 24;
|
||||
const unsigned TOPIC_FILE_MANAGER = 23;
|
||||
const unsigned TOPIC_DATABASE_MANAGER = 22;
|
||||
const unsigned TOPIC_GAME = 21;
|
||||
const unsigned TOPIC_SGP = 20;
|
||||
const unsigned TOPIC_VIDEO = 19;
|
||||
const unsigned TOPIC_INPUT = 18;
|
||||
const unsigned TOPIC_STACK_CONTAINERS = 17;
|
||||
const unsigned TOPIC_LIST_CONTAINERS = 16;
|
||||
const unsigned TOPIC_QUEUE_CONTAINERS = 15;
|
||||
const unsigned TOPIC_PRILIST_CONTAINERS = 14;
|
||||
const unsigned TOPIC_HIMAGE = 13;
|
||||
const unsigned TOPIC_ORDLIST_CONTAINERS = 12;
|
||||
const unsigned TOPIC_3DENGINE = 11;
|
||||
const unsigned TOPIC_VIDEOOBJECT = 10;
|
||||
const unsigned TOPIC_FONT_HANDLER = 9;
|
||||
const unsigned TOPIC_VIDEOSURFACE = 8;
|
||||
const unsigned TOPIC_MOUSE_SYSTEM = 7;
|
||||
const unsigned TOPIC_BUTTON_HANDLER = 6;
|
||||
const unsigned TOPIC_JA2INTERRUPT = 4;
|
||||
const unsigned TOPIC_JA2 = 3;
|
||||
const unsigned TOPIC_BLIT_QUEUE = INVALID_TOPIC;
|
||||
const unsigned TOPIC_JA2OPPLIST = 2;
|
||||
const unsigned TOPIC_JA2AI = 1;
|
||||
|
||||
#endif // NUM_TOPICS_IDS
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef _TopicOps_h
|
||||
#define _TopicOps_h
|
||||
|
||||
// debug levels
|
||||
|
||||
#define DBG_LEVEL_0 0 // for registering and unregistering topics only
|
||||
#define DBG_LEVEL_1 1 // for basic stuff
|
||||
#define DBG_LEVEL_2 2 // for ordinary, I usually want to see them, messages
|
||||
#define DBG_LEVEL_3 3 // nitty gritty detail
|
||||
|
||||
// from client
|
||||
|
||||
#define TOPIC_REGISTER 0
|
||||
#define TOPIC_UNREGISTER 1
|
||||
#define TOPIC_MESSAGE 2
|
||||
#define CLIENT_REGISTER 3
|
||||
#define CLIENT_SHUTDOWN 4
|
||||
|
||||
// from server
|
||||
|
||||
#define SYSTEM_SHUTDOWN 0
|
||||
#define MODULE_RESET 1
|
||||
#define SET_DEBUG_LEVEL 2
|
||||
|
||||
#endif
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
#ifndef __TYPES_
|
||||
#define __TYPES_
|
||||
|
||||
#ifndef _SIRTECH_TYPES_
|
||||
#define _SIRTECH_TYPES_
|
||||
|
||||
#ifdef RELEASE_WITH_DEBUG_INFO
|
||||
|
||||
//For JA2 Release with debug info build, disable these warnigs messages
|
||||
#pragma warning( disable : 4201 4214 4057 4100 4514 4115 4711 4244 )
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// build defines header....
|
||||
#include "builddefines.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#include <wchar.h> // for wide-character strings
|
||||
|
||||
// *** SIR-TECH TYPE DEFINITIONS ***
|
||||
|
||||
// These two types are defined by VC6 and were causing redefinition
|
||||
// problems, but JA2 is compiled with VC5
|
||||
|
||||
// HEY WIZARDRY DUDES, JA2 ISN'T THE ONLY PROGRAM WE COMPILE! :-)
|
||||
|
||||
typedef unsigned int UINT32;
|
||||
typedef signed __int64 INT64; // WANNE - BMP: Used for Big Maps
|
||||
typedef signed int INT32;
|
||||
typedef unsigned __int64 UINT64;
|
||||
//typedef unsigned long long UINT128; //Madd: Doing away with this redundant type
|
||||
|
||||
// integers
|
||||
typedef unsigned char UINT8;
|
||||
typedef signed char INT8;
|
||||
typedef unsigned short UINT16;
|
||||
typedef signed short INT16;
|
||||
// floats
|
||||
typedef float FLOAT;
|
||||
typedef double DOUBLE;
|
||||
// strings
|
||||
typedef char CHAR8;
|
||||
typedef wchar_t CHAR16;
|
||||
typedef CHAR8 * STR;
|
||||
typedef CHAR8 * STR8;
|
||||
typedef CHAR16 * STR16;
|
||||
// flags (individual bits used)
|
||||
typedef unsigned char FLAGS8;
|
||||
typedef unsigned short FLAGS16;
|
||||
typedef unsigned long FLAGS32;
|
||||
// other
|
||||
typedef unsigned char BOOLEAN;
|
||||
typedef void * PTR;
|
||||
typedef unsigned short HNDL;
|
||||
typedef UINT8 BYTE;
|
||||
typedef CHAR8 STRING512[512];
|
||||
typedef UINT32 HWFILE;
|
||||
|
||||
#define SGPFILENAME_LEN 100
|
||||
typedef CHAR8 SGPFILENAME[SGPFILENAME_LEN];
|
||||
|
||||
// *** SIR-TECH TYPE DEFINITIONS ***
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define BAD_INDEX -1
|
||||
|
||||
#define NULL_HANDLE 65535
|
||||
|
||||
#define PI 3.1415926
|
||||
|
||||
#define ST_EPSILON 0.00001 // define a sir-tech epsilon value
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
INT32 x;
|
||||
INT32 y;
|
||||
INT32 width;
|
||||
INT32 height;
|
||||
|
||||
} SGPRectangle;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
INT32 iLeft;
|
||||
INT32 iTop;
|
||||
INT32 iRight;
|
||||
INT32 iBottom;
|
||||
|
||||
} SGPRect;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
INT32 iX;
|
||||
INT32 iY;
|
||||
|
||||
} SGPPoint;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
INT32 Min;
|
||||
INT32 Max;
|
||||
|
||||
} SGPRange;
|
||||
|
||||
|
||||
typedef FLOAT VECTOR2[2]; // 2d vector (2x1 matrix)
|
||||
typedef FLOAT VECTOR3[3]; // 3d vector (3x1 matrix)
|
||||
typedef FLOAT VECTOR4[4]; // 4d vector (4x1 matrix)
|
||||
|
||||
typedef INT32 IVECTOR2[2]; // 2d vector (2x1 matrix)
|
||||
typedef INT32 IVECTOR3[3]; // 3d vector (3x1 matrix)
|
||||
typedef INT32 IVECTOR4[4]; // 4d vector (4x1 matrix)
|
||||
|
||||
typedef VECTOR3 MATRIX3[3]; // 3x3 matrix
|
||||
typedef VECTOR4 MATRIX4[4]; // 4x4 matrix
|
||||
|
||||
//typedef VECTOR3 ANGLE; // angle return array //lal removed
|
||||
typedef VECTOR4 COLOR; // rgba color array
|
||||
|
||||
|
||||
#include <vfs/Aspects/vfs_settings.h>
|
||||
#include <vfs/Core/vfs_string.h>
|
||||
|
||||
inline void convert_string(std::wstring const& str_in, std::string &str_out)
|
||||
{
|
||||
if(vfs::Settings::getUseUnicode())
|
||||
{
|
||||
str_out = vfs::String::as_utf8(str_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs::String::narrow(str_in, str_out);
|
||||
}
|
||||
}
|
||||
|
||||
inline void convert_string(std::string const& str_in, std::wstring &str_out)
|
||||
{
|
||||
if(vfs::Settings::getUseUnicode())
|
||||
{
|
||||
vfs::String::as_utf16(str_in, str_out);
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs::String::widen(str_in, str_out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef __WCHECK_
|
||||
#define __WCHECK_
|
||||
|
||||
#define CHECKF(exp) if (!(exp)) { return(FALSE); }
|
||||
#define CHECKV(exp) if (!(exp)) { return; }
|
||||
#define CHECKN(exp) if (!(exp)) { return(NULL); }
|
||||
#define CHECKBI(exp) if (!(exp)) { return(-1); }
|
||||
|
||||
#define CHECKASSERTF(exp) if (!(exp)) { ASSERT(0); return(FALSE); }
|
||||
#define CHECKASSERTV(exp) if (!(exp)) { ASSERT(0); return; }
|
||||
#define CHECKASSERTN(exp) if (!(exp)) { ASSERT(0); return(NULL); }
|
||||
#define CHECKASSERTBI(exp) if (!(exp)) { ASSERT(0); return(-1); }
|
||||
|
||||
#endif
|
||||
+514
@@ -0,0 +1,514 @@
|
||||
|
||||
//#define UNICODE
|
||||
#include "types.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <malloc.h>
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include "sgp.h"
|
||||
#include "memman.h"
|
||||
#include "fileman.h"
|
||||
#include "Font.h"
|
||||
#include "Debug.h"
|
||||
#include "vsurface.h"
|
||||
#include "vsurface_private.h"
|
||||
#include "DirectX Common.h"
|
||||
#include <ddraw.h>
|
||||
#include "winfont.h"
|
||||
#include "font.h"
|
||||
#include "Font Control.h"
|
||||
#include "GameSettings.h"
|
||||
|
||||
#include <vfs/Tools/vfs_property_container.h>
|
||||
|
||||
INT32 FindFreeWinFont( void );
|
||||
|
||||
// Private struct not to be exported
|
||||
// to other modules
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HFONT hFont;
|
||||
COLORVAL ForeColor;
|
||||
COLORVAL BackColor;
|
||||
UINT8 Height;
|
||||
UINT8 InternalLeading;
|
||||
#ifdef CHINESE
|
||||
UINT8 Width[0x80];
|
||||
#endif
|
||||
} HWINFONT;
|
||||
|
||||
LONG gWinFontAdjust;
|
||||
HWINFONT WinFonts[WIN_LASTFONT + 2]; // extra space for the tooltip fonts
|
||||
|
||||
INT32 WinFontMap[MAX_WINFONTMAP];
|
||||
|
||||
struct {
|
||||
char FontName[32]; //the key name
|
||||
LOGFONT LogFont; //read it from GAME_INI_FILE
|
||||
COLORVAL Color;
|
||||
} FontInfo[] = {
|
||||
{"LargeFont1", {-12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(98, 98, 98)},
|
||||
{"SmallFont1", {-11, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(98, 98, 98)},
|
||||
{"TinyFont1", {-12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(98, 98, 98)},
|
||||
{"12PointFont1", {-14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, 0},
|
||||
{"CompFont", {-12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(0, 255, 0)},
|
||||
{"SmallCompFont", {-10, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(98, 98, 98)},
|
||||
{"10PointRoman", {-12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(0, 255 , 0)},
|
||||
{"12PointRoman", {-14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(0, 255 , 0)},
|
||||
{"14PointSansSerif", {-16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(0, 255 , 0)},
|
||||
{"10PointArial", {-11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, 0},
|
||||
{"14PointArial", {-16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(0, 255 , 0)},
|
||||
{"12PointArial", {-13, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(222, 222, 222)},
|
||||
{"BlockyFont", {-11, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(217, 217, 217)},
|
||||
{"BlockyFont2", {-12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(217, 217, 217)},
|
||||
{"10PointArialBold", {-11, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, 0},
|
||||
{"12PointArialFixedFont", {-12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, 0},
|
||||
{"16PointArial", {-20, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(222, 222, 222)},
|
||||
{"BlockFontNarrow", {-11, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(128, 0 , 0)},
|
||||
{"14PointHumanist", {-15, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(255, 0, 0)},
|
||||
{"HugeFont", {-19, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(0, 255, 0)}
|
||||
};
|
||||
|
||||
INT32 TOOLTIP_IFONT = -1;
|
||||
INT32 TOOLTIP_IFONT_BOLD = -1;
|
||||
|
||||
void Convert16BitStringTo8Bit( CHAR8 *dst, CHAR16 *src )
|
||||
{
|
||||
//hope 'dst' is big enough
|
||||
WideCharToMultiByte(CP_ACP, 0, src, -1, dst, 512 ,NULL,NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
void GetWinFontInfo()
|
||||
{
|
||||
/*
|
||||
;default settings, can be changed in GAME_INI_FILE
|
||||
|
||||
[LargeFont1]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=400
|
||||
|
||||
[SmallFont1]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=400
|
||||
|
||||
[TinyFont1]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=400
|
||||
|
||||
[12PointFont1]
|
||||
Name=Tahoma
|
||||
Height=-14
|
||||
Weight=400
|
||||
|
||||
[CompFont]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=400
|
||||
|
||||
[SmallCompFont]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=400
|
||||
|
||||
[10PointRoman]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=400
|
||||
|
||||
[12PointRoman]
|
||||
Name=Tahoma
|
||||
Height=-14
|
||||
Weight=400
|
||||
|
||||
[14PointSansSerif]
|
||||
Name=Tahoma
|
||||
Height=-16
|
||||
Weight=400
|
||||
|
||||
[10PointArial]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=400
|
||||
|
||||
[14PointArial]
|
||||
Name=Tahoma
|
||||
Height=-16
|
||||
Weight=700
|
||||
|
||||
[12PointArial]
|
||||
Name=Tahoma
|
||||
Height=-14
|
||||
Weight=400
|
||||
|
||||
[BlockyFont]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=700
|
||||
|
||||
[BlockyFont2]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=700
|
||||
|
||||
[10PointArialBold]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=400
|
||||
|
||||
[12PointArialFixedFont]
|
||||
Name=Tahoma
|
||||
Height=-14
|
||||
Weight=400
|
||||
|
||||
[16PointArial]
|
||||
Name=Tahoma
|
||||
Height=-18
|
||||
Weight=400
|
||||
|
||||
[BlockFontNarrow]
|
||||
Name=Tahoma
|
||||
Height=-12
|
||||
Weight=700
|
||||
|
||||
[14PointHumanist]
|
||||
Name=Tahoma
|
||||
Height=-16
|
||||
Weight=400
|
||||
|
||||
[HugeFont]
|
||||
Name=Tahoma
|
||||
Height=-20
|
||||
Weight=400
|
||||
*/
|
||||
vfs::PropertyContainer props;
|
||||
props.initFromIniFile(GAME_INI_FILE);
|
||||
|
||||
gWinFontAdjust = (LONG)props.getIntProperty(L"Ja2 Settings", L"WIN_FONT_ADJUST", 0);
|
||||
for (UINT16 i=0; i<WIN_LASTFONT; i++)
|
||||
{
|
||||
vfs::String name = props.getStringProperty(FontInfo[i].FontName, L"Name", FontInfo[i].LogFont.lfFaceName);
|
||||
strncpy(FontInfo[i].LogFont.lfFaceName, name.utf8().c_str(), LF_FACESIZE);
|
||||
|
||||
FontInfo[i].LogFont.lfHeight = gWinFontAdjust + (LONG)props.getIntProperty(FontInfo[i].FontName, "Height", FontInfo[i].LogFont.lfHeight);
|
||||
FontInfo[i].LogFont.lfWeight = (LONG)props.getIntProperty(FontInfo[i].FontName, "Weight", FontInfo[i].LogFont.lfWeight);
|
||||
}
|
||||
}
|
||||
|
||||
void InitWinFonts( )
|
||||
{
|
||||
INT32 FontSlot[WIN_LASTFONT];
|
||||
memset( WinFonts, 0, sizeof( WinFonts ) );
|
||||
|
||||
GetWinFontInfo();
|
||||
|
||||
for (int i = 0; i<WIN_LASTFONT; i++)
|
||||
{
|
||||
FontSlot[i] = CreateWinFont(FontInfo[i].LogFont);
|
||||
SetWinFontForeColor(FontSlot[i], &FontInfo[i].Color);
|
||||
}
|
||||
|
||||
//can't use switch here, because FONT12ARIAL, LARGEFONT1... are variables
|
||||
for (int i=0; i<MAX_WINFONTMAP; i++)
|
||||
{
|
||||
if (i == FONT12ARIAL)
|
||||
{WinFontMap[i] = FontSlot[WIN_12POINTARIAL];}
|
||||
else if (i == LARGEFONT1)
|
||||
{WinFontMap[i] = FontSlot[WIN_LARGEFONT1];}
|
||||
else if (i == SMALLFONT1)
|
||||
{WinFontMap[i] = FontSlot[WIN_SMALLFONT1];}
|
||||
else if (i == TINYFONT1)
|
||||
{WinFontMap[i] = FontSlot[WIN_TINYFONT1];}
|
||||
else if (i == FONT12POINT1)
|
||||
{WinFontMap[i] = FontSlot[WIN_12POINTFONT1];}
|
||||
else if (i == COMPFONT)
|
||||
{WinFontMap[i] = FontSlot[WIN_COMPFONT];}
|
||||
else if (i == SMALLCOMPFONT)
|
||||
{WinFontMap[i] = FontSlot[WIN_SMALLCOMPFONT];}
|
||||
else if (i == FONT10ROMAN)
|
||||
{WinFontMap[i] = FontSlot[WIN_10POINTROMAN];}
|
||||
else if (i == FONT12ROMAN)
|
||||
{WinFontMap[i] = FontSlot[WIN_12POINTROMAN];}
|
||||
else if (i == FONT14SANSERIF)
|
||||
{WinFontMap[i] = FontSlot[WIN_14POINTSANSSERIF];}
|
||||
else if (i == MILITARYFONT1)
|
||||
{WinFontMap[i] = FontSlot[WIN_BLOCKYFONT];}
|
||||
else if (i == FONT10ARIAL)
|
||||
{WinFontMap[i] = FontSlot[WIN_10POINTARIAL];}
|
||||
else if (i == FONT14ARIAL)
|
||||
{WinFontMap[i] = FontSlot[WIN_14POINTARIAL];}
|
||||
else if (i == FONT10ARIALBOLD)
|
||||
{WinFontMap[i] = FontSlot[WIN_10POINTARIALBOLD];}
|
||||
else if (i == BLOCKFONT)
|
||||
{WinFontMap[i] = FontSlot[WIN_BLOCKYFONT];}
|
||||
else if (i == BLOCKFONT2)
|
||||
{WinFontMap[i] = FontSlot[WIN_BLOCKYFONT2];}
|
||||
else if (i == FONT12ARIALFIXEDWIDTH)
|
||||
{WinFontMap[i] = FontSlot[WIN_12POINTARIALFIXEDFONT];}
|
||||
else if (i == FONT16ARIAL)
|
||||
{WinFontMap[i] = FontSlot[WIN_16POINTARIAL];}
|
||||
else if (i == BLOCKFONTNARROW)
|
||||
{WinFontMap[i] = FontSlot[WIN_BLOCKFONTNARROW];}
|
||||
else if (i == FONT14HUMANIST)
|
||||
{WinFontMap[i] = FontSlot[WIN_14POINTHUMANIST];}
|
||||
else {WinFontMap[i] = -1;}
|
||||
}
|
||||
}
|
||||
|
||||
void ShutdownWinFonts( )
|
||||
{
|
||||
for (int i=0; i<MAX_WINFONTMAP; i++)
|
||||
{DeleteWinFont(i);}
|
||||
}
|
||||
|
||||
void InitTooltipFonts()
|
||||
{
|
||||
LOGFONT logFont = { -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE,
|
||||
"Arial"
|
||||
};
|
||||
logFont.lfHeight = logFont.lfHeight * fTooltipScaleFactor;
|
||||
|
||||
LOGFONT boldTooltipLogFont = logFont;
|
||||
boldTooltipLogFont.lfWeight = FW_BOLD;
|
||||
|
||||
TOOLTIP_IFONT = CreateWinFont(logFont);
|
||||
TOOLTIP_IFONT_BOLD = CreateWinFont(boldTooltipLogFont);
|
||||
|
||||
COLORVAL regularColor = FROMRGB(201, 197, 143);
|
||||
COLORVAL boldColor = FROMRGB(223, 176, 1);
|
||||
SetWinFontForeColor(TOOLTIP_IFONT, ®ularColor);
|
||||
SetWinFontForeColor(TOOLTIP_IFONT_BOLD, &boldColor);
|
||||
}
|
||||
|
||||
void ShutdownTooltipFonts()
|
||||
{
|
||||
ShutdownWinFonts();
|
||||
}
|
||||
|
||||
INT32 FindFreeWinFont( void )
|
||||
{
|
||||
INT32 iCount;
|
||||
|
||||
for( iCount = 0; iCount < MAX_WINFONTMAP; iCount++ )
|
||||
{
|
||||
if( WinFonts[ iCount ].hFont == NULL )
|
||||
{
|
||||
return( iCount );
|
||||
}
|
||||
}
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
|
||||
HWINFONT *GetWinFont( INT32 iFont )
|
||||
{
|
||||
if (iFont == -1 || iFont >= sizeof(WinFonts) )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if ( WinFonts[ iFont ].hFont == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
return( &( WinFonts[ iFont ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
INT32 CreateWinFont( LOGFONT &logfont )
|
||||
{
|
||||
INT32 iFont;
|
||||
HFONT hFont;
|
||||
// Find free slot
|
||||
iFont = FindFreeWinFont( );
|
||||
|
||||
if ( iFont == -1 )
|
||||
{
|
||||
return( iFont );
|
||||
}
|
||||
|
||||
|
||||
//ATTEMPT TO LOAD THE FONT NOW
|
||||
hFont = CreateFontIndirect( &logfont );
|
||||
if (hFont == NULL)
|
||||
{
|
||||
FatalError( "Cannot load subtitle Windows Font: %S.", logfont.lfFaceName);
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
// Set font....
|
||||
WinFonts[ iFont ].hFont = hFont;
|
||||
|
||||
HDC hdc = GetDC(NULL);
|
||||
SelectObject(hdc, hFont);
|
||||
|
||||
#ifdef CHINESE
|
||||
SIZE RectSize;
|
||||
wchar_t str[2]=L"\1";
|
||||
for (int i = 1; i<0x80; i++)
|
||||
{
|
||||
GetTextExtentPoint32W( hdc, str, 1, &RectSize );
|
||||
WinFonts[iFont].Width[i]=(UINT8)RectSize.cx;
|
||||
str[0]++;
|
||||
}
|
||||
str[0] = L'啊';
|
||||
GetTextExtentPoint32W( hdc, str, 1, &RectSize );
|
||||
WinFonts[iFont].Width[0] = (UINT8)RectSize.cx;
|
||||
#endif
|
||||
|
||||
TEXTMETRIC tm;
|
||||
GetTextMetrics(hdc, &tm);
|
||||
WinFonts[ iFont ].Height = (UINT8)tm.tmAscent;
|
||||
WinFonts[ iFont ].InternalLeading = (UINT8)tm.tmInternalLeading;
|
||||
ReleaseDC(NULL, hdc);
|
||||
|
||||
return( iFont );
|
||||
}
|
||||
|
||||
void DeleteWinFont( INT32 iFont )
|
||||
{
|
||||
HWINFONT *pWinFont;
|
||||
|
||||
pWinFont = GetWinFont( iFont );
|
||||
|
||||
if ( pWinFont != NULL )
|
||||
{
|
||||
DeleteObject( pWinFont->hFont );
|
||||
pWinFont->hFont = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SetWinFontForeColor( INT32 iFont, COLORVAL *pColor )
|
||||
{
|
||||
HWINFONT *pWinFont;
|
||||
|
||||
pWinFont = GetWinFont( iFont );
|
||||
|
||||
if ( pWinFont != NULL )
|
||||
{
|
||||
pWinFont->ForeColor = ( *pColor );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SetWinFontBackColor( INT32 iFont, COLORVAL *pColor )
|
||||
{
|
||||
HWINFONT *pWinFont;
|
||||
|
||||
pWinFont = GetWinFont( iFont );
|
||||
|
||||
if ( pWinFont != NULL )
|
||||
{
|
||||
pWinFont->BackColor = ( *pColor );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
CHAR16 string[512];
|
||||
HVSURFACE hVSurface;
|
||||
LPDIRECTDRAWSURFACE2 pDDSurface;
|
||||
HDC hdc;
|
||||
HWINFONT *pWinFont;
|
||||
int len;
|
||||
|
||||
pWinFont = GetWinFont( iFont );
|
||||
|
||||
if ( pWinFont == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
va_start(argptr, pFontString); // Set up variable argument pointer
|
||||
len = vswprintf(string, pFontString, argptr); // process gprintf string (get output str)
|
||||
va_end(argptr);
|
||||
|
||||
// Get surface...
|
||||
GetVideoSurface( &hVSurface, uiDestBuf );
|
||||
|
||||
pDDSurface = GetVideoSurfaceDDSurface( hVSurface );
|
||||
|
||||
IDirectDrawSurface2_GetDC( pDDSurface, &hdc );
|
||||
|
||||
SelectObject(hdc, pWinFont->hFont );
|
||||
SetTextColor( hdc, pWinFont->ForeColor );
|
||||
SetBkColor(hdc, pWinFont->BackColor );
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
SetTextAlign(hdc, TA_TOP|TA_LEFT);
|
||||
|
||||
if (y - pWinFont->InternalLeading >=0)
|
||||
{
|
||||
y -= pWinFont->InternalLeading;
|
||||
}
|
||||
TextOutW( hdc, x, y, string, len );
|
||||
|
||||
IDirectDrawSurface2_ReleaseDC( pDDSurface, hdc );
|
||||
|
||||
}
|
||||
|
||||
INT16 WinFontStringPixLength( STR16 string2, INT32 iFont )
|
||||
{
|
||||
HWINFONT *pWinFont;
|
||||
pWinFont = GetWinFont( iFont );
|
||||
|
||||
if (pWinFont == NULL) return(0);
|
||||
|
||||
#ifdef CHINESE
|
||||
wchar_t *p=string2;
|
||||
UINT32 size = 0;
|
||||
while (*p!=0)
|
||||
{
|
||||
if (*p != L'|')
|
||||
{
|
||||
if (*p>0x80)
|
||||
{size+=pWinFont->Width[0];}
|
||||
else
|
||||
{size+=pWinFont->Width[*p];}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return size;
|
||||
#else
|
||||
SIZE RectSize;
|
||||
HDC hdc = GetDC(NULL);
|
||||
|
||||
SelectObject(hdc, pWinFont->hFont );
|
||||
GetTextExtentPoint32W( hdc, string2, lstrlenW(string2), &RectSize );
|
||||
ReleaseDC(NULL, hdc);
|
||||
|
||||
return( (INT16)RectSize.cx );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
INT16 GetWinFontHeight(INT32 iFont)
|
||||
{
|
||||
HWINFONT* pWinFont;
|
||||
|
||||
pWinFont = GetWinFont(iFont);
|
||||
|
||||
if (pWinFont == NULL) return(0);
|
||||
#ifdef CHINESE //zwwooooo: Correct tactical interface font height to fixed Chinese characters smearing bug
|
||||
if (iFont == WinFontMap[TINYFONT1] || iFont == WinFontMap[SMALLFONT1] || iFont == WinFontMap[FONT14ARIAL])
|
||||
{
|
||||
return pWinFont->Height + 2;
|
||||
}
|
||||
#endif
|
||||
return pWinFont->Height;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef __WINFONT_
|
||||
#define __WINFONT_
|
||||
#include <windows.h>
|
||||
|
||||
void InitWinFonts( );
|
||||
void ShutdownWinFonts( );
|
||||
|
||||
void InitTooltipFonts();
|
||||
void ShutdownTooltipFonts();
|
||||
|
||||
INT32 CreateWinFont( LOGFONT &logfont );
|
||||
void DeleteWinFont( INT32 iFont );
|
||||
|
||||
void SetWinFontBackColor( INT32 iFont, COLORVAL *pColor );
|
||||
void SetWinFontForeColor( INT32 iFont, COLORVAL *pColor );
|
||||
|
||||
void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...);
|
||||
|
||||
INT16 WinFontStringPixLength( STR16 string, INT32 iFont );
|
||||
INT16 GetWinFontHeight( INT32 iFont );
|
||||
|
||||
//if you cahnge this enum, you must change FontInfo struct in WinFont.cpp too.
|
||||
enum {
|
||||
WIN_LARGEFONT1 = 0,
|
||||
WIN_SMALLFONT1,
|
||||
WIN_TINYFONT1,
|
||||
WIN_12POINTFONT1,
|
||||
WIN_COMPFONT,
|
||||
WIN_SMALLCOMPFONT,
|
||||
WIN_10POINTROMAN,
|
||||
WIN_12POINTROMAN,
|
||||
WIN_14POINTSANSSERIF,
|
||||
WIN_10POINTARIAL,
|
||||
WIN_14POINTARIAL,
|
||||
WIN_12POINTARIAL,
|
||||
WIN_BLOCKYFONT,
|
||||
WIN_BLOCKYFONT2,
|
||||
WIN_10POINTARIALBOLD,
|
||||
WIN_12POINTARIALFIXEDFONT,
|
||||
WIN_16POINTARIAL,
|
||||
WIN_BLOCKFONTNARROW,
|
||||
WIN_14POINTHUMANIST,
|
||||
WIN_HUGEFONT,
|
||||
WIN_LASTFONT
|
||||
};
|
||||
#define MAX_WINFONTMAP 25
|
||||
extern INT32 WinFontMap[MAX_WINFONTMAP];
|
||||
extern INT32 TOOLTIP_IFONT;
|
||||
extern INT32 TOOLTIP_IFONT_BOLD;
|
||||
|
||||
#endif
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-1996 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* $Id: ZCONF.H,v 1.2 2004/03/16 02:00:39 digicrab Exp $ */
|
||||
|
||||
#ifndef _ZCONF_H
|
||||
#define _ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateReset z_inflateReset
|
||||
# define compress z_compress
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||
# define WIN32
|
||||
#endif
|
||||
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
|
||||
# ifndef __32BIT__
|
||||
# define __32BIT__
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#if defined(MSDOS) && !defined(__32BIT__)
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
|
||||
# define STDC
|
||||
#endif
|
||||
#if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
|
||||
# define STDC
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
1 << (windowBits+2) + 1 << (memLevel+9)
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR __far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
# ifndef __32BIT__
|
||||
# define SMALL_MEDIUM
|
||||
# define FAR __far
|
||||
# endif
|
||||
#endif
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
|
||||
/* Borland C/C++ ignores FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
|
||||
/* Compile with -DZLIB_DLL for Windows DLL support */
|
||||
#if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
|
||||
# include <windows.h>
|
||||
# define EXPORT WINAPI
|
||||
#else
|
||||
# define EXPORT
|
||||
#endif
|
||||
|
||||
#endif /* _ZCONF_H */
|
||||
+780
@@ -0,0 +1,780 @@
|
||||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.0.4, Jul 24th, 1996.
|
||||
|
||||
Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
gzip@prep.ai.mit.edu madler@alumni.caltech.edu
|
||||
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||
*/
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#define _ZLIB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "zconf.h"
|
||||
|
||||
#define ZLIB_VERSION "1.0.4"
|
||||
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
decompression functions, including integrity checks of the uncompressed
|
||||
data. This version of the library supports only one compression method
|
||||
(deflation) but other algorithms may be added later and will have the same
|
||||
stream interface.
|
||||
|
||||
For compression the application must provide the output buffer and
|
||||
may optionally provide the input buffer for optimization. For decompression,
|
||||
the application must provide the input buffer and may optionally provide
|
||||
the output buffer for optimization.
|
||||
|
||||
Compression can be done in a single step if the buffers are large
|
||||
enough (for example if an input file is mmap'ed), or can be done by
|
||||
repeated calls of the compression function. In the latter case, the
|
||||
application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
|
||||
The library does not install any signal handler. It is recommended to
|
||||
add at least a handler for SIGSEGV when decompressing; the library checks
|
||||
the consistency of the input data whenever possible but may go nuts
|
||||
for some forms of corrupted input.
|
||||
*/
|
||||
|
||||
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
|
||||
typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
||||
|
||||
struct internal_state;
|
||||
|
||||
typedef struct z_stream_s {
|
||||
Bytef *next_in; /* next input byte */
|
||||
uInt avail_in; /* number of bytes available at next_in */
|
||||
uLong total_in; /* total nb of input bytes read so far */
|
||||
|
||||
Bytef *next_out; /* next output byte should be put there */
|
||||
uInt avail_out; /* remaining free space at next_out */
|
||||
uLong total_out; /* total nb of bytes output so far */
|
||||
|
||||
char *msg; /* last error message, NULL if no error */
|
||||
struct internal_state FAR *state; /* not visible by applications */
|
||||
|
||||
alloc_func zalloc; /* used to allocate the internal state */
|
||||
free_func zfree; /* used to free the internal state */
|
||||
voidpf opaque; /* private data object passed to zalloc and zfree */
|
||||
|
||||
int data_type; /* best guess about the data type: ascii or binary */
|
||||
uLong adler; /* adler32 value of the uncompressed data */
|
||||
uLong reserved; /* reserved for future use */
|
||||
} z_stream;
|
||||
|
||||
typedef z_stream FAR *z_streamp;
|
||||
|
||||
/*
|
||||
The application must update next_in and avail_in when avail_in has
|
||||
dropped to zero. It must update next_out and avail_out when avail_out
|
||||
has dropped to zero. The application must initialize zalloc, zfree and
|
||||
opaque before calling the init function. All other fields are set by the
|
||||
compression library and must not be updated by the application.
|
||||
|
||||
The opaque value provided by the application will be passed as the first
|
||||
parameter for calls of zalloc and zfree. This can be useful for custom
|
||||
memory management. The compression library attaches no meaning to the
|
||||
opaque value.
|
||||
|
||||
zalloc must return Z_NULL if there is not enough memory for the object.
|
||||
On 16-bit systems, the functions zalloc and zfree must be able to allocate
|
||||
exactly 65536 bytes, but will not be required to allocate more than this
|
||||
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
||||
pointers returned by zalloc for objects of exactly 65536 bytes *must*
|
||||
have their offset normalized to zero. The default allocation function
|
||||
provided by this library ensures this (see zutil.c). To reduce memory
|
||||
requirements and avoid any allocation of 64K objects, at the expense of
|
||||
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
|
||||
|
||||
The fields total_in and total_out can be used for statistics or
|
||||
progress reports. After compression, total_in holds the total size of
|
||||
the uncompressed data and may be saved for use in the decompressor
|
||||
(particularly if the decompressor wants to decompress everything in
|
||||
a single step).
|
||||
*/
|
||||
|
||||
/* constants */
|
||||
|
||||
#define Z_NO_FLUSH 0
|
||||
#define Z_PARTIAL_FLUSH 1
|
||||
#define Z_SYNC_FLUSH 2
|
||||
#define Z_FULL_FLUSH 3
|
||||
#define Z_FINISH 4
|
||||
/* Allowed flush values; see deflate() below for details */
|
||||
|
||||
#define Z_OK 0
|
||||
#define Z_STREAM_END 1
|
||||
#define Z_NEED_DICT 2
|
||||
#define Z_ERRNO (-1)
|
||||
#define Z_STREAM_ERROR (-2)
|
||||
#define Z_DATA_ERROR (-3)
|
||||
#define Z_MEM_ERROR (-4)
|
||||
#define Z_BUF_ERROR (-5)
|
||||
#define Z_VERSION_ERROR (-6)
|
||||
/* Return codes for the compression/decompression functions. Negative
|
||||
* values are errors, positive values are used for special but normal events.
|
||||
*/
|
||||
|
||||
#define Z_NO_COMPRESSION 0
|
||||
#define Z_BEST_SPEED 1
|
||||
#define Z_BEST_COMPRESSION 9
|
||||
#define Z_DEFAULT_COMPRESSION (-1)
|
||||
/* compression levels */
|
||||
|
||||
#define Z_FILTERED 1
|
||||
#define Z_HUFFMAN_ONLY 2
|
||||
#define Z_DEFAULT_STRATEGY 0
|
||||
/* compression strategy; see deflateInit2() below for details */
|
||||
|
||||
#define Z_BINARY 0
|
||||
#define Z_ASCII 1
|
||||
#define Z_UNKNOWN 2
|
||||
/* Possible values of the data_type field */
|
||||
|
||||
#define Z_DEFLATED 8
|
||||
/* The deflate compression method (the only one supported in this version) */
|
||||
|
||||
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
|
||||
|
||||
#define zlib_version zlibVersion()
|
||||
/* for compatibility with versions < 1.0.2 */
|
||||
|
||||
/* basic functions */
|
||||
|
||||
extern const char * EXPORT zlibVersion OF((void));
|
||||
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
|
||||
If the first character differs, the library code actually used is
|
||||
not compatible with the zlib.h header file used by the application.
|
||||
This check is automatically made by deflateInit and inflateInit.
|
||||
*/
|
||||
|
||||
/*
|
||||
extern int EXPORT deflateInit OF((z_streamp strm, int level));
|
||||
|
||||
Initializes the internal stream state for compression. The fields
|
||||
zalloc, zfree and opaque must be initialized before by the caller.
|
||||
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
|
||||
use default allocation functions.
|
||||
|
||||
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
|
||||
1 gives best speed, 9 gives best compression, 0 gives no compression at
|
||||
all (the input data is simply copied a block at a time).
|
||||
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
|
||||
compression (currently equivalent to level 6).
|
||||
|
||||
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
|
||||
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
|
||||
with the version assumed by the caller (ZLIB_VERSION).
|
||||
msg is set to null if there is no error message. deflateInit does not
|
||||
perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
|
||||
extern int EXPORT deflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
Performs one or both of the following actions:
|
||||
|
||||
- Compress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in and avail_in are updated and
|
||||
processing will resume at this point for the next call of deflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. This action is forced if the parameter flush is non zero.
|
||||
Forcing flush frequently degrades the compression ratio, so this parameter
|
||||
should be set only when necessary (in interactive applications).
|
||||
Some output may be provided even if flush is not set.
|
||||
|
||||
Before the call of deflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating avail_in or avail_out accordingly; avail_out
|
||||
should never be zero before the call. The application can consume the
|
||||
compressed output when it wants, for example when the output buffer is full
|
||||
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
|
||||
and with zero avail_out, it must be called again after making room in the
|
||||
output buffer because there might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
|
||||
block is terminated and flushed to the output buffer so that the
|
||||
decompressor can get all input data available so far. For method 9, a future
|
||||
variant on method 8, the current block will be flushed but not terminated.
|
||||
Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
|
||||
output is byte aligned (the compressor can clear its internal bit buffer)
|
||||
and the current block is always terminated; this can be useful if the
|
||||
compressor has to be restarted from scratch after an interruption (in which
|
||||
case the internal state of the compressor may be lost).
|
||||
If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
|
||||
special marker is output and the compression dictionary is discarded; this
|
||||
is useful to allow the decompressor to synchronize if one compressed block
|
||||
has been damaged (see inflateSync below). Flushing degrades compression and
|
||||
so should be used only when necessary. Using Z_FULL_FLUSH too often can
|
||||
seriously degrade the compression. If deflate returns with avail_out == 0,
|
||||
this function must be called again with the same value of the flush
|
||||
parameter and more output space (updated avail_out), until the flush is
|
||||
complete (deflate returns with non-zero avail_out).
|
||||
|
||||
If the parameter flush is set to Z_FINISH, pending input is processed,
|
||||
pending output is flushed and deflate returns with Z_STREAM_END if there
|
||||
was enough output space; if deflate returns with Z_OK, this function must be
|
||||
called again with Z_FINISH and more output space (updated avail_out) but no
|
||||
more input data, until it returns with Z_STREAM_END or an error. After
|
||||
deflate has returned Z_STREAM_END, the only possible operations on the
|
||||
stream are deflateReset or deflateEnd.
|
||||
|
||||
Z_FINISH can be used immediately after deflateInit if all the compression
|
||||
is to be done in a single step. In this case, avail_out must be at least
|
||||
0.1% larger than avail_in plus 12 bytes. If deflate does not return
|
||||
Z_STREAM_END, then it must be called again as described above.
|
||||
|
||||
deflate() may update data_type if it can make a good guess about
|
||||
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
||||
binary. This field is only for information purposes and does not affect
|
||||
the compression algorithm in any manner.
|
||||
|
||||
deflate() returns Z_OK if some progress has been made (more input
|
||||
processed or more output produced), Z_STREAM_END if all input has been
|
||||
consumed and all output has been produced (only when flush is set to
|
||||
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
|
||||
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
|
||||
*/
|
||||
|
||||
|
||||
extern int EXPORT deflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
|
||||
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
|
||||
prematurely (some input or output was discarded). In the error case,
|
||||
msg may be set but then points to a static string (which must not be
|
||||
deallocated).
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
extern int EXPORT inflateInit OF((z_streamp strm));
|
||||
|
||||
Initializes the internal stream state for decompression. The fields
|
||||
zalloc, zfree and opaque must be initialized before by the caller. If
|
||||
zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
|
||||
allocation functions.
|
||||
|
||||
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
|
||||
with the version assumed by the caller. msg is set to null if there is no
|
||||
error message. inflateInit does not perform any decompression: this will be
|
||||
done by inflate().
|
||||
*/
|
||||
|
||||
|
||||
extern int EXPORT inflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
Performs one or both of the following actions:
|
||||
|
||||
- Decompress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in is updated and processing
|
||||
will resume at this point for the next call of inflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. inflate() provides as much output as possible, until there
|
||||
is no more input data or no more space in the output buffer (see below
|
||||
about the flush parameter).
|
||||
|
||||
Before the call of inflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating the next_* and avail_* values accordingly.
|
||||
The application can consume the uncompressed output when it wants, for
|
||||
example when the output buffer is full (avail_out == 0), or after each
|
||||
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
|
||||
must be called again after making room in the output buffer because there
|
||||
might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much
|
||||
output as possible to the output buffer. The flushing behavior of inflate is
|
||||
not specified for values of the flush parameter other than Z_PARTIAL_FLUSH
|
||||
and Z_FINISH, but the current implementation actually flushes as much output
|
||||
as possible anyway.
|
||||
|
||||
inflate() should normally be called until it returns Z_STREAM_END or an
|
||||
error. However if all decompression is to be performed in a single step
|
||||
(a single call of inflate), the parameter flush should be set to
|
||||
Z_FINISH. In this case all pending input is processed and all pending
|
||||
output is flushed; avail_out must be large enough to hold all the
|
||||
uncompressed data. (The size of the uncompressed data may have been saved
|
||||
by the compressor for this purpose.) The next operation on this stream must
|
||||
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
|
||||
is never required, but can be used to inform inflate that a faster routine
|
||||
may be used for the single inflate() call.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input
|
||||
processed or more output produced), Z_STREAM_END if the end of the
|
||||
compressed data has been reached and all uncompressed output has been
|
||||
produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
|
||||
inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
|
||||
Z_STREAM_ERROR if the stream structure was inconsistent (for example if
|
||||
next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
|
||||
Z_BUF_ERROR if no progress is possible or if there was not enough room in
|
||||
the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
|
||||
application may then call inflateSync to look for a good compression block.
|
||||
In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
|
||||
dictionary chosen by the compressor.
|
||||
*/
|
||||
|
||||
|
||||
extern int EXPORT inflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
|
||||
was inconsistent. In the error case, msg may be set but then points to a
|
||||
static string (which must not be deallocated).
|
||||
*/
|
||||
|
||||
/* Advanced functions */
|
||||
|
||||
/*
|
||||
The following functions are needed only in some special applications.
|
||||
*/
|
||||
|
||||
/*
|
||||
extern int EXPORT deflateInit2 OF((z_streamp strm,
|
||||
int level,
|
||||
int method,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy));
|
||||
|
||||
This is another version of deflateInit with more compression options. The
|
||||
fields next_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller.
|
||||
|
||||
The method parameter is the compression method. It must be Z_DEFLATED in
|
||||
this version of the library. (Method 9 will allow a 64K history buffer and
|
||||
partial block flushes.)
|
||||
|
||||
The windowBits parameter is the base two logarithm of the window size
|
||||
(the size of the history buffer). It should be in the range 8..15 for this
|
||||
version of the library (the value 16 will be allowed for method 9). Larger
|
||||
values of this parameter result in better compression at the expense of
|
||||
memory usage. The default value is 15 if deflateInit is used instead.
|
||||
|
||||
The memLevel parameter specifies how much memory should be allocated
|
||||
for the internal compression state. memLevel=1 uses minimum memory but
|
||||
is slow and reduces compression ratio; memLevel=9 uses maximum memory
|
||||
for optimal speed. The default value is 8. See zconf.h for total memory
|
||||
usage as a function of windowBits and memLevel.
|
||||
|
||||
The strategy parameter is used to tune the compression algorithm. Use the
|
||||
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
|
||||
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
|
||||
string match). Filtered data consists mostly of small values with a
|
||||
somewhat random distribution. In this case, the compression algorithm is
|
||||
tuned to compress them better. The effect of Z_FILTERED is to force more
|
||||
Huffman coding and less string matching; it is somewhat intermediate
|
||||
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
|
||||
the compression ratio but not the correctness of the compressed output even
|
||||
if it is not set appropriately.
|
||||
|
||||
If next_in is not null, the library will use this buffer to hold also
|
||||
some history information; the buffer must either hold the entire input
|
||||
data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
|
||||
is null, the library will allocate its own history buffer (and leave next_in
|
||||
null). next_out need not be provided here but must be provided by the
|
||||
application for the next call of deflate().
|
||||
|
||||
If the history buffer is provided by the application, next_in must
|
||||
must never be changed by the application since the compressor maintains
|
||||
information inside this buffer from call to call; the application
|
||||
must provide more input only by increasing avail_in. next_in is always
|
||||
reset by the library in this case.
|
||||
|
||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
|
||||
not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
|
||||
an invalid method). msg is set to null if there is no error message.
|
||||
deflateInit2 does not perform any compression: this will be done by
|
||||
deflate().
|
||||
*/
|
||||
|
||||
extern int EXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the compression dictionary (history buffer) from the given
|
||||
byte sequence without producing any compressed output. This function must
|
||||
be called immediately after deflateInit or deflateInit2, before any call
|
||||
of deflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see inflateSetDictionary).
|
||||
The dictionary should consist of strings (byte sequences) that are likely
|
||||
to be encountered later in the data to be compressed, with the most commonly
|
||||
used strings preferably put towards the end of the dictionary. Using a
|
||||
dictionary is most useful when the data to be compressed is short and
|
||||
can be predicted with good accuracy; the data can then be compressed better
|
||||
than with the default empty dictionary. In this version of the library,
|
||||
only the last 32K bytes of the dictionary are used.
|
||||
Upon return of this function, strm->adler is set to the Adler32 value
|
||||
of the dictionary; the decompressor may later use this value to determine
|
||||
which dictionary has been used by the compressor. (The Adler32 value
|
||||
applies to the whole dictionary even if only a subset of the dictionary is
|
||||
actually used by the compressor.)
|
||||
|
||||
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state
|
||||
is inconsistent (for example if deflate has already been called for this
|
||||
stream). deflateSetDictionary does not perform any compression: this will
|
||||
be done by deflate().
|
||||
*/
|
||||
|
||||
extern int EXPORT deflateCopy OF((z_streamp dest,
|
||||
z_streamp source));
|
||||
/*
|
||||
Sets the destination stream as a complete copy of the source stream. If
|
||||
the source stream is using an application-supplied history buffer, a new
|
||||
buffer is allocated for the destination stream. The compressed output
|
||||
buffer is always application-supplied. It's the responsibility of the
|
||||
application to provide the correct values of next_out and avail_out for the
|
||||
next call of deflate.
|
||||
|
||||
This function can be useful when several compression strategies will be
|
||||
tried, for example when there are several ways of pre-processing the input
|
||||
data with a filter. The streams that will be discarded should then be freed
|
||||
by calling deflateEnd. Note that deflateCopy duplicates the internal
|
||||
compression state which can be quite large, so this strategy is slow and
|
||||
can consume lots of memory.
|
||||
|
||||
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
|
||||
(such as zalloc being NULL). msg is left unchanged in both source and
|
||||
destination.
|
||||
*/
|
||||
|
||||
extern int EXPORT deflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to deflateEnd followed by deflateInit,
|
||||
but does not free and reallocate all the internal compression state.
|
||||
The stream will keep the same compression level and any other attributes
|
||||
that may have been set by deflateInit2.
|
||||
|
||||
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
|
||||
/*
|
||||
Dynamically update the compression level and compression strategy.
|
||||
This can be used to switch between compression and straight copy of
|
||||
the input data, or to switch to a different kind of input data requiring
|
||||
a different strategy. If the compression level is changed, the input
|
||||
available so far is compressed with the old level (and may be flushed);
|
||||
the new level will take effect only at the next call of deflate().
|
||||
|
||||
Before the call of deflateParams, the stream state must be set as for
|
||||
a call of deflate(), since the currently available input may have to
|
||||
be compressed and flushed. In particular, strm->avail_out must be non-zero.
|
||||
|
||||
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
|
||||
if strm->avail_out was zero.
|
||||
*/
|
||||
|
||||
/*
|
||||
extern int EXPORT inflateInit2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
|
||||
This is another version of inflateInit with more compression options. The
|
||||
fields next_out, zalloc, zfree and opaque must be initialized before by
|
||||
the caller.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the maximum window
|
||||
size (the size of the history buffer). It should be in the range 8..15 for
|
||||
this version of the library (the value 16 will be allowed soon). The
|
||||
default value is 15 if inflateInit is used instead. If a compressed stream
|
||||
with a larger window size is given as input, inflate() will return with
|
||||
the error code Z_DATA_ERROR instead of trying to allocate a larger window.
|
||||
|
||||
If next_out is not null, the library will use this buffer for the history
|
||||
buffer; the buffer must either be large enough to hold the entire output
|
||||
data, or have at least 1<<windowBits bytes. If next_out is null, the
|
||||
library will allocate its own buffer (and leave next_out null). next_in
|
||||
need not be provided here but must be provided by the application for the
|
||||
next call of inflate().
|
||||
|
||||
If the history buffer is provided by the application, next_out must
|
||||
never be changed by the application since the decompressor maintains
|
||||
history information inside this buffer from call to call; the application
|
||||
can only reset next_out to the beginning of the history buffer when
|
||||
avail_out is zero and all output has been consumed.
|
||||
|
||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
|
||||
not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
|
||||
windowBits < 8). msg is set to null if there is no error message.
|
||||
inflateInit2 does not perform any decompression: this will be done by
|
||||
inflate().
|
||||
*/
|
||||
|
||||
extern int EXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the decompression dictionary (history buffer) from the given
|
||||
uncompressed byte sequence. This function must be called immediately after
|
||||
a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
|
||||
by the compressor can be determined from the Adler32 value returned by this
|
||||
call of inflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see deflateSetDictionary).
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
|
||||
expected one (incorrect Adler32 value). inflateSetDictionary does not
|
||||
perform any decompression: this will be done by subsequent calls of
|
||||
inflate().
|
||||
*/
|
||||
|
||||
extern int EXPORT inflateSync OF((z_streamp strm));
|
||||
/*
|
||||
Skips invalid compressed data until the special marker (see deflate()
|
||||
above) can be found, or until all available input is skipped. No output
|
||||
is provided.
|
||||
|
||||
inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no marker has been found,
|
||||
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
|
||||
case, the application may save the current current value of total_in which
|
||||
indicates where valid compressed data was found. In the error case, the
|
||||
application may repeatedly call inflateSync, providing more input each time,
|
||||
until success or end of the input data.
|
||||
*/
|
||||
|
||||
extern int EXPORT inflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to inflateEnd followed by inflateInit,
|
||||
but does not free and reallocate all the internal decompression state.
|
||||
The stream will keep attributes that may have been set by inflateInit2.
|
||||
|
||||
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
|
||||
/* utility functions */
|
||||
|
||||
/*
|
||||
The following utility functions are implemented on top of the
|
||||
basic stream-oriented functions. To simplify the interface, some
|
||||
default options are assumed (compression level, window size,
|
||||
standard memory allocation functions). The source code of these
|
||||
utility functions can easily be modified if you need special options.
|
||||
*/
|
||||
|
||||
extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be at least 0.1% larger than
|
||||
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
|
||||
compressed buffer.
|
||||
This function can be used to compress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
compress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer.
|
||||
*/
|
||||
|
||||
extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
/*
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be large enough to hold the
|
||||
entire uncompressed data. (The size of the uncompressed data must have
|
||||
been saved previously by the compressor and transmitted to the decompressor
|
||||
by some mechanism outside the scope of this compression library.)
|
||||
Upon exit, destLen is the actual size of the compressed buffer.
|
||||
This function can be used to decompress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
*/
|
||||
|
||||
|
||||
typedef voidp gzFile;
|
||||
|
||||
extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
|
||||
/*
|
||||
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
||||
is as in fopen ("rb" or "wb") but can also include a compression level
|
||||
("wb9"). gzopen can be used to read a file which is not in gzip format;
|
||||
in this case gzread will directly read from the file without decompression.
|
||||
gzopen returns NULL if the file could not be opened or if there was
|
||||
insufficient memory to allocate the (de)compression state; errno
|
||||
can be checked to distinguish the two cases (if errno is zero, the
|
||||
zlib error is Z_MEM_ERROR).
|
||||
*/
|
||||
|
||||
extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
|
||||
/*
|
||||
gzdopen() associates a gzFile with the file descriptor fd. File
|
||||
descriptors are obtained from calls like open, dup, creat, pipe or
|
||||
fileno (in the file has been previously opened with fopen).
|
||||
The mode parameter is as in gzopen.
|
||||
The next call of gzclose on the returned gzFile will also close the
|
||||
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
|
||||
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
|
||||
gzdopen returns NULL if there was insufficient memory to allocate
|
||||
the (de)compression state.
|
||||
*/
|
||||
|
||||
extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
/*
|
||||
Reads the given number of uncompressed bytes from the compressed file.
|
||||
If the input file was not in gzip format, gzread copies the given number
|
||||
of bytes into the buffer.
|
||||
gzread returns the number of uncompressed bytes actually read (0 for
|
||||
end of file, -1 for error). */
|
||||
|
||||
extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
|
||||
/*
|
||||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of uncompressed bytes actually written
|
||||
(0 in case of error).
|
||||
*/
|
||||
|
||||
extern int EXPORT gzflush OF((gzFile file, int flush));
|
||||
/*
|
||||
Flushes all pending output into the compressed file. The parameter
|
||||
flush is as in the deflate() function. The return value is the zlib
|
||||
error number (see function gzerror below). gzflush returns Z_OK if
|
||||
the flush parameter is Z_FINISH and all output could be flushed.
|
||||
gzflush should be called only when strictly necessary because it can
|
||||
degrade compression.
|
||||
*/
|
||||
|
||||
extern int EXPORT gzclose OF((gzFile file));
|
||||
/*
|
||||
Flushes all pending output if necessary, closes the compressed file
|
||||
and deallocates all the (de)compression state. The return value is the zlib
|
||||
error number (see function gzerror below).
|
||||
*/
|
||||
|
||||
extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
|
||||
/*
|
||||
Returns the error message for the last error which occurred on the
|
||||
given compressed file. errnum is set to zlib error number. If an
|
||||
error occurred in the file system and not in the compression library,
|
||||
errnum is set to Z_ERRNO and the application may consult errno
|
||||
to get the exact error code.
|
||||
*/
|
||||
|
||||
/* checksum functions */
|
||||
|
||||
/*
|
||||
These functions are not related to compression but are exported
|
||||
anyway because they might be useful in applications using the
|
||||
compression library.
|
||||
*/
|
||||
|
||||
extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
|
||||
/*
|
||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||
return the updated checksum. If buf is NULL, this function returns
|
||||
the required initial value for the checksum.
|
||||
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
||||
much faster. Usage example:
|
||||
|
||||
uLong adler = adler32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
adler = adler32(adler, buffer, length);
|
||||
}
|
||||
if (adler != original_adler) error();
|
||||
*/
|
||||
|
||||
extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
/*
|
||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
||||
crc. If buf is NULL, this function returns the required initial value
|
||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
||||
within this function so it shouldn't be done by the application.
|
||||
Usage example:
|
||||
|
||||
uLong crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
crc = crc32(crc, buffer, length);
|
||||
}
|
||||
if (crc != original_crc) error();
|
||||
*/
|
||||
|
||||
|
||||
/* various hacks, don't look :) */
|
||||
|
||||
/* deflateInit and inflateInit are macros to allow checking the zlib version
|
||||
* and the compiler's view of z_stream:
|
||||
*/
|
||||
extern int EXPORT deflateInit_ OF((z_streamp strm, int level,
|
||||
const char *version, int stream_size));
|
||||
extern int EXPORT inflateInit_ OF((z_streamp strm,
|
||||
const char *version, int stream_size));
|
||||
extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
|
||||
int windowBits, int memLevel, int strategy,
|
||||
const char *version, int stream_size));
|
||||
extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size));
|
||||
#define deflateInit(strm, level) \
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit(strm) \
|
||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
|
||||
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
|
||||
(strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit2(strm, windowBits) \
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
|
||||
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||
#endif
|
||||
|
||||
uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ZLIB_H */
|
||||
+3102
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "debug_util.h"
|
||||
|
||||
const void *const *StackTrace::Addresses(size_t* count) {
|
||||
*count = trace_.size();
|
||||
if (trace_.size())
|
||||
return &trace_[0];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void sgp::dumpStackTrace(vfs::String const& msg)
|
||||
{
|
||||
// the first error is the important one anyway
|
||||
static bool already_dumping = false;
|
||||
|
||||
if(!already_dumping) // needs a mutes to be sure
|
||||
{
|
||||
already_dumping = true;
|
||||
StackTrace str;
|
||||
str.PrintBacktrace(msg.utf8().c_str());
|
||||
already_dumping = false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
StackTrace::StackTrace()
|
||||
{
|
||||
}
|
||||
|
||||
void StackTrace::PrintBacktrace(const char* msg)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This is a cross platform interface for helper functions related to debuggers.
|
||||
// You should use this to test if you're running under a debugger, and if you
|
||||
// would like to yield (breakpoint) into the debugger.
|
||||
|
||||
#ifndef BASE_DEBUG_UTIL_H_
|
||||
#define BASE_DEBUG_UTIL_H_
|
||||
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
#include "sgp_logger.h"
|
||||
|
||||
// A macro to disallow the copy constructor and operator= functions
|
||||
// This should be used in the private: declarations for a class
|
||||
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
||||
TypeName(const TypeName&); \
|
||||
void operator=(const TypeName&)
|
||||
|
||||
// An older, deprecated, politically incorrect name for the above.
|
||||
#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName)
|
||||
|
||||
// A stacktrace can be helpful in debugging. For example, you can include a
|
||||
// stacktrace member in a object (probably around #ifndef NDEBUG) so that you
|
||||
// can later see where the given object was created from.
|
||||
class StackTrace {
|
||||
public:
|
||||
// Create a stacktrace from the current location
|
||||
StackTrace();
|
||||
// Get an array of instruction pointer values.
|
||||
// count: (output) the number of elements in the returned array
|
||||
const void *const *Addresses(size_t* count);
|
||||
// Print a backtrace to stderr
|
||||
void PrintBacktrace(const char* msg);
|
||||
|
||||
// Resolve backtrace to symbols and write to stream.
|
||||
void OutputToStream(const char* msg, sgp::Logger::LogInstance* os);
|
||||
|
||||
private:
|
||||
std::vector<void*> trace_;
|
||||
int count_;
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(StackTrace);
|
||||
};
|
||||
|
||||
namespace sgp
|
||||
{
|
||||
void dumpStackTrace(vfs::String const& msg);
|
||||
}
|
||||
|
||||
#endif // BASE_DEBUG_UTIL_H_
|
||||
@@ -0,0 +1,230 @@
|
||||
// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#include "debug_util.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#include <dbghelp.h>
|
||||
|
||||
#include <vfs/Tools/vfs_log.h>
|
||||
|
||||
|
||||
|
||||
// The arraysize(arr) macro returns the # of elements in an array arr.
|
||||
// The expression is a compile-time constant, and therefore can be
|
||||
// used in defining new arrays, for example. If you use arraysize on
|
||||
// a pointer by mistake, you will get a compile-time error.
|
||||
//
|
||||
// One caveat is that arraysize() doesn't accept any array of an
|
||||
// anonymous type or a type defined inside a function. In these rare
|
||||
// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is
|
||||
// due to a limitation in C++'s template system. The limitation might
|
||||
// eventually be removed, but it hasn't happened yet.
|
||||
|
||||
// This template function declaration is used in defining arraysize.
|
||||
// Note that the function doesn't need an implementation, as we only
|
||||
// use its type.
|
||||
template <typename T, size_t N>
|
||||
char (&ArraySizeHelper(T (&array)[N]))[N];
|
||||
|
||||
// That gcc wants both of these prototypes seems mysterious. VC, for
|
||||
// its part, can't decide which to use (another mystery). Matching of
|
||||
// template overloads: the final frontier.
|
||||
#ifndef _MSC_VER
|
||||
template <typename T, size_t N>
|
||||
char (&ArraySizeHelper(const T (&array)[N]))[N];
|
||||
#endif
|
||||
|
||||
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
||||
|
||||
|
||||
namespace {
|
||||
// SymbolContext is a threadsafe singleton that wraps the DbgHelp Sym* family
|
||||
// of functions. The Sym* family of functions may only be invoked by one
|
||||
// thread at a time. SymbolContext code may access a symbol server over the
|
||||
// network while holding the lock for this singleton. In the case of high
|
||||
// latency, this code will adversly affect performance.
|
||||
//
|
||||
// There is also a known issue where this backtrace code can interact
|
||||
// badly with breakpad if breakpad is invoked in a separate thread while
|
||||
// we are using the Sym* functions. This is because breakpad does now
|
||||
// share a lock with this function. See this related bug:
|
||||
//
|
||||
// http://code.google.com/p/google-breakpad/issues/detail?id=311
|
||||
//
|
||||
// This is a very unlikely edge case, and the current solution is to
|
||||
// just ignore it.
|
||||
class SymbolContext {
|
||||
public:
|
||||
static SymbolContext* Get() {
|
||||
static SymbolContext* s_singleton = NULL;
|
||||
if(!s_singleton) s_singleton = new SymbolContext();
|
||||
return s_singleton;
|
||||
// We use a leaky singleton because code may call this during process
|
||||
// termination.
|
||||
|
||||
//return Singleton<SymbolContext, LeakySingletonTraits<SymbolContext> >::get();
|
||||
}
|
||||
|
||||
// Returns the error code of a failed initialization.
|
||||
DWORD init_error() const {
|
||||
return init_error_;
|
||||
}
|
||||
|
||||
// For the given trace, attempts to resolve the symbols, and output a trace
|
||||
// to the ostream os. The format for each line of the backtrace is:
|
||||
//
|
||||
// <tab>SymbolName[0xAddress+Offset] (FileName:LineNo)
|
||||
//
|
||||
// This function should only be called if Init() has been called. We do not
|
||||
// LOG(FATAL) here because this code is called might be triggered by a
|
||||
// LOG(FATAL) itself.
|
||||
void OutputTraceToStream(const std::vector<void*>& trace, sgp::Logger::LogInstance* os) {
|
||||
//AutoLock lock(lock_);
|
||||
|
||||
for (size_t i = 0; (i < trace.size()); ++i) {
|
||||
const int kMaxNameLength = 256;
|
||||
DWORD_PTR frame = reinterpret_cast<DWORD_PTR>(trace[i]);
|
||||
|
||||
// Code adapted from MSDN example:
|
||||
// http://msdn.microsoft.com/en-us/library/ms680578(VS.85).aspx
|
||||
ULONG64 buffer[
|
||||
(sizeof(SYMBOL_INFO) +
|
||||
kMaxNameLength * sizeof(wchar_t) +
|
||||
sizeof(ULONG64) - 1) /
|
||||
sizeof(ULONG64)];
|
||||
|
||||
// Initialize symbol information retrieval structures.
|
||||
DWORD64 sym_displacement = 0;
|
||||
PSYMBOL_INFO symbol = reinterpret_cast<PSYMBOL_INFO>(&buffer[0]);
|
||||
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
symbol->MaxNameLen = kMaxNameLength;
|
||||
BOOL has_symbol = SymFromAddr(GetCurrentProcess(), frame,
|
||||
&sym_displacement, symbol);
|
||||
|
||||
// Attempt to retrieve line number information.
|
||||
DWORD line_displacement = 0;
|
||||
IMAGEHLP_LINE64 line = {};
|
||||
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
|
||||
BOOL has_line = SymGetLineFromAddr64(GetCurrentProcess(), frame,
|
||||
&line_displacement, &line);
|
||||
|
||||
// Output the backtrace line.
|
||||
(*os) << " ";
|
||||
if (has_symbol)
|
||||
{
|
||||
(*os) << " [0x" << trace[i] << "+" << sym_displacement << "]\t";
|
||||
(*os) << vfs::String(symbol->Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
(*os) << " [0x" << trace[i] << "]\t";
|
||||
// If there is no symbol information, add a spacer.
|
||||
(*os) << " (No symbol)";
|
||||
}
|
||||
if (has_line)
|
||||
{
|
||||
(*os) << " - (" << line.FileName << ":" << line.LineNumber << ")";
|
||||
}
|
||||
(*os) << sgp::endl;
|
||||
}
|
||||
(*os) << sgp::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
SymbolContext() : init_error_(ERROR_SUCCESS) {
|
||||
// Initializes the symbols for the process.
|
||||
// Defer symbol load until they're needed, use undecorated names, and
|
||||
// get line numbers.
|
||||
SymSetOptions(SYMOPT_DEFERRED_LOADS |
|
||||
SYMOPT_UNDNAME |
|
||||
SYMOPT_LOAD_LINES);
|
||||
if (SymInitialize(GetCurrentProcess(), NULL, TRUE)) {
|
||||
init_error_ = ERROR_SUCCESS;
|
||||
} else {
|
||||
__debugbreak();
|
||||
init_error_ = GetLastError();
|
||||
}
|
||||
}
|
||||
|
||||
DWORD init_error_;
|
||||
//Lock lock_;
|
||||
DISALLOW_COPY_AND_ASSIGN(SymbolContext);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#define ENABLE_STACK_TRACE 0
|
||||
|
||||
StackTrace::StackTrace() {
|
||||
// From http://msdn.microsoft.com/en-us/library/bb204633(VS.85).aspx,
|
||||
// the sum of FramesToSkip and FramesToCapture must be less than 63,
|
||||
// so set it to 62.
|
||||
const int kMaxCallers = 62;
|
||||
// TODO(ajwong): Migrate this to StackWalk64.
|
||||
|
||||
#if ENABLE_STACK_TRACE
|
||||
|
||||
// WANNE: This only works with Visual Studio version >= 2008
|
||||
#if _MSC_VER >= 1500
|
||||
|
||||
void* callers[kMaxCallers];
|
||||
int count = CaptureStackBackTrace(0, kMaxCallers, callers, NULL);
|
||||
|
||||
// Not used, because we use CaptureStackBackTrace()
|
||||
//int count = RtlCaptureStackBackTrace(0, kMaxCallers, callers, NULL);
|
||||
|
||||
if (count > 0) {
|
||||
trace_.resize(count);
|
||||
memcpy(&trace_[0], callers, sizeof(callers[0]) * count);
|
||||
}
|
||||
else
|
||||
{
|
||||
trace_.resize(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct StackTraceLog {
|
||||
sgp::Logger_ID id;
|
||||
StackTraceLog() {
|
||||
id = sgp::Logger::instance().createLogger();
|
||||
sgp::Logger::instance().connectFile(id, L"stack_trace.log", false, sgp::Logger::FLUSH_ON_ENDL);
|
||||
};
|
||||
} s_log;
|
||||
|
||||
void StackTrace::PrintBacktrace(const char* msg) {
|
||||
OutputToStream(msg, &(SGP_LOG(s_log.id)));
|
||||
}
|
||||
|
||||
void StackTrace::OutputToStream(const char* msg, sgp::Logger::LogInstance* os) {
|
||||
SymbolContext* context = SymbolContext::Get();
|
||||
DWORD error = context->init_error();
|
||||
if (error != ERROR_SUCCESS)
|
||||
{
|
||||
(*os) << "Error initializing symbols (" << error
|
||||
<< "). Dumping unresolved backtrace:"
|
||||
<< sgp::endl;
|
||||
for (size_t i = 0; (i < trace_.size()); ++i)
|
||||
{
|
||||
(*os) << "\t" << trace_[i] << sgp::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(*os) << L"Backtrace: " << (msg != NULL ? msg : "") << sgp::endl;
|
||||
context->OutputTraceToStream(trace_, os);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _MSC_VER
|
||||
+366
@@ -0,0 +1,366 @@
|
||||
/*==========================================================================;
|
||||
*
|
||||
* Copyright (C) 1995,1996 Microsoft Corporation. All Rights Reserved.
|
||||
*
|
||||
* File: dsound.h
|
||||
* Content: DirectSound include file
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef __DSOUND_INCLUDED__
|
||||
#define __DSOUND_INCLUDED__
|
||||
|
||||
#ifdef _WIN32
|
||||
#define COM_NO_WINDOWS_H
|
||||
#include <objbase.h>
|
||||
#endif
|
||||
|
||||
#define _FACDS 0x878
|
||||
#define MAKE_DSHRESULT( code ) MAKE_HRESULT( 1, _FACDS, code )
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Direct Sound Component GUID {47D4D946-62E8-11cf-93BC-444553540000}
|
||||
DEFINE_GUID(CLSID_DirectSound,
|
||||
0x47d4d946, 0x62e8, 0x11cf, 0x93, 0xbc, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);
|
||||
|
||||
// DirectSound 279afa83-4981-11ce-a521-0020af0be560
|
||||
DEFINE_GUID(IID_IDirectSound,0x279AFA83,0x4981,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60);
|
||||
// DirectSoundBuffer 279afa85-4981-11ce-a521-0020af0be560
|
||||
DEFINE_GUID(IID_IDirectSoundBuffer,0x279AFA85,0x4981,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60);
|
||||
|
||||
|
||||
|
||||
//==========================================================================;
|
||||
//
|
||||
// Structures...
|
||||
//
|
||||
//==========================================================================;
|
||||
#ifdef __cplusplus
|
||||
/* 'struct' not 'class' per the way DECLARE_INTERFACE_ is defined */
|
||||
struct IDirectSound;
|
||||
struct IDirectSoundBuffer;
|
||||
#endif
|
||||
|
||||
typedef struct IDirectSound *LPDIRECTSOUND;
|
||||
typedef struct IDirectSoundBuffer *LPDIRECTSOUNDBUFFER;
|
||||
typedef struct IDirectSoundBuffer **LPLPDIRECTSOUNDBUFFER;
|
||||
|
||||
|
||||
typedef struct _DSCAPS
|
||||
{
|
||||
DWORD dwSize;
|
||||
DWORD dwFlags;
|
||||
DWORD dwMinSecondarySampleRate;
|
||||
DWORD dwMaxSecondarySampleRate;
|
||||
DWORD dwPrimaryBuffers;
|
||||
DWORD dwMaxHwMixingAllBuffers;
|
||||
DWORD dwMaxHwMixingStaticBuffers;
|
||||
DWORD dwMaxHwMixingStreamingBuffers;
|
||||
DWORD dwFreeHwMixingAllBuffers;
|
||||
DWORD dwFreeHwMixingStaticBuffers;
|
||||
DWORD dwFreeHwMixingStreamingBuffers;
|
||||
DWORD dwMaxHw3DAllBuffers;
|
||||
DWORD dwMaxHw3DStaticBuffers;
|
||||
DWORD dwMaxHw3DStreamingBuffers;
|
||||
DWORD dwFreeHw3DAllBuffers;
|
||||
DWORD dwFreeHw3DStaticBuffers;
|
||||
DWORD dwFreeHw3DStreamingBuffers;
|
||||
DWORD dwTotalHwMemBytes;
|
||||
DWORD dwFreeHwMemBytes;
|
||||
DWORD dwMaxContigFreeHwMemBytes;
|
||||
DWORD dwUnlockTransferRateHwBuffers;
|
||||
DWORD dwPlayCpuOverheadSwBuffers;
|
||||
DWORD dwReserved1;
|
||||
DWORD dwReserved2;
|
||||
} DSCAPS, *LPDSCAPS;
|
||||
|
||||
typedef struct _DSBCAPS
|
||||
{
|
||||
|
||||
DWORD dwSize;
|
||||
DWORD dwFlags;
|
||||
DWORD dwBufferBytes;
|
||||
DWORD dwUnlockTransferRate;
|
||||
DWORD dwPlayCpuOverhead;
|
||||
} DSBCAPS, *LPDSBCAPS;
|
||||
|
||||
typedef struct _DSBUFFERDESC
|
||||
{
|
||||
DWORD dwSize;
|
||||
DWORD dwFlags;
|
||||
DWORD dwBufferBytes;
|
||||
DWORD dwReserved;
|
||||
LPWAVEFORMATEX lpwfxFormat;
|
||||
} DSBUFFERDESC, *LPDSBUFFERDESC;
|
||||
|
||||
|
||||
|
||||
typedef LPVOID* LPLPVOID;
|
||||
|
||||
|
||||
typedef BOOL (FAR PASCAL * LPDSENUMCALLBACKW)(GUID FAR *, LPWSTR, LPWSTR, LPVOID);
|
||||
typedef BOOL (FAR PASCAL * LPDSENUMCALLBACKA)(GUID FAR *, LPSTR, LPSTR, LPVOID);
|
||||
|
||||
extern HRESULT WINAPI DirectSoundCreate(GUID FAR * lpGUID, LPDIRECTSOUND * ppDS, IUnknown FAR *pUnkOuter );
|
||||
extern HRESULT WINAPI DirectSoundEnumerateW(LPDSENUMCALLBACKW lpCallback, LPVOID lpContext );
|
||||
extern HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA lpCallback, LPVOID lpContext );
|
||||
|
||||
#ifdef UNICODE
|
||||
#define LPDSENUMCALLBACK LPDSENUMCALLBACKW
|
||||
#define DirectSoundEnumerate DirectSoundEnumerateW
|
||||
#else
|
||||
#define LPDSENUMCALLBACK LPDSENUMCALLBACKA
|
||||
#define DirectSoundEnumerate DirectSoundEnumerateA
|
||||
#endif
|
||||
|
||||
//
|
||||
// IDirectSound
|
||||
//
|
||||
#undef INTERFACE
|
||||
#define INTERFACE IDirectSound
|
||||
#ifdef _WIN32
|
||||
DECLARE_INTERFACE_( IDirectSound, IUnknown )
|
||||
{
|
||||
/*** IUnknown methods ***/
|
||||
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
|
||||
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
|
||||
STDMETHOD_(ULONG,Release) (THIS) PURE;
|
||||
/*** IDirectSound methods ***/
|
||||
|
||||
STDMETHOD( CreateSoundBuffer)(THIS_ LPDSBUFFERDESC, LPLPDIRECTSOUNDBUFFER, IUnknown FAR *) PURE;
|
||||
STDMETHOD( GetCaps)(THIS_ LPDSCAPS ) PURE;
|
||||
STDMETHOD( DuplicateSoundBuffer)(THIS_ LPDIRECTSOUNDBUFFER, LPLPDIRECTSOUNDBUFFER ) PURE;
|
||||
STDMETHOD( SetCooperativeLevel)(THIS_ HWND, DWORD ) PURE;
|
||||
STDMETHOD( Compact)(THIS ) PURE;
|
||||
STDMETHOD( GetSpeakerConfig)(THIS_ LPDWORD ) PURE;
|
||||
STDMETHOD( SetSpeakerConfig)(THIS_ DWORD ) PURE;
|
||||
STDMETHOD( Initialize)(THIS_ GUID FAR * ) PURE;
|
||||
};
|
||||
|
||||
#if !defined(__cplusplus) || defined(CINTERFACE)
|
||||
#define IDirectSound_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
|
||||
#define IDirectSound_AddRef(p) (p)->lpVtbl->AddRef(p)
|
||||
#define IDirectSound_Release(p) (p)->lpVtbl->Release(p)
|
||||
#define IDirectSound_CreateSoundBuffer(p,a,b,c) (p)->lpVtbl->CreateSoundBuffer(p,a,b,c)
|
||||
#define IDirectSound_GetCaps(p,a) (p)->lpVtbl->GetCaps(p,a)
|
||||
#define IDirectSound_DuplicateSoundBuffer(p,a,b) (p)->lpVtbl->DuplicateSoundBuffer(p,a,b)
|
||||
#define IDirectSound_SetCooperativeLevel(p,a,b) (p)->lpVtbl->SetCooperativeLevel(p,a,b)
|
||||
#define IDirectSound_Compact(p) (p)->lpVtbl->Compact(p)
|
||||
#define IDirectSound_GetSpeakerConfig(p,a) (p)->lpVtbl->GetSpeakerConfig(p,a)
|
||||
#define IDirectSound_SetSpeakerConfig(p,b) (p)->lpVtbl->SetSpeakerConfig(p,b)
|
||||
#define IDirectSound_Initialize(p,a) (p)->lpVtbl->Initialize(p,a)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
// IDirectSoundBuffer
|
||||
//
|
||||
#undef INTERFACE
|
||||
#define INTERFACE IDirectSoundBuffer
|
||||
#ifdef _WIN32
|
||||
DECLARE_INTERFACE_( IDirectSoundBuffer, IUnknown )
|
||||
{
|
||||
/*** IUnknown methods ***/
|
||||
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID * ppvObj) PURE;
|
||||
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
|
||||
STDMETHOD_(ULONG,Release) (THIS) PURE;
|
||||
/*** IDirectSoundBuffer methods ***/
|
||||
|
||||
STDMETHOD( GetCaps)(THIS_ LPDSBCAPS ) PURE;
|
||||
STDMETHOD(GetCurrentPosition)(THIS_ LPDWORD,LPDWORD ) PURE;
|
||||
STDMETHOD( GetFormat)(THIS_ LPWAVEFORMATEX, DWORD, LPDWORD ) PURE;
|
||||
STDMETHOD( GetVolume)(THIS_ LPLONG ) PURE;
|
||||
STDMETHOD( GetPan)(THIS_ LPLONG ) PURE;
|
||||
STDMETHOD( GetFrequency)(THIS_ LPDWORD ) PURE;
|
||||
STDMETHOD( GetStatus)(THIS_ LPDWORD ) PURE;
|
||||
STDMETHOD( Initialize)(THIS_ LPDIRECTSOUND, LPDSBUFFERDESC ) PURE;
|
||||
STDMETHOD( Lock)(THIS_ DWORD,DWORD,LPVOID,LPDWORD,LPVOID,LPDWORD,DWORD ) PURE;
|
||||
STDMETHOD( Play)(THIS_ DWORD,DWORD,DWORD ) PURE;
|
||||
STDMETHOD(SetCurrentPosition)(THIS_ DWORD ) PURE;
|
||||
STDMETHOD( SetFormat)(THIS_ LPWAVEFORMATEX ) PURE;
|
||||
STDMETHOD( SetVolume)(THIS_ LONG ) PURE;
|
||||
STDMETHOD( SetPan)(THIS_ LONG ) PURE;
|
||||
STDMETHOD( SetFrequency)(THIS_ DWORD ) PURE;
|
||||
STDMETHOD( Stop)(THIS ) PURE;
|
||||
STDMETHOD( Unlock)(THIS_ LPVOID,DWORD,LPVOID,DWORD ) PURE;
|
||||
STDMETHOD( Restore)(THIS ) PURE;
|
||||
};
|
||||
|
||||
#if !defined(__cplusplus) || defined(CINTERFACE)
|
||||
#define IDirectSoundBuffer_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
|
||||
#define IDirectSoundBuffer_AddRef(p) (p)->lpVtbl->AddRef(p)
|
||||
#define IDirectSoundBuffer_Release(p) (p)->lpVtbl->Release(p)
|
||||
#define IDirectSoundBuffer_GetCaps(p,a) (p)->lpVtbl->GetCaps(p,a)
|
||||
#define IDirectSoundBuffer_GetCurrentPosition(p,a,b) (p)->lpVtbl->GetCurrentPosition(p,a,b)
|
||||
#define IDirectSoundBuffer_GetFormat(p,a,b,c) (p)->lpVtbl->GetFormat(p,a,b,c)
|
||||
#define IDirectSoundBuffer_GetVolume(p,a) (p)->lpVtbl->GetVolume(p,a)
|
||||
#define IDirectSoundBuffer_GetPan(p,a) (p)->lpVtbl->GetPan(p,a)
|
||||
#define IDirectSoundBuffer_GetFrequency(p,a) (p)->lpVtbl->GetFrequency(p,a)
|
||||
#define IDirectSoundBuffer_GetStatus(p,a) (p)->lpVtbl->GetStatus(p,a)
|
||||
#define IDirectSoundBuffer_Initialize(p,a,b) (p)->lpVtbl->Initialize(p,a,b)
|
||||
#define IDirectSoundBuffer_Lock(p,a,b,c,d,e,f,g) (p)->lpVtbl->Lock(p,a,b,c,d,e,f,g)
|
||||
#define IDirectSoundBuffer_Play(p,a,b,c) (p)->lpVtbl->Play(p,a,b,c)
|
||||
#define IDirectSoundBuffer_SetCurrentPosition(p,a) (p)->lpVtbl->SetCurrentPosition(p,a)
|
||||
#define IDirectSoundBuffer_SetFormat(p,a) (p)->lpVtbl->SetFormat(p,a)
|
||||
#define IDirectSoundBuffer_SetVolume(p,a) (p)->lpVtbl->SetVolume(p,a)
|
||||
#define IDirectSoundBuffer_SetPan(p,a) (p)->lpVtbl->SetPan(p,a)
|
||||
#define IDirectSoundBuffer_SetFrequency(p,a) (p)->lpVtbl->SetFrequency(p,a)
|
||||
#define IDirectSoundBuffer_Stop(p) (p)->lpVtbl->Stop(p)
|
||||
#define IDirectSoundBuffer_Unlock(p,a,b,c,d) (p)->lpVtbl->Unlock(p,a,b,c,d)
|
||||
#define IDirectSoundBuffer_Restore(p) (p)->lpVtbl->Restore(p)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Return Codes
|
||||
*/
|
||||
|
||||
#define DS_OK 0
|
||||
|
||||
/*
|
||||
* The call failed because resources (such as a priority level)
|
||||
* were already being used by another caller.
|
||||
*/
|
||||
#define DSERR_ALLOCATED MAKE_DSHRESULT( 10 )
|
||||
/*
|
||||
* The control (vol,pan,etc.) requested by the caller is not available.
|
||||
*/
|
||||
#define DSERR_CONTROLUNAVAIL MAKE_DSHRESULT( 30 )
|
||||
/*
|
||||
* An invalid parameter was passed to the returning function
|
||||
*/
|
||||
#define DSERR_INVALIDPARAM E_INVALIDARG
|
||||
/*
|
||||
* This call is not valid for the current state of this object
|
||||
*/
|
||||
#define DSERR_INVALIDCALL MAKE_DSHRESULT( 50 )
|
||||
/*
|
||||
* An undetermined error occured inside the DSound subsystem
|
||||
*/
|
||||
#define DSERR_GENERIC E_FAIL
|
||||
/*
|
||||
* The caller does not have the priority level required for the function to
|
||||
* succeed.
|
||||
*/
|
||||
#define DSERR_PRIOLEVELNEEDED MAKE_DSHRESULT( 70 )
|
||||
/*
|
||||
* The DSound subsystem couldn't allocate sufficient memory to complete the
|
||||
* caller's request.
|
||||
*/
|
||||
#define DSERR_OUTOFMEMORY E_OUTOFMEMORY
|
||||
/*
|
||||
* The specified WAVE format is not supported
|
||||
*/
|
||||
#define DSERR_BADFORMAT MAKE_DSHRESULT( 100 )
|
||||
/*
|
||||
* The function called is not supported at this time
|
||||
*/
|
||||
#define DSERR_UNSUPPORTED E_NOTIMPL
|
||||
/*
|
||||
* No sound driver is available for use
|
||||
*/
|
||||
#define DSERR_NODRIVER MAKE_DSHRESULT( 120 )
|
||||
/*
|
||||
* This object is already initialized
|
||||
*/
|
||||
#define DSERR_ALREADYINITIALIZED MAKE_DSHRESULT( 130 )
|
||||
/*
|
||||
* This object does not support aggregation
|
||||
*/
|
||||
#define DSERR_NOAGGREGATION CLASS_E_NOAGGREGATION
|
||||
/*
|
||||
* The buffer memory has been lost, and must be Restored.
|
||||
*/
|
||||
#define DSERR_BUFFERLOST MAKE_DSHRESULT( 150 )
|
||||
/*
|
||||
* Another app has a higher priority level, preventing this call from
|
||||
* succeeding.
|
||||
*/
|
||||
#define DSERR_OTHERAPPHASPRIO MAKE_DSHRESULT( 160 )
|
||||
/*
|
||||
* The Initialize() member on the Direct Sound Object has not been
|
||||
* called or called successfully before calls to other members.
|
||||
*/
|
||||
#define DSERR_UNINITIALIZED MAKE_DSHRESULT( 170 )
|
||||
|
||||
|
||||
|
||||
|
||||
//==========================================================================;
|
||||
//
|
||||
// Flags...
|
||||
//
|
||||
//==========================================================================;
|
||||
|
||||
#define DSCAPS_PRIMARYMONO 0x00000001
|
||||
#define DSCAPS_PRIMARYSTEREO 0x00000002
|
||||
#define DSCAPS_PRIMARY8BIT 0x00000004
|
||||
#define DSCAPS_PRIMARY16BIT 0x00000008
|
||||
#define DSCAPS_CONTINUOUSRATE 0x00000010
|
||||
#define DSCAPS_EMULDRIVER 0x00000020
|
||||
#define DSCAPS_CERTIFIED 0x00000040
|
||||
#define DSCAPS_SECONDARYMONO 0x00000100
|
||||
#define DSCAPS_SECONDARYSTEREO 0x00000200
|
||||
#define DSCAPS_SECONDARY8BIT 0x00000400
|
||||
#define DSCAPS_SECONDARY16BIT 0x00000800
|
||||
|
||||
|
||||
|
||||
#define DSBPLAY_LOOPING 0x00000001
|
||||
|
||||
|
||||
|
||||
#define DSBSTATUS_PLAYING 0x00000001
|
||||
#define DSBSTATUS_BUFFERLOST 0x00000002
|
||||
#define DSBSTATUS_LOOPING 0x00000004
|
||||
|
||||
|
||||
#define DSBLOCK_FROMWRITECURSOR 0x00000001
|
||||
|
||||
|
||||
|
||||
#define DSSCL_NORMAL 1
|
||||
#define DSSCL_PRIORITY 2
|
||||
#define DSSCL_EXCLUSIVE 3
|
||||
#define DSSCL_WRITEPRIMARY 4
|
||||
|
||||
|
||||
|
||||
#define DSBCAPS_PRIMARYBUFFER 0x00000001
|
||||
#define DSBCAPS_STATIC 0x00000002
|
||||
#define DSBCAPS_LOCHARDWARE 0x00000004
|
||||
#define DSBCAPS_LOCSOFTWARE 0x00000008
|
||||
#define DSBCAPS_CTRLFREQUENCY 0x00000020
|
||||
#define DSBCAPS_CTRLPAN 0x00000040
|
||||
#define DSBCAPS_CTRLVOLUME 0x00000080
|
||||
#define DSBCAPS_CTRLDEFAULT 0x000000E0 // Pan + volume + frequency.
|
||||
#define DSBCAPS_CTRLALL 0x000000E0 // All control capabilities
|
||||
#define DSBCAPS_STICKYFOCUS 0x00004000
|
||||
#define DSBCAPS_GETCURRENTPOSITION2 0x00010000 // More accurate play cursor under emulation
|
||||
|
||||
|
||||
|
||||
|
||||
#define DSSPEAKER_HEADPHONE 1
|
||||
#define DSSPEAKER_MONO 2
|
||||
#define DSSPEAKER_QUAD 3
|
||||
#define DSSPEAKER_STEREO 4
|
||||
#define DSSPEAKER_SURROUND 5
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* __DSOUND_INCLUDED__ */
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
#ifndef __ENGLISH_
|
||||
#define __ENGLISH_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define SHIFT 16
|
||||
#define CTRL 17
|
||||
#define ALT 18
|
||||
|
||||
#define F1 124
|
||||
#define F2 125
|
||||
#define F3 126
|
||||
#define F4 127
|
||||
#define F5 128
|
||||
#define F6 129
|
||||
#define F7 130
|
||||
#define F8 131
|
||||
#define F9 132
|
||||
#define F10 133
|
||||
#define F11 134
|
||||
#define F12 135
|
||||
|
||||
#define SHIFT_F1 368
|
||||
#define SHIFT_F2 369
|
||||
#define SHIFT_F3 370
|
||||
#define SHIFT_F4 371
|
||||
#define SHIFT_F5 372
|
||||
#define SHIFT_F6 373
|
||||
#define SHIFT_F7 374
|
||||
#define SHIFT_F8 375
|
||||
#define SHIFT_F9 376
|
||||
#define SHIFT_F10 377
|
||||
#define SHIFT_F11 378
|
||||
#define SHIFT_F12 379
|
||||
|
||||
#define ALT_F1 624
|
||||
#define ALT_F2 625
|
||||
#define ALT_F3 626
|
||||
#define ALT_F4 627
|
||||
#define ALT_F5 628
|
||||
#define ALT_F6 629
|
||||
#define ALT_F7 630
|
||||
#define ALT_F8 631
|
||||
#define ALT_F9 632
|
||||
#define ALT_F10 633
|
||||
#define ALT_F11 634
|
||||
#define ALT_F12 635
|
||||
|
||||
#define CTRL_F1 880
|
||||
#define CTRL_F2 881
|
||||
#define CTRL_F3 882
|
||||
#define CTRL_F4 883
|
||||
#define CTRL_F5 884
|
||||
#define CTRL_F6 885
|
||||
#define CTRL_F7 886
|
||||
#define CTRL_F8 887
|
||||
#define CTRL_F9 888
|
||||
#define CTRL_F10 889
|
||||
#define CTRL_F11 890
|
||||
#define CTRL_F12 891
|
||||
|
||||
#define ESC 27
|
||||
#define TAB 9
|
||||
#define CAPS 20
|
||||
#define SCRL_LOCK 145 //*** this may be incorrect! DB
|
||||
#define SNAPSHOT 44
|
||||
#define PAUSE 19
|
||||
#define NUM_LOCK 144
|
||||
#define BACKSPACE 8
|
||||
|
||||
#define INSERT 245
|
||||
#define DEL 246
|
||||
|
||||
#define END 247
|
||||
|
||||
#define DNARROW 248
|
||||
#define PGDN 249
|
||||
#define LEFTARROW 250
|
||||
#define RIGHTARROW 251
|
||||
#define HOME 252
|
||||
#define UPARROW 253
|
||||
#define PGUP 254
|
||||
|
||||
#define SHIFT_TAB 265
|
||||
|
||||
#define SHIFT_INSERT 501
|
||||
#define SHIFT_DELETE 502
|
||||
#define SHIFT_END 503
|
||||
#define SHIFT_DNARROW 504
|
||||
#define SHIFT_PGDN 505
|
||||
#define SHIFT_LEFTARROW 506
|
||||
#define SHIFT_RIGHTARROW 507
|
||||
#define SHIFT_HOME 508
|
||||
#define SHIFT_UPARROW 509
|
||||
#define SHIFT_PGUP 510
|
||||
|
||||
#define ALT_TAB 521
|
||||
|
||||
#define ALT_INSERT 757
|
||||
#define ALT_DELETE 758
|
||||
#define ALT_END 759
|
||||
#define ALT_DNARROW 760
|
||||
#define ALT_PGDN 761
|
||||
#define ALT_LEFTARROW 762
|
||||
#define ALT_RIGHTARROW 763
|
||||
#define ALT_HOME 764
|
||||
#define ALT_UPARROW 765
|
||||
#define ALT_PGUP 766
|
||||
|
||||
#define CTRL_TAB 777
|
||||
|
||||
#define CTRL_INSERT 1013
|
||||
#define CTRL_DELETE 1014
|
||||
#define CTRL_END 1015
|
||||
#define CTRL_DNARROW 1016
|
||||
#define CTRL_PGDN 1017
|
||||
#define CTRL_LEFTARROW 1018
|
||||
#define CTRL_RIGHTARROW 1019
|
||||
#define CTRL_HOME 1020
|
||||
#define CTRL_UPARROW 1021
|
||||
#define CTRL_PGUP 1022
|
||||
|
||||
#define CURSOR 1023
|
||||
|
||||
#define ENTER 13
|
||||
#define SPACE 32
|
||||
|
||||
#define COMMA 188
|
||||
#define FULLSTOP 190
|
||||
|
||||
#endif
|
||||
+1001
File diff suppressed because it is too large
Load Diff
+1224
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
#ifndef _FMOD_ERRORS_H
|
||||
#define _FMOD_ERRORS_H
|
||||
static STR8 FMOD_ErrorString(int errcode)
|
||||
{
|
||||
switch (errcode)
|
||||
{
|
||||
case FMOD_ERR_NONE: return "No errors";
|
||||
case FMOD_ERR_BUSY: return "Cannot call this command after FSOUND_Init. Call FSOUND_Close first.";
|
||||
case FMOD_ERR_UNINITIALIZED: return "This command failed because FSOUND_Init was not called";
|
||||
case FMOD_ERR_PLAY: return "Playing the sound failed.";
|
||||
case FMOD_ERR_INIT: return "Error initializing output device.";
|
||||
case FMOD_ERR_ALLOCATED: return "The output device is already in use and cannot be reused.";
|
||||
case FMOD_ERR_OUTPUT_FORMAT: return "Soundcard does not support the features needed for this soundsystem (16bit stereo output)";
|
||||
case FMOD_ERR_COOPERATIVELEVEL: return "Error setting cooperative level for hardware.";
|
||||
case FMOD_ERR_CREATEBUFFER: return "Error creating hardware sound buffer.";
|
||||
case FMOD_ERR_FILE_NOTFOUND: return "File not found";
|
||||
case FMOD_ERR_FILE_FORMAT: return "Unknown file format";
|
||||
case FMOD_ERR_FILE_BAD: return "Error loading file";
|
||||
case FMOD_ERR_MEMORY: return "Not enough memory ";
|
||||
case FMOD_ERR_VERSION: return "The version number of this file format is not supported";
|
||||
case FMOD_ERR_INVALID_PARAM: return "An invalid parameter was passed to this function";
|
||||
case FMOD_ERR_NO_EAX: return "Tried to use an EAX command on a non EAX enabled channel or output.";
|
||||
case FMOD_ERR_CHANNEL_ALLOC: return "Failed to allocate a new channel";
|
||||
case FMOD_ERR_RECORD: return "Recording not supported on this device";
|
||||
case FMOD_ERR_MEDIAPLAYER: return "Required Mediaplayer codec is not installed";
|
||||
|
||||
default : return "Unknown error";
|
||||
};
|
||||
}
|
||||
#endif
|
||||
+1090
File diff suppressed because it is too large
Load Diff
+217
@@ -0,0 +1,217 @@
|
||||
#ifndef __IMAGE_H
|
||||
#define __IMAGE_H
|
||||
|
||||
#include "MemMan.h"
|
||||
#include "imgfmt.h"
|
||||
|
||||
// The HIMAGE module provides a common interface for managing image data. This module
|
||||
// includes:
|
||||
// - A set of data structures representing image data. Data can be 8 or 16 bpp and/or
|
||||
// compressed
|
||||
// - A set of file loaders which load specific file formats into the internal data format
|
||||
// - A set of blitters which blt the data to memory
|
||||
// - A comprehensive automatic blitter which blits the appropriate type based on the
|
||||
// image header.
|
||||
|
||||
|
||||
// Defines for type of file readers
|
||||
#define PCX_FILE_READER 0x1
|
||||
#define TGA_FILE_READER 0x2
|
||||
#define STCI_FILE_READER 0x4
|
||||
#define TRLE_FILE_READER 0x8
|
||||
#define PNG_FILE_READER 0x10
|
||||
#define JPC_FILE_READER 0x20
|
||||
#define UNKNOWN_FILE_READER 0x200
|
||||
|
||||
// Defines for buffer bit depth
|
||||
#define BUFFER_8BPP 0x1
|
||||
#define BUFFER_16BPP 0x2
|
||||
|
||||
// Defines for image charactoristics
|
||||
#define IMAGE_COMPRESSED 0x0001
|
||||
#define IMAGE_TRLECOMPRESSED 0x0002
|
||||
#define IMAGE_PALETTE 0x0004
|
||||
#define IMAGE_BITMAPDATA 0x0008
|
||||
#define IMAGE_APPDATA 0x0010
|
||||
#define IMAGE_ALLIMAGEDATA 0x000C
|
||||
#define IMAGE_ALLDATA 0x001C
|
||||
|
||||
// Palette structure, mimics that of Win32
|
||||
typedef struct tagSGPPaletteEntry
|
||||
{
|
||||
UINT8 peRed;
|
||||
UINT8 peGreen;
|
||||
UINT8 peBlue;
|
||||
UINT8 peFlags;
|
||||
|
||||
} SGPPaletteEntry;
|
||||
|
||||
#define AUX_FULL_TILE 0x01
|
||||
#define AUX_ANIMATED_TILE 0x02
|
||||
#define AUX_DYNAMIC_TILE 0x04
|
||||
#define AUX_INTERACTIVE_TILE 0x08
|
||||
#define AUX_IGNORES_HEIGHT 0x10
|
||||
#define AUX_USES_LAND_Z 0x20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 ubWallOrientation;
|
||||
UINT8 ubNumberOfTiles;
|
||||
UINT16 usTileLocIndex;
|
||||
UINT8 ubUnused1[3];
|
||||
UINT8 ubCurrentFrame;
|
||||
UINT8 ubNumberOfFrames;
|
||||
UINT8 fFlags;
|
||||
UINT8 ubUnused[6];
|
||||
} AuxObjectData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
INT8 bTileOffsetX;
|
||||
INT8 bTileOffsetY;
|
||||
} RelTileLoc; // relative tile location
|
||||
|
||||
// TRLE subimage structure, mirroring that of ST(C)I
|
||||
typedef struct tagETRLEObject
|
||||
{
|
||||
UINT32 uiDataOffset;
|
||||
UINT32 uiDataLength;
|
||||
INT16 sOffsetX;
|
||||
INT16 sOffsetY;
|
||||
UINT16 usHeight;
|
||||
UINT16 usWidth;
|
||||
} ETRLEObject;
|
||||
|
||||
typedef struct tagETRLEData
|
||||
{
|
||||
PTR pPixData;
|
||||
UINT32 uiSizePixData;
|
||||
ETRLEObject * pETRLEObject;
|
||||
UINT16 usNumberOfObjects;
|
||||
} ETRLEData;
|
||||
|
||||
// Image header structure
|
||||
typedef struct
|
||||
{
|
||||
UINT16 usWidth;
|
||||
UINT16 usHeight;
|
||||
UINT8 ubBitDepth;
|
||||
UINT16 fFlags;
|
||||
SGPFILENAME ImageFile;
|
||||
UINT32 iFileLoader;
|
||||
SGPPaletteEntry* pPalette;
|
||||
UINT16* pui16BPPPalette;
|
||||
UINT8* pAppData;
|
||||
UINT32 uiAppDataSize;
|
||||
// This union is used to describe each data type and is flexible to include the
|
||||
// data strucutre of the compresssed format, once developed.
|
||||
union
|
||||
{
|
||||
PTR pImageData;
|
||||
PTR pCompressedImageData;
|
||||
UINT8* p8BPPData;
|
||||
UINT16* p16BPPData;
|
||||
UINT32* p32BPPData;
|
||||
struct
|
||||
{
|
||||
UINT8* pPixData8;
|
||||
UINT32 uiSizePixData;
|
||||
ETRLEObject* pETRLEObject;
|
||||
UINT16 usNumberOfObjects;
|
||||
};
|
||||
};
|
||||
|
||||
} image_type, *HIMAGE;
|
||||
|
||||
|
||||
#define SGPGetRValue(rgb) ((BYTE) (rgb))
|
||||
#define SGPGetBValue(rgb) ((BYTE) ((rgb) >> 16))
|
||||
#define SGPGetGValue(rgb) ((BYTE) (((UINT16) (rgb)) >> 8))
|
||||
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Function prototypes
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
namespace ImageFileType
|
||||
{
|
||||
enum TestOrder
|
||||
{
|
||||
DEFAULT = 0, // check extension
|
||||
JPC, // ignore file extension, test only *.jpc
|
||||
JPC_FALLBACK, // test *.jpc, fallback to original type
|
||||
PNG, // ignore file extension, test only *.png
|
||||
PNG_FALLBACK, // test *.png, fallback to original type
|
||||
};
|
||||
};
|
||||
|
||||
// This function will return NULL if it fails, and call SetLastError() to set
|
||||
// error information
|
||||
HIMAGE CreateImage( SGPFILENAME ImageFile, UINT16 fContents, ImageFileType::TestOrder order = ImageFileType::JPC_FALLBACK);
|
||||
|
||||
// This function destroys the HIMAGE structure as well as its contents
|
||||
BOOLEAN DestroyImage( HIMAGE hImage );
|
||||
|
||||
// This function releases data allocated to various parts of the image based
|
||||
// on the contents flags passed as a parameter. If a contents flag is given
|
||||
// and the image does not contain that data, no error is raised
|
||||
BOOLEAN ReleaseImageData( HIMAGE hImage, UINT16 fContents );
|
||||
|
||||
// This function will attept to Load data from an existing image object's filename
|
||||
// In this way, dynamic loading of image data can be done
|
||||
BOOLEAN LoadImageData( HIMAGE hImage, UINT16 fContents );
|
||||
|
||||
// This function will run the appropriate copy function based on the type of HIMAGE object
|
||||
BOOLEAN CopyImageToBuffer( HIMAGE hImage, UINT32 fBufferType, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
|
||||
// The following blitters are used by the function above as well as clients
|
||||
#ifndef NO_ZLIB_COMPRESSION
|
||||
BOOLEAN Copy8BPPCompressedImageTo8BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
BOOLEAN Copy8BPPCompressedImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
BOOLEAN Copy16BPPCompressedImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
// This function will extract a compressed image into a non-compressed buffer
|
||||
BOOLEAN Extract8BPPCompressedImageToBuffer( HIMAGE hImage, BYTE *pDestBuf );
|
||||
BOOLEAN Extract16BPPCompressedImageToBuffer( HIMAGE hImage, BYTE *pDestBuf );
|
||||
#endif
|
||||
|
||||
BOOLEAN Copy8BPPImageTo8BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
BOOLEAN Copy8BPPImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
BOOLEAN Copy16BPPImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
|
||||
|
||||
// This function will create a buffer in memory of ETRLE data, excluding palette
|
||||
BOOLEAN GetETRLEImageData( HIMAGE hImage, ETRLEData *pBuffer );
|
||||
|
||||
// UTILITY FUNCTIONS
|
||||
|
||||
// Used to create a 16BPP Palette from an 8 bit palette, found in himage.c
|
||||
UINT16 *Create16BPPPaletteShaded( SGPPaletteEntry *pPalette, UINT32 rscale, UINT32 gscale, UINT32 bscale, BOOLEAN mono);
|
||||
UINT16 *Create16BPPPalette( SGPPaletteEntry *pPalette );
|
||||
UINT16 Get16BPPColor( UINT32 RGBValue );
|
||||
UINT32 GetRGBColor( UINT16 Value16BPP );
|
||||
SGPPaletteEntry *ConvertRGBToPaletteEntry(UINT8 sbStart, UINT8 sbEnd, UINT8 *pOldPalette);
|
||||
|
||||
extern UINT16 gusAlphaMask;
|
||||
extern UINT16 gusRedMask;
|
||||
extern UINT16 gusGreenMask;
|
||||
extern UINT16 gusBlueMask;
|
||||
extern INT16 gusRedShift;
|
||||
extern INT16 gusBlueShift;
|
||||
extern INT16 gusGreenShift;
|
||||
|
||||
// used to convert 565 RGB data into different bit-formats
|
||||
void ConvertRGBDistribution565To555( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
|
||||
void ConvertRGBDistribution565To655( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
|
||||
void ConvertRGBDistribution565To556( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
|
||||
void ConvertRGBDistribution565ToAny( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,92 @@
|
||||
#if !defined( STCI_H )
|
||||
|
||||
#define STCI_H
|
||||
|
||||
// Sir-Tech's Crazy Image (STCI) file format specifications. Each file is composed of:
|
||||
// 1 ImageFileHeader, uncompressed
|
||||
// * Palette (STCI_INDEXED, size = uiNumberOfColours * PALETTE_ELEMENT_SIZE), uncompressed
|
||||
// * SubRectInfo's (usNumberOfRects > 0, size = usNumberOfSubRects * sizeof(SubRectInfo) ), uncompressed
|
||||
// * Bytes of image data, possibly compressed
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
#define STCI_ID_STRING "STCI"
|
||||
#define STCI_ID_LEN 4
|
||||
|
||||
#define STCI_ETRLE_COMPRESSED 0x0020
|
||||
#define STCI_ZLIB_COMPRESSED 0x0010
|
||||
#define STCI_INDEXED 0x0008
|
||||
#define STCI_RGB 0x0004
|
||||
#define STCI_ALPHA 0x0002
|
||||
#define STCI_TRANSPARENT 0x0001
|
||||
|
||||
// ETRLE defines
|
||||
#define COMPRESS_TRANSPARENT 0x80
|
||||
#define COMPRESS_NON_TRANSPARENT 0x00
|
||||
#define COMPRESS_RUN_LIMIT 0x7F
|
||||
|
||||
// NB if you're going to change the header definition:
|
||||
// - make sure that everything in this header is nicely aligned
|
||||
// - don't exceed the 64-byte maximum
|
||||
typedef struct
|
||||
{
|
||||
UINT8 cID[STCI_ID_LEN];
|
||||
UINT32 uiOriginalSize;
|
||||
UINT32 uiStoredSize; // equal to uiOriginalSize if data uncompressed
|
||||
UINT32 uiTransparentValue;
|
||||
UINT32 fFlags;
|
||||
UINT16 usHeight;
|
||||
UINT16 usWidth;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
UINT32 uiRedMask;
|
||||
UINT32 uiGreenMask;
|
||||
UINT32 uiBlueMask;
|
||||
UINT32 uiAlphaMask;
|
||||
UINT8 ubRedDepth;
|
||||
UINT8 ubGreenDepth;
|
||||
UINT8 ubBlueDepth;
|
||||
UINT8 ubAlphaDepth;
|
||||
} RGB;
|
||||
struct
|
||||
{ // For indexed files, the palette will contain 3 separate bytes for red, green, and blue
|
||||
UINT32 uiNumberOfColours;
|
||||
UINT16 usNumberOfSubImages;
|
||||
UINT8 ubRedDepth;
|
||||
UINT8 ubGreenDepth;
|
||||
UINT8 ubBlueDepth;
|
||||
UINT8 cIndexedUnused[11];
|
||||
} Indexed;
|
||||
};
|
||||
UINT8 ubDepth; // size in bits of one pixel as stored in the file
|
||||
UINT32 uiAppDataSize;
|
||||
UINT8 cUnused[15];
|
||||
} STCIHeader;
|
||||
|
||||
#define STCI_HEADER_SIZE 64
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT32 uiDataOffset;
|
||||
UINT32 uiDataLength;
|
||||
INT16 sOffsetX;
|
||||
INT16 sOffsetY;
|
||||
UINT16 usHeight;
|
||||
UINT16 usWidth;
|
||||
} STCISubImage;
|
||||
|
||||
#define STCI_SUBIMAGE_SIZE 16
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 ubRed;
|
||||
UINT8 ubGreen;
|
||||
UINT8 ubBlue;
|
||||
} STCIPaletteElement;
|
||||
|
||||
#define STCI_PALETTE_ELEMENT_SIZE 3
|
||||
#define STCI_8BIT_PALETTE_SIZE 768
|
||||
|
||||
#endif
|
||||
+431
@@ -0,0 +1,431 @@
|
||||
//**************************************************************************
|
||||
//
|
||||
// Filename : impTGA.c
|
||||
//
|
||||
// Purpose : .tga file importer
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 20nov96:HJH - Creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#include "types.h"
|
||||
#include "Fileman.h"
|
||||
#include "memman.h"
|
||||
#include "WCheck.h"
|
||||
#include "himage.h"
|
||||
#include "string.h"
|
||||
#include "debug.h"
|
||||
#include "video.h"
|
||||
#include "impTGA.h"
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Typedefs
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN ReadUncompColMapImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents );
|
||||
BOOLEAN ReadUncompRGBImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents );
|
||||
BOOLEAN ReadRLEColMapImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents );
|
||||
BOOLEAN ReadRLERGBImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents );
|
||||
//BOOLEAN ConvertTGAToSystemBPPFormat( HIMAGE hImage );
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Function Definitions
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN LoadTGAFileToImage( HIMAGE hImage, UINT16 fContents )
|
||||
{
|
||||
HWFILE hFile;
|
||||
UINT8 uiImgID, uiColMap, uiType;
|
||||
UINT32 uiBytesRead;
|
||||
BOOLEAN fReturnVal = FALSE;
|
||||
|
||||
Assert( hImage != NULL );
|
||||
|
||||
CHECKF( FileExists( hImage->ImageFile ) );
|
||||
|
||||
hFile = FileOpen( hImage->ImageFile, FILE_ACCESS_READ, FALSE );
|
||||
CHECKF( hFile );
|
||||
|
||||
if ( !FileRead( hFile, &uiImgID, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiColMap, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiType, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto end;
|
||||
|
||||
switch( uiType )
|
||||
{
|
||||
case 1:
|
||||
fReturnVal = ReadUncompColMapImage( hImage, hFile, uiImgID, uiColMap, fContents );
|
||||
break;
|
||||
case 2:
|
||||
fReturnVal = ReadUncompRGBImage( hImage, hFile, uiImgID, uiColMap, fContents );
|
||||
break;
|
||||
case 9:
|
||||
fReturnVal = ReadRLEColMapImage( hImage, hFile, uiImgID, uiColMap, fContents );
|
||||
break;
|
||||
case 10:
|
||||
fReturnVal = ReadRLERGBImage( hImage, hFile, uiImgID, uiColMap, fContents );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Set remaining values
|
||||
|
||||
end:
|
||||
FileClose( hFile );
|
||||
return( fReturnVal );
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// ReadUncompColMapImage
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 20nov96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN ReadUncompColMapImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// ReadUncompRGBImage
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 20nov96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN ReadUncompRGBImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents )
|
||||
{
|
||||
UINT8 *pBMData;
|
||||
UINT8 *pBMPtr;
|
||||
|
||||
UINT16 uiColMapOrigin;
|
||||
UINT16 uiColMapLength;
|
||||
UINT8 uiColMapEntrySize;
|
||||
UINT32 uiBytesRead;
|
||||
UINT16 uiXOrg;
|
||||
UINT16 uiYOrg;
|
||||
UINT16 uiWidth;
|
||||
UINT16 uiHeight;
|
||||
UINT8 uiImagePixelSize;
|
||||
UINT8 uiImageDescriptor;
|
||||
UINT32 iNumValues;
|
||||
UINT16 cnt;
|
||||
|
||||
UINT32 i;
|
||||
UINT8 r;
|
||||
UINT8 g;
|
||||
UINT8 b;
|
||||
|
||||
if ( !FileRead( hFile, &uiColMapOrigin, sizeof(UINT16), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiColMapLength, sizeof(UINT16), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiColMapEntrySize, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto end;
|
||||
|
||||
if ( !FileRead( hFile, &uiXOrg, sizeof(UINT16), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiYOrg, sizeof(UINT16), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiWidth, sizeof(UINT16), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiHeight, sizeof(UINT16), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiImagePixelSize, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto end;
|
||||
if ( !FileRead( hFile, &uiImageDescriptor, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto end;
|
||||
|
||||
// skip the id
|
||||
FileSeek( hFile, uiImgID, FILE_SEEK_FROM_CURRENT );
|
||||
|
||||
// skip the colour map
|
||||
if ( uiColMap != 0 )
|
||||
{
|
||||
FileSeek( hFile, uiColMapLength * (uiImagePixelSize / 8), FILE_SEEK_FROM_CURRENT );
|
||||
}
|
||||
|
||||
// Set some HIMAGE data values
|
||||
hImage->usWidth = uiWidth;
|
||||
hImage->usHeight = uiHeight;
|
||||
hImage->ubBitDepth = uiImagePixelSize;
|
||||
|
||||
// Allocate memory based on bpp, height, width
|
||||
|
||||
// Only do if contents flag is appropriate
|
||||
if ( fContents & IMAGE_BITMAPDATA )
|
||||
{
|
||||
|
||||
if ( uiImagePixelSize == 16 )
|
||||
{
|
||||
|
||||
iNumValues = uiWidth * uiHeight;
|
||||
|
||||
hImage->p16BPPData = (UINT16 *) MemAlloc( iNumValues * (uiImagePixelSize / 8) );
|
||||
|
||||
if ( hImage->p16BPPData == NULL )
|
||||
goto end;
|
||||
|
||||
// Get data pointer
|
||||
pBMData = hImage->p8BPPData;
|
||||
|
||||
// Start at end
|
||||
pBMData += uiWidth * ( uiHeight - 1 ) * (uiImagePixelSize / 8);
|
||||
|
||||
// Data is stored top-bottom - reverse for SGP HIMAGE format
|
||||
for ( cnt = 0; cnt < uiHeight-1; cnt++ )
|
||||
{
|
||||
if ( !FileRead( hFile, pBMData, uiWidth*2, &uiBytesRead ) )
|
||||
goto freeEnd;
|
||||
|
||||
pBMData -= uiWidth * 2;
|
||||
}
|
||||
// Do first row
|
||||
if ( !FileRead( hFile, pBMData, uiWidth*2, &uiBytesRead ) )
|
||||
goto freeEnd;
|
||||
|
||||
// Convert TGA 5,5,5 16 BPP data into current system 16 BPP Data
|
||||
//ConvertTGAToSystemBPPFormat( hImage );
|
||||
|
||||
hImage->fFlags |= IMAGE_BITMAPDATA;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ( uiImagePixelSize == 24 )
|
||||
{
|
||||
hImage->p8BPPData = (UINT8 *) MemAlloc( uiWidth * uiHeight * (uiImagePixelSize / 8) );
|
||||
|
||||
if ( hImage->p8BPPData == NULL )
|
||||
goto end;
|
||||
|
||||
// Get data pointer
|
||||
pBMData = (UINT8*)hImage->p8BPPData;
|
||||
|
||||
// Start at end
|
||||
pBMPtr = pBMData + uiWidth * ( uiHeight - 1 ) * 3;
|
||||
|
||||
iNumValues = uiWidth * uiHeight;
|
||||
|
||||
for ( cnt = 0; cnt < uiHeight; cnt++ )
|
||||
{
|
||||
for ( i=0 ; i < uiWidth; i++ )
|
||||
{
|
||||
if ( !FileRead( hFile, &b, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto freeEnd;
|
||||
if ( !FileRead( hFile, &g, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto freeEnd;
|
||||
if ( !FileRead( hFile, &r, sizeof(UINT8), &uiBytesRead ) )
|
||||
goto freeEnd;
|
||||
|
||||
pBMPtr[ i*3 ] = r;
|
||||
pBMPtr[ i*3+1 ] = g;
|
||||
pBMPtr[ i*3+2 ] = b;
|
||||
}
|
||||
pBMPtr -= uiWidth * 3;
|
||||
}
|
||||
hImage->fFlags |= IMAGE_BITMAPDATA;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return( TRUE );
|
||||
|
||||
end:
|
||||
return( FALSE );
|
||||
|
||||
freeEnd:
|
||||
MemFree( pBMData );
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// ReadRLEColMapImage
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 20nov96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN ReadRLEColMapImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// ReadRLERGBImage
|
||||
//
|
||||
//
|
||||
//
|
||||
// Parameter List :
|
||||
// Return Value :
|
||||
// Modification history :
|
||||
//
|
||||
// 20nov96:HJH ->creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
BOOLEAN ReadRLERGBImage( HIMAGE hImage, HWFILE hFile, UINT8 uiImgID, UINT8 uiColMap, UINT16 fContents )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
/*
|
||||
BOOLEAN ConvertTGAToSystemBPPFormat( HIMAGE hImage )
|
||||
{
|
||||
UINT16 usX, usY;
|
||||
UINT16 Old16BPPValue;
|
||||
UINT16 *pData;
|
||||
UINT16 usR, usG, usB;
|
||||
float scale_val;
|
||||
UINT32 uiRBitMask;
|
||||
UINT32 uiGBitMask;
|
||||
UINT32 uiBBitMask;
|
||||
UINT8 ubRNewShift;
|
||||
UINT8 ubGNewShift;
|
||||
UINT8 ubBNewShift;
|
||||
UINT8 ubScaleR;
|
||||
UINT8 ubScaleB;
|
||||
UINT8 ubScaleG;
|
||||
|
||||
// Basic algorithm for coonverting to different rgb distributions
|
||||
|
||||
// Get current Pixel Format from DirectDraw
|
||||
CHECKF( GetPrimaryRGBDistributionMasks( &uiRBitMask, &uiGBitMask, &uiBBitMask ) );
|
||||
|
||||
// Only convert if different
|
||||
if ( uiRBitMask == 0x7c00 && uiGBitMask == 0x3e0 && uiBBitMask == 0x1f )
|
||||
{
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
// Default values
|
||||
ubScaleR = 0;
|
||||
ubScaleG = 0;
|
||||
ubScaleB = 0;
|
||||
ubRNewShift = 10;
|
||||
ubGNewShift = 5;
|
||||
ubBNewShift = 0;
|
||||
|
||||
// Determine values
|
||||
switch( uiBBitMask )
|
||||
{
|
||||
case 0x3f: // 0000000000111111 pixel mask for blue
|
||||
|
||||
// 5-5-6
|
||||
ubRNewShift = 11;
|
||||
ubGNewShift = 6;
|
||||
ubScaleB = 1;
|
||||
break;
|
||||
|
||||
case 0x1f: // 0000000000011111 pixel mask for blue
|
||||
switch( uiGBitMask )
|
||||
{
|
||||
case 0x7e0: // 0000011111100000 pixel mask for green
|
||||
|
||||
// 5-6-5
|
||||
ubRNewShift = 11;
|
||||
ubScaleG = 1;
|
||||
break;
|
||||
|
||||
case 0x3e0: // 0000001111100000 pixel mask for green
|
||||
|
||||
switch( uiRBitMask )
|
||||
{
|
||||
case 0xfc00: // 1111110000000000 pixel mask for red
|
||||
|
||||
// 6-5-5
|
||||
ubScaleR = 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
pData = hImage->pui16BPPPalette;
|
||||
usX = 0;
|
||||
do
|
||||
{
|
||||
|
||||
usY = 0;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
// Get Old 5,5,5 value
|
||||
Old16BPPValue = hImage->p16BPPData[ usX * hImage->usWidth + usY ];
|
||||
|
||||
// Get component r,g,b values AT 5 5 5
|
||||
usR = ( Old16BPPValue & 0x7c00 ) >> 10;
|
||||
usG = ( Old16BPPValue & 0x3e0 ) >> 5;
|
||||
usB = Old16BPPValue & 0x1f;
|
||||
|
||||
// Scale accordingly
|
||||
usR = usR << ubScaleR;
|
||||
usG = usG << ubScaleG;
|
||||
usB = usB << ubScaleB;
|
||||
|
||||
hImage->p16BPPData[ usX * hImage->usWidth + usY ] = ((UINT16) ( ( usR << ubRNewShift | usG << ubGNewShift ) | usB ) );
|
||||
|
||||
usY++;
|
||||
|
||||
} while( usY < hImage->usWidth );
|
||||
|
||||
usX++;
|
||||
|
||||
} while( usX < hImage->usHeight );
|
||||
|
||||
return( TRUE );
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,54 @@
|
||||
//**************************************************************************
|
||||
//
|
||||
// Filename : impTGA.h
|
||||
//
|
||||
// Purpose : .tga file importer function prototypes
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 20nov96:HJH - Creation
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#ifndef _impTGA_h
|
||||
#define _impTGA_h
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
#include "types.h"
|
||||
#include "himage.h"
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Typedefs
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Function Prototypes
|
||||
//
|
||||
//**************************************************************************
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
BOOLEAN LoadTGAFileToImage( HIMAGE hImage, UINT16 fContents );
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
|
||||
+1720
File diff suppressed because it is too large
Load Diff
+154
@@ -0,0 +1,154 @@
|
||||
#ifndef __INPUT_
|
||||
#define __INPUT_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define SCAN_CODE_MASK 0xff0000
|
||||
#define EXT_CODE_MASK 0x01000000
|
||||
#define TRANSITION_MASK 0x80000000
|
||||
|
||||
#define KEY_DOWN 0x0001
|
||||
#define KEY_UP 0x0002
|
||||
#define KEY_REPEAT 0x0004
|
||||
#define LEFT_BUTTON_DOWN 0x0008
|
||||
#define LEFT_BUTTON_UP 0x0010
|
||||
#define LEFT_BUTTON_DBL_CLK 0x0020
|
||||
#define LEFT_BUTTON_REPEAT 0x0040
|
||||
#define RIGHT_BUTTON_DOWN 0x0080
|
||||
#define RIGHT_BUTTON_UP 0x0100
|
||||
#define RIGHT_BUTTON_REPEAT 0x0200
|
||||
#define MOUSE_POS 0x0400
|
||||
#define MOUSE_WHEEL 0x0800
|
||||
#define MOUSE_WHEEL_UP 0x0800
|
||||
#define MOUSE_WHEEL_DOWN 0x1000
|
||||
#define MIDDLE_BUTTON_DOWN 0x2000
|
||||
#define MIDDLE_BUTTON_UP 0x4000
|
||||
#define MIDDLE_BUTTON_REPEAT 0x8000
|
||||
#define X1_BUTTON_DOWN 0x8010
|
||||
#define X1_BUTTON_UP 0x8020
|
||||
#define X1_BUTTON_REPEAT 0x8030
|
||||
#define X2_BUTTON_DOWN 0x8040
|
||||
#define X2_BUTTON_UP 0x8050
|
||||
#define X2_BUTTON_REPEAT 0x8060
|
||||
|
||||
#define SHIFT_DOWN 0x01
|
||||
#define CTRL_DOWN 0x02
|
||||
#define ALT_DOWN 0x04
|
||||
|
||||
#define MAX_STRING_INPUT 64
|
||||
#define DBL_CLK_TIME 300 // Increased by Alex, Jun-10-97, 200 felt too short
|
||||
#define BUTTON_REPEAT_TIMEOUT 250
|
||||
#define BUTTON_REPEAT_TIME 50
|
||||
|
||||
typedef struct InputAtom
|
||||
{
|
||||
UINT32 uiTimeStamp;
|
||||
UINT16 usKeyState;
|
||||
UINT16 usEvent;
|
||||
UINT32 usParam;
|
||||
UINT32 uiParam;
|
||||
|
||||
} InputAtom;
|
||||
|
||||
//Mouse pos extracting macros from InputAtom
|
||||
#define GETYPOS(a) HIWORD(((a)->uiParam))
|
||||
#define GETXPOS(a) LOWORD(((a)->uiParam))
|
||||
|
||||
|
||||
typedef struct StringInput
|
||||
{
|
||||
UINT16 *pString;
|
||||
UINT16 *pOriginalString;
|
||||
UINT16 *pFilter;
|
||||
UINT16 usMaxStringLength;
|
||||
UINT16 usCurrentStringLength;
|
||||
UINT16 usStringOffset;
|
||||
UINT16 usLastCharacter;
|
||||
BOOLEAN fInsertMode;
|
||||
BOOLEAN fFocus;
|
||||
struct StringInput *pPreviousString;
|
||||
struct StringInput *pNextString;
|
||||
|
||||
} StringInput;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern BOOLEAN InitializeInputManager(void);
|
||||
extern void ShutdownInputManager(void);
|
||||
extern BOOLEAN DequeueEvent(InputAtom *Event);
|
||||
extern void QueueEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam);
|
||||
|
||||
extern void KeyDown(UINT32 usParam, UINT32 uiParam);
|
||||
extern void KeyUp(UINT32 usParam, UINT32 uiParam);
|
||||
|
||||
extern void EnableDoubleClk(void);
|
||||
extern void DisableDoubleClk(void);
|
||||
extern void GetMousePos(SGPPoint *Point);
|
||||
|
||||
extern StringInput *InitStringInput(UINT16 *pInputString, UINT16 usLength, UINT16 *pFilter);
|
||||
extern void LinkPreviousString(StringInput *pCurrentString, StringInput *pPreviousString);
|
||||
extern void LinkNextString(StringInput *pCurrentString, StringInput *pNextString);
|
||||
extern UINT16 GetStringLastInput(void);
|
||||
extern BOOLEAN StringInputHasFocus(void);
|
||||
extern BOOLEAN SetStringFocus(StringInput *pStringDescriptor);
|
||||
extern UINT16 GetCursorPositionInString(StringInput *pStringDescriptor);
|
||||
extern UINT16 GetStringInputState(void);
|
||||
extern BOOLEAN StringHasFocus(StringInput *pStringDescriptor);
|
||||
extern UINT16 *GetString(StringInput *pStringDescriptor);
|
||||
extern void EndStringInput(StringInput *pStringDescriptor);
|
||||
extern BOOLEAN DequeueSpecificEvent(InputAtom *Event, UINT32 uiMaskFlags );
|
||||
|
||||
extern void RestrictMouseToXYXY(UINT16 usX1, UINT16 usY1, UINT16 usX2, UINT16 usY2);
|
||||
extern void RestrictMouseCursor(SGPRect *pRectangle);
|
||||
extern void FreeMouseCursor( BOOLEAN fLockForTacticalWindowedMode );
|
||||
extern BOOLEAN IsCursorRestricted( void );
|
||||
extern void GetRestrictedClipCursor( SGPRect *pRectangle );
|
||||
extern void RestoreCursorClipRect( void );
|
||||
|
||||
|
||||
void SimulateMouseMovement( UINT32 uiNewXPos, UINT32 uiNewYPos );
|
||||
BOOLEAN InputEventInside(InputAtom *Event, UINT32 uiX1, UINT32 uiY1, UINT32 uiX2, UINT32 uiY2);
|
||||
|
||||
INT16 GetMouseWheelDeltaValue( UINT32 wParam );
|
||||
|
||||
extern void DequeueAllKeyBoardEvents();
|
||||
extern BOOLEAN PeekSpecificEvent(UINT32 uiMaskFlags);//dnl ch74 221013
|
||||
|
||||
extern BOOLEAN gfKeyState[256]; // TRUE = Pressed, FALSE = Not Pressed
|
||||
|
||||
extern INT16 gusMouseXPos; // X position of the mouse on screen
|
||||
extern INT16 gusMouseYPos; // y position of the mouse on screen
|
||||
extern INT16 gsMouseWheelDeltaValue;//dnl ch4 210909
|
||||
extern BOOLEAN gfLeftButtonState; // TRUE = Pressed, FALSE = Not Pressed
|
||||
extern BOOLEAN gfRightButtonState; // TRUE = Pressed, FALSE = Not Pressed
|
||||
extern BOOLEAN gfMiddleButtonState;//dnl ch4 210909 TRUE = Pressed, FALSE = Not Pressed
|
||||
|
||||
extern BOOLEAN gfSGPInputReceived;
|
||||
|
||||
#define _KeyDown(a) gfKeyState[(a)]
|
||||
#define _LeftButtonDown gfLeftButtonState
|
||||
#define _RightButtonDown gfRightButtonState
|
||||
#define _MiddleButtonDown gfMiddleButtonState//dnl ch4 210909
|
||||
#define _WheelValue gsMouseWheelDeltaValue//dnl ch4 210909
|
||||
#define _MouseXPos gusMouseXPos
|
||||
#define _MouseYPos gusMouseYPos
|
||||
|
||||
// NOTE: this may not be the absolute most-latest current mouse co-ordinates, use GetCursorPos for that
|
||||
#define _gusMouseInside(x1,y1,x2,y2) ((gusMouseXPos >= x1) && (gusMouseXPos <= x2) && (gusMouseYPos >= y1) && (gusMouseYPos <= y2))
|
||||
|
||||
#define _EvType(a) ((InputAtom *)(a))->usEvent
|
||||
#define _EvTimeStamp(a) ((InputAtom *)(a))->uiTimeStamp
|
||||
#define _EvKey(a) ((InputAtom *)(a))->usParam
|
||||
#define _EvMouseX(a) (UINT16)(((InputAtom *)(a))->uiParam & 0x0000ffff)
|
||||
#define _EvMouseY(a) (UINT16)((((InputAtom *)(a))->uiParam & 0xffff0000) >> 16)
|
||||
#define _EvShiftDown(a) (((InputAtom *)(a))->usKeyState & SHIFT_DOWN)
|
||||
#define _EvCtrlDown(a) (((InputAtom *)(a))->usKeyState & CTRL_DOWN)
|
||||
#define _EvAltDown(a) (((InputAtom *)(a))->usKeyState & ALT_DOWN)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+683
@@ -0,0 +1,683 @@
|
||||
#include "line.h"
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Example Usage
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
// SEND THE PITCH IN BYTES
|
||||
// SetClippingRegionAndImageWidth( uiPitch, 15, 15, 30, 30 );
|
||||
//
|
||||
// LineDraw( TRUE, 10, 10, 200, 200, colour, pImageData);
|
||||
// OR
|
||||
// RectangleDraw( TRUE, 10, 10, 200, 200, colour, pImageData);
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Line Drawing Functions
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
int giImageWidth=0;
|
||||
int giClipXMin=0;
|
||||
int giClipXMax=0;
|
||||
int giClipYMin=0;
|
||||
int giClipYMax=0;
|
||||
|
||||
void DrawHorizontalRun(UINT8 **ScreenPtr, int XAdvance, int RunLength,
|
||||
int Color, int ScreenWidth);
|
||||
void DrawVerticalRun(UINT8 **ScreenPtr, int XAdvance, int RunLength,
|
||||
int Color, int ScreenWidth);
|
||||
|
||||
void DrawHorizontalRun8(UINT8 **ScreenPtr, int XAdvance,
|
||||
int RunLength, int Color, int ScreenWidth);
|
||||
void DrawVerticalRun8(UINT8 **ScreenPtr, int XAdvance,
|
||||
int RunLength, int Color, int ScreenWidth);
|
||||
|
||||
|
||||
void SetClippingRegionAndImageWidth(
|
||||
int iImageWidth,
|
||||
int iClipStartX,
|
||||
int iClipStartY,
|
||||
int iClipWidth,
|
||||
int iClipHeight
|
||||
)
|
||||
{
|
||||
giImageWidth = iImageWidth;
|
||||
giClipXMin = iClipStartX;
|
||||
giClipXMax = iClipStartX + iClipWidth-1;
|
||||
giClipYMin = iClipStartY;
|
||||
giClipYMax = iClipStartY + iClipHeight-1;
|
||||
}
|
||||
|
||||
BOOL Clipt( FLOAT denom, FLOAT num, FLOAT *tE, FLOAT *tL )
|
||||
{
|
||||
FLOAT t;
|
||||
BOOL accept;
|
||||
|
||||
accept = TRUE;
|
||||
|
||||
if ( denom > 0.0f )
|
||||
{
|
||||
t = num/denom;
|
||||
if ( t > *tL )
|
||||
accept = FALSE;
|
||||
else if ( t > *tE )
|
||||
*tE = t;
|
||||
}
|
||||
else if ( denom < 0.0f )
|
||||
{
|
||||
t = num/denom;
|
||||
if ( t < *tE )
|
||||
accept = FALSE;
|
||||
else if ( t < *tL )
|
||||
*tL = t;
|
||||
}
|
||||
else if ( num > 0 )
|
||||
accept = FALSE;
|
||||
|
||||
return(accept);
|
||||
}
|
||||
|
||||
BOOL ClipPoint( int x, int y )
|
||||
{
|
||||
return( x <= giClipXMax && x >= giClipXMin &&
|
||||
y <= giClipYMax && y >= giClipYMin );
|
||||
}
|
||||
|
||||
BOOL Clip2D( int *ix0, int *iy0, int *ix1, int *iy1 )
|
||||
{
|
||||
BOOL visible;
|
||||
FLOAT te, tl;
|
||||
FLOAT dx, dy;
|
||||
FLOAT x0, y0, x1, y1;
|
||||
|
||||
x0 = (FLOAT)*ix0;
|
||||
x1 = (FLOAT)*ix1;
|
||||
y0 = (FLOAT)*iy0;
|
||||
y1 = (FLOAT)*iy1;
|
||||
|
||||
dx = x1-x0;
|
||||
dy = y1-y0;
|
||||
visible = FALSE;
|
||||
|
||||
if ( dx == 0.0 && dy == 0.0 && ClipPoint(*ix0,*iy0) )
|
||||
visible = TRUE;
|
||||
else
|
||||
{
|
||||
te = 0.0f;
|
||||
tl = 1.0f;
|
||||
if ( Clipt( dx, (FLOAT)giClipXMin-x0, &te, &tl ) )
|
||||
{
|
||||
if ( Clipt(-dx, x0-(FLOAT)giClipXMax, &te, &tl ) )
|
||||
{
|
||||
if ( Clipt(dy, (FLOAT)giClipYMin-y0, &te, &tl ) )
|
||||
{
|
||||
if ( Clipt(-dy, y0-(FLOAT)giClipYMax, &te, &tl ) )
|
||||
{
|
||||
visible = TRUE;
|
||||
if ( tl < 1.0f )
|
||||
{
|
||||
x1 = x0 + tl*dx;
|
||||
y1 = y0 + tl*dy;
|
||||
}
|
||||
if ( te > 0 )
|
||||
{
|
||||
x0 = x0 + te*dx;
|
||||
y0 = y0 + te*dy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*ix0 = (int)x0;
|
||||
*ix1 = (int)x1;
|
||||
*iy0 = (int)y0;
|
||||
*iy1 = (int)y1;
|
||||
|
||||
return( visible );
|
||||
}
|
||||
|
||||
void LineDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr)
|
||||
{
|
||||
int Temp, AdjUp, AdjDown, ErrorTerm, XAdvance, XDelta, YDelta;
|
||||
int WholeStep, InitialPixelCount, FinalPixelCount, i, RunLength;
|
||||
int ScreenWidth=giImageWidth/2;
|
||||
char col2 = Color>>8;
|
||||
char col1 = Color & 0x00FF;
|
||||
|
||||
if ( fClip )
|
||||
{
|
||||
if ( !Clip2D( &XStart, &YStart, &XEnd, &YEnd ) )
|
||||
return;
|
||||
}
|
||||
|
||||
/* We'll always draw top to bottom, to reduce the number of cases we have to
|
||||
handle, and to make lines between the same endpoints draw the same pixels */
|
||||
if (YStart > YEnd) {
|
||||
Temp = YStart;
|
||||
YStart = YEnd;
|
||||
YEnd = Temp;
|
||||
Temp = XStart;
|
||||
XStart = XEnd;
|
||||
XEnd = Temp;
|
||||
}
|
||||
|
||||
// point to the bitmap address first pixel to draw
|
||||
ScreenPtr = ScreenPtr + YStart*giImageWidth + XStart*2;
|
||||
|
||||
/* Figure out whether we're going left or right, and how far we're
|
||||
going horizontally */
|
||||
if ((XDelta = XEnd - XStart) < 0)
|
||||
{
|
||||
XAdvance = -1;
|
||||
XDelta = -XDelta;
|
||||
}
|
||||
else
|
||||
{
|
||||
XAdvance = 1;
|
||||
}
|
||||
/* Figure out how far we're going vertically */
|
||||
YDelta = YEnd - YStart;
|
||||
|
||||
/* Special-case horizontal, vertical, and diagonal lines, for speed
|
||||
and to avoid nasty boundary conditions and division by 0 */
|
||||
if (XDelta == 0)
|
||||
{
|
||||
/* Vertical line */
|
||||
for (i=0; i<=YDelta; i++)
|
||||
{
|
||||
ScreenPtr[0] = col1;
|
||||
ScreenPtr[1] = col2;
|
||||
ScreenPtr += giImageWidth;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (YDelta == 0)
|
||||
{
|
||||
/* Horizontal line */
|
||||
for (i=0; i<=XDelta; i++)
|
||||
{
|
||||
ScreenPtr[0] = col1;
|
||||
ScreenPtr[1] = col2;
|
||||
ScreenPtr += XAdvance*2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (XDelta == YDelta)
|
||||
{
|
||||
/* Diagonal line */
|
||||
for (i=0; i<=XDelta; i++)
|
||||
{
|
||||
ScreenPtr[0] = col1;
|
||||
ScreenPtr[1] = col2;
|
||||
ScreenPtr += (XAdvance*2) + giImageWidth;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Determine whether the line is X or Y major, and handle accordingly */
|
||||
if (XDelta >= YDelta)
|
||||
{
|
||||
/* X major line */
|
||||
/* Minimum # of pixels in a run in this line */
|
||||
WholeStep = XDelta / YDelta;
|
||||
|
||||
/* Error term adjust each time Y steps by 1; used to tell when one
|
||||
extra pixel should be drawn as part of a run, to account for
|
||||
fractional steps along the X axis per 1-pixel steps along Y */
|
||||
AdjUp = (XDelta % YDelta) * 2;
|
||||
|
||||
/* Error term adjust when the error term turns over, used to factor
|
||||
out the X step made at that time */
|
||||
AdjDown = YDelta * 2;
|
||||
|
||||
/* Initial error term; reflects an initial step of 0.5 along the Y
|
||||
axis */
|
||||
ErrorTerm = (XDelta % YDelta) - (YDelta * 2);
|
||||
|
||||
/* The initial and last runs are partial, because Y advances only 0.5
|
||||
for these runs, rather than 1. Divide one full run, plus the
|
||||
initial pixel, between the initial and last runs */
|
||||
InitialPixelCount = (WholeStep / 2) + 1;
|
||||
FinalPixelCount = InitialPixelCount;
|
||||
|
||||
/* If the basic run length is even and there's no fractional
|
||||
advance, we have one pixel that could go to either the initial
|
||||
or last partial run, which we'll arbitrarily allocate to the
|
||||
last run */
|
||||
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
|
||||
{
|
||||
InitialPixelCount--;
|
||||
}
|
||||
/* If there're an odd number of pixels per run, we have 1 pixel that can't
|
||||
be allocated to either the initial or last partial run, so we'll add 0.5
|
||||
to error term so this pixel will be handled by the normal full-run loop */
|
||||
if ((WholeStep & 0x01) != 0)
|
||||
{
|
||||
ErrorTerm += YDelta;
|
||||
}
|
||||
/* Draw the first, partial run of pixels */
|
||||
DrawHorizontalRun(&ScreenPtr, XAdvance, InitialPixelCount, Color, ScreenWidth);
|
||||
/* Draw all full runs */
|
||||
for (i=0; i<(YDelta-1); i++)
|
||||
{
|
||||
RunLength = WholeStep; /* run is at least this long */
|
||||
/* Advance the error term and add an extra pixel if the error
|
||||
term so indicates */
|
||||
if ((ErrorTerm += AdjUp) > 0)
|
||||
{
|
||||
RunLength++;
|
||||
ErrorTerm -= AdjDown; /* reset the error term */
|
||||
}
|
||||
/* Draw this scan line's run */
|
||||
DrawHorizontalRun(&ScreenPtr, XAdvance, RunLength, Color, ScreenWidth);
|
||||
}
|
||||
/* Draw the final run of pixels */
|
||||
DrawHorizontalRun(&ScreenPtr, XAdvance, FinalPixelCount, Color, ScreenWidth);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Y major line */
|
||||
|
||||
/* Minimum # of pixels in a run in this line */
|
||||
WholeStep = YDelta / XDelta;
|
||||
|
||||
/* Error term adjust each time X steps by 1; used to tell when 1 extra
|
||||
pixel should be drawn as part of a run, to account for
|
||||
fractional steps along the Y axis per 1-pixel steps along X */
|
||||
AdjUp = (YDelta % XDelta) * 2;
|
||||
|
||||
/* Error term adjust when the error term turns over, used to factor
|
||||
out the Y step made at that time */
|
||||
AdjDown = XDelta * 2;
|
||||
|
||||
/* Initial error term; reflects initial step of 0.5 along the X axis */
|
||||
ErrorTerm = (YDelta % XDelta) - (XDelta * 2);
|
||||
|
||||
/* The initial and last runs are partial, because X advances only 0.5
|
||||
for these runs, rather than 1. Divide one full run, plus the
|
||||
initial pixel, between the initial and last runs */
|
||||
InitialPixelCount = (WholeStep / 2) + 1;
|
||||
FinalPixelCount = InitialPixelCount;
|
||||
|
||||
/* If the basic run length is even and there's no fractional advance, we
|
||||
have 1 pixel that could go to either the initial or last partial run,
|
||||
which we'll arbitrarily allocate to the last run */
|
||||
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
|
||||
{
|
||||
InitialPixelCount--;
|
||||
}
|
||||
/* If there are an odd number of pixels per run, we have one pixel
|
||||
that can't be allocated to either the initial or last partial
|
||||
run, so we'll add 0.5 to the error term so this pixel will be
|
||||
handled by the normal full-run loop */
|
||||
if ((WholeStep & 0x01) != 0)
|
||||
{
|
||||
ErrorTerm += XDelta;
|
||||
}
|
||||
/* Draw the first, partial run of pixels */
|
||||
DrawVerticalRun(&ScreenPtr, XAdvance, InitialPixelCount, Color, ScreenWidth);
|
||||
|
||||
/* Draw all full runs */
|
||||
for (i=0; i<(XDelta-1); i++)
|
||||
{
|
||||
RunLength = WholeStep; /* run is at least this long */
|
||||
/* Advance the error term and add an extra pixel if the error
|
||||
term so indicates */
|
||||
if ((ErrorTerm += AdjUp) > 0)
|
||||
{
|
||||
RunLength++;
|
||||
ErrorTerm -= AdjDown; /* reset the error term */
|
||||
}
|
||||
/* Draw this scan line's run */
|
||||
DrawVerticalRun(&ScreenPtr, XAdvance, RunLength, Color, ScreenWidth);
|
||||
}
|
||||
/* Draw the final run of pixels */
|
||||
DrawVerticalRun(&ScreenPtr, XAdvance, FinalPixelCount, Color, ScreenWidth);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Draws a pixel in the specified color
|
||||
void PixelDraw( BOOLEAN fClip, INT32 xp, INT32 yp, INT16 sColor, UINT8 *pScreen )
|
||||
{
|
||||
if ( fClip && !ClipPoint( xp, yp ) )
|
||||
return;
|
||||
|
||||
// point to the bitmap address first pixel to draw
|
||||
pScreen += yp * giImageWidth + xp * 2;
|
||||
|
||||
INT8 col2 = sColor >> 8;
|
||||
INT8 col1 = sColor & 0x00ff;
|
||||
|
||||
pScreen[ 0 ] = col1;
|
||||
pScreen[ 1 ] = col2;
|
||||
}
|
||||
|
||||
// Flugente: alter the colour of existing pixels instead of fully replacing the colour
|
||||
void PixelAlterColour(BOOLEAN fClip, INT32 xp, INT32 yp, INT16 sColor, UINT8 *pScreen)
|
||||
{
|
||||
if ( fClip && !ClipPoint( xp, yp ) )
|
||||
return;
|
||||
|
||||
// point to the bitmap address first pixel to draw
|
||||
pScreen += yp * giImageWidth + xp * 2;
|
||||
|
||||
INT8 col2 = sColor >> 8;
|
||||
INT8 col1 = sColor & 0x00ff;
|
||||
|
||||
pScreen[0] |= col1;
|
||||
pScreen[1] |= col2;
|
||||
}
|
||||
|
||||
/* Draws a horizontal run of pixels, then advances the bitmap pointer to
|
||||
the first pixel of the next run. */
|
||||
void DrawHorizontalRun(UINT8 **ScreenPtr, int XAdvance,
|
||||
int RunLength, int Color, int ScreenWidth)
|
||||
{
|
||||
int i;
|
||||
UINT8 *WorkingScreenPtr = *ScreenPtr;
|
||||
UINT8 col2 = Color>>8;
|
||||
UINT8 col1 = Color & 0x00FF;
|
||||
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
WorkingScreenPtr[0] = col1;
|
||||
WorkingScreenPtr[1] = col2;
|
||||
WorkingScreenPtr += XAdvance*2;
|
||||
}
|
||||
/* Advance to the next scan line */
|
||||
WorkingScreenPtr += giImageWidth;
|
||||
*ScreenPtr = WorkingScreenPtr;
|
||||
}
|
||||
|
||||
/* Draws a vertical run of pixels, then advances the bitmap pointer to
|
||||
the first pixel of the next run. */
|
||||
void DrawVerticalRun(UINT8 **ScreenPtr, int XAdvance,
|
||||
int RunLength, int Color, int ScreenWidth)
|
||||
{
|
||||
int i;
|
||||
UINT8 *WorkingScreenPtr = *ScreenPtr;
|
||||
UINT8 col2 = Color>>8;
|
||||
UINT8 col1 = Color & 0x00FF;
|
||||
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
WorkingScreenPtr[0] = col1;
|
||||
WorkingScreenPtr[1] = col2;
|
||||
WorkingScreenPtr += giImageWidth;
|
||||
}
|
||||
/* Advance to the next column */
|
||||
WorkingScreenPtr += XAdvance*2;
|
||||
*ScreenPtr = WorkingScreenPtr;
|
||||
}
|
||||
|
||||
|
||||
/* Draws a rectangle between the specified endpoints in color Color. */
|
||||
void RectangleDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr)
|
||||
{
|
||||
LineDraw( fClip, XStart, YStart, XEnd, YStart, Color, ScreenPtr);
|
||||
LineDraw( fClip, XStart, YEnd, XEnd, YEnd, Color, ScreenPtr);
|
||||
LineDraw( fClip, XStart, YStart, XStart, YEnd, Color, ScreenPtr);
|
||||
LineDraw( fClip, XEnd, YStart, XEnd, YEnd, Color, ScreenPtr);
|
||||
}
|
||||
|
||||
/***********************************************************************************
|
||||
* 8-Bit Versions
|
||||
*
|
||||
*
|
||||
*
|
||||
* Added by Derek Beland
|
||||
***********************************************************************************/
|
||||
|
||||
/* Draws a rectangle between the specified endpoints in color Color. */
|
||||
void RectangleDraw8( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr)
|
||||
{
|
||||
LineDraw8( fClip, XStart, YStart, XEnd, YStart, Color, ScreenPtr);
|
||||
LineDraw8( fClip, XStart, YEnd, XEnd, YEnd, Color, ScreenPtr);
|
||||
LineDraw8( fClip, XStart, YStart, XStart, YEnd, Color, ScreenPtr);
|
||||
LineDraw8( fClip, XEnd, YStart, XEnd, YEnd, Color, ScreenPtr);
|
||||
}
|
||||
|
||||
/* Draws a line between the specified endpoints in color Color. */
|
||||
void LineDraw8( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr)
|
||||
{
|
||||
int Temp, AdjUp, AdjDown, ErrorTerm, XAdvance, XDelta, YDelta;
|
||||
int WholeStep, InitialPixelCount, FinalPixelCount, i, RunLength;
|
||||
int ScreenWidth = giImageWidth;
|
||||
UINT8 col1 = Color & 0x00FF;
|
||||
|
||||
if ( fClip )
|
||||
{
|
||||
if ( !Clip2D( &XStart, &YStart, &XEnd, &YEnd ) )
|
||||
return;
|
||||
}
|
||||
|
||||
/* We'll always draw top to bottom, to reduce the number of cases we have to
|
||||
handle, and to make lines between the same endpoints draw the same pixels */
|
||||
if (YStart > YEnd) {
|
||||
Temp = YStart;
|
||||
YStart = YEnd;
|
||||
YEnd = Temp;
|
||||
Temp = XStart;
|
||||
XStart = XEnd;
|
||||
XEnd = Temp;
|
||||
}
|
||||
|
||||
// point to the bitmap address first pixel to draw
|
||||
ScreenPtr = ScreenPtr + YStart*giImageWidth + XStart;
|
||||
|
||||
/* Figure out whether we're going left or right, and how far we're
|
||||
going horizontally */
|
||||
if ((XDelta = XEnd - XStart) < 0)
|
||||
{
|
||||
XAdvance = -1;
|
||||
XDelta = -XDelta;
|
||||
}
|
||||
else
|
||||
{
|
||||
XAdvance = 1;
|
||||
}
|
||||
/* Figure out how far we're going vertically */
|
||||
YDelta = YEnd - YStart;
|
||||
|
||||
/* Special-case horizontal, vertical, and diagonal lines, for speed
|
||||
and to avoid nasty boundary conditions and division by 0 */
|
||||
if (XDelta == 0)
|
||||
{
|
||||
/* Vertical line */
|
||||
for (i=0; i<=YDelta; i++)
|
||||
{
|
||||
*ScreenPtr = col1;
|
||||
ScreenPtr += giImageWidth;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (YDelta == 0)
|
||||
{
|
||||
/* Horizontal line */
|
||||
for (i=0; i<=XDelta; i++)
|
||||
{
|
||||
*ScreenPtr = col1;
|
||||
ScreenPtr += XAdvance;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (XDelta == YDelta)
|
||||
{
|
||||
/* Diagonal line */
|
||||
for (i=0; i<=XDelta; i++)
|
||||
{
|
||||
*ScreenPtr = col1;
|
||||
ScreenPtr += (XAdvance + giImageWidth);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Determine whether the line is X or Y major, and handle accordingly */
|
||||
if (XDelta >= YDelta)
|
||||
{
|
||||
/* X major line */
|
||||
/* Minimum # of pixels in a run in this line */
|
||||
WholeStep = XDelta / YDelta;
|
||||
|
||||
/* Error term adjust each time Y steps by 1; used to tell when one
|
||||
extra pixel should be drawn as part of a run, to account for
|
||||
fractional steps along the X axis per 1-pixel steps along Y */
|
||||
AdjUp = (XDelta % YDelta) * 2;
|
||||
|
||||
/* Error term adjust when the error term turns over, used to factor
|
||||
out the X step made at that time */
|
||||
AdjDown = YDelta * 2;
|
||||
|
||||
/* Initial error term; reflects an initial step of 0.5 along the Y
|
||||
axis */
|
||||
ErrorTerm = (XDelta % YDelta) - (YDelta * 2);
|
||||
|
||||
/* The initial and last runs are partial, because Y advances only 0.5
|
||||
for these runs, rather than 1. Divide one full run, plus the
|
||||
initial pixel, between the initial and last runs */
|
||||
InitialPixelCount = (WholeStep / 2) + 1;
|
||||
FinalPixelCount = InitialPixelCount;
|
||||
|
||||
/* If the basic run length is even and there's no fractional
|
||||
advance, we have one pixel that could go to either the initial
|
||||
or last partial run, which we'll arbitrarily allocate to the
|
||||
last run */
|
||||
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
|
||||
{
|
||||
InitialPixelCount--;
|
||||
}
|
||||
/* If there're an odd number of pixels per run, we have 1 pixel that can't
|
||||
be allocated to either the initial or last partial run, so we'll add 0.5
|
||||
to error term so this pixel will be handled by the normal full-run loop */
|
||||
if ((WholeStep & 0x01) != 0)
|
||||
{
|
||||
ErrorTerm += YDelta;
|
||||
}
|
||||
/* Draw the first, partial run of pixels */
|
||||
DrawHorizontalRun8(&ScreenPtr, XAdvance, InitialPixelCount, Color, ScreenWidth);
|
||||
/* Draw all full runs */
|
||||
for (i=0; i<(YDelta-1); i++)
|
||||
{
|
||||
RunLength = WholeStep; /* run is at least this long */
|
||||
/* Advance the error term and add an extra pixel if the error
|
||||
term so indicates */
|
||||
if ((ErrorTerm += AdjUp) > 0)
|
||||
{
|
||||
RunLength++;
|
||||
ErrorTerm -= AdjDown; /* reset the error term */
|
||||
}
|
||||
/* Draw this scan line's run */
|
||||
DrawHorizontalRun8(&ScreenPtr, XAdvance, RunLength, Color, ScreenWidth);
|
||||
}
|
||||
/* Draw the final run of pixels */
|
||||
DrawHorizontalRun8(&ScreenPtr, XAdvance, FinalPixelCount, Color, ScreenWidth);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Y major line */
|
||||
|
||||
/* Minimum # of pixels in a run in this line */
|
||||
WholeStep = YDelta / XDelta;
|
||||
|
||||
/* Error term adjust each time X steps by 1; used to tell when 1 extra
|
||||
pixel should be drawn as part of a run, to account for
|
||||
fractional steps along the Y axis per 1-pixel steps along X */
|
||||
AdjUp = (YDelta % XDelta) * 2;
|
||||
|
||||
/* Error term adjust when the error term turns over, used to factor
|
||||
out the Y step made at that time */
|
||||
AdjDown = XDelta * 2;
|
||||
|
||||
/* Initial error term; reflects initial step of 0.5 along the X axis */
|
||||
ErrorTerm = (YDelta % XDelta) - (XDelta * 2);
|
||||
|
||||
/* The initial and last runs are partial, because X advances only 0.5
|
||||
for these runs, rather than 1. Divide one full run, plus the
|
||||
initial pixel, between the initial and last runs */
|
||||
InitialPixelCount = (WholeStep / 2) + 1;
|
||||
FinalPixelCount = InitialPixelCount;
|
||||
|
||||
/* If the basic run length is even and there's no fractional advance, we
|
||||
have 1 pixel that could go to either the initial or last partial run,
|
||||
which we'll arbitrarily allocate to the last run */
|
||||
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
|
||||
{
|
||||
InitialPixelCount--;
|
||||
}
|
||||
/* If there are an odd number of pixels per run, we have one pixel
|
||||
that can't be allocated to either the initial or last partial
|
||||
run, so we'll add 0.5 to the error term so this pixel will be
|
||||
handled by the normal full-run loop */
|
||||
if ((WholeStep & 0x01) != 0)
|
||||
{
|
||||
ErrorTerm += XDelta;
|
||||
}
|
||||
/* Draw the first, partial run of pixels */
|
||||
DrawVerticalRun8(&ScreenPtr, XAdvance, InitialPixelCount, Color, ScreenWidth);
|
||||
|
||||
/* Draw all full runs */
|
||||
for (i=0; i<(XDelta-1); i++)
|
||||
{
|
||||
RunLength = WholeStep; /* run is at least this long */
|
||||
/* Advance the error term and add an extra pixel if the error
|
||||
term so indicates */
|
||||
if ((ErrorTerm += AdjUp) > 0)
|
||||
{
|
||||
RunLength++;
|
||||
ErrorTerm -= AdjDown; /* reset the error term */
|
||||
}
|
||||
/* Draw this scan line's run */
|
||||
DrawVerticalRun8(&ScreenPtr, XAdvance, RunLength, Color, ScreenWidth);
|
||||
}
|
||||
/* Draw the final run of pixels */
|
||||
DrawVerticalRun8(&ScreenPtr, XAdvance, FinalPixelCount, Color, ScreenWidth);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Draws a horizontal run of pixels, then advances the bitmap pointer to
|
||||
the first pixel of the next run. */
|
||||
void DrawHorizontalRun8(UINT8 **ScreenPtr, int XAdvance,
|
||||
int RunLength, int Color, int ScreenWidth)
|
||||
{
|
||||
int i;
|
||||
UINT8 *WorkingScreenPtr = *ScreenPtr;
|
||||
UINT8 col1 = Color & 0x00FF;
|
||||
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
*WorkingScreenPtr = col1;
|
||||
WorkingScreenPtr += XAdvance;
|
||||
}
|
||||
/* Advance to the next scan line */
|
||||
WorkingScreenPtr += giImageWidth;
|
||||
*ScreenPtr = WorkingScreenPtr;
|
||||
}
|
||||
|
||||
/* Draws a vertical run of pixels, then advances the bitmap pointer to
|
||||
the first pixel of the next run. */
|
||||
void DrawVerticalRun8(UINT8 **ScreenPtr, int XAdvance,
|
||||
int RunLength, int Color, int ScreenWidth)
|
||||
{
|
||||
int i;
|
||||
UINT8 *WorkingScreenPtr = *ScreenPtr;
|
||||
UINT8 col1 = Color & 0x00FF;
|
||||
|
||||
for (i=0; i<RunLength; i++)
|
||||
{
|
||||
*WorkingScreenPtr = col1;
|
||||
WorkingScreenPtr += giImageWidth;
|
||||
}
|
||||
/* Advance to the next column */
|
||||
WorkingScreenPtr += XAdvance;
|
||||
*ScreenPtr = WorkingScreenPtr;
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Filename : line.h
|
||||
//
|
||||
// Purpose :
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
#ifndef ___LINE___H
|
||||
#define ___LINE___H
|
||||
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
#include "sgp.h"
|
||||
#include "types.h"
|
||||
|
||||
//**************************************************************************
|
||||
//
|
||||
// Example Usage
|
||||
//
|
||||
//**************************************************************************
|
||||
|
||||
// // don't send pitch, send width in pixels
|
||||
// SetClippingRegionAndImageWidth( uiPitch, 15, 15, 30, 30 );
|
||||
//
|
||||
// LineDraw( TRUE, 10, 10, 200, 200, colour, pImageData);
|
||||
// OR
|
||||
// RectangleDraw( TRUE, 10, 10, 200, 200, colour, pImageData);
|
||||
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Prototypes
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
|
||||
// *****************************************************************************
|
||||
|
||||
void SetClippingRegionAndImageWidth(
|
||||
int iImageWidth,
|
||||
int iClipStartX, int iClipStartY,
|
||||
int iClipWidth, int iClipHeight );
|
||||
|
||||
// NOTE:
|
||||
// Don't send fClip==TRUE to LineDraw if you don't have to. So if you know
|
||||
// that your line will be within the region you want it to be in, set
|
||||
// fClip == FALSE.
|
||||
void PixelDraw( BOOLEAN fClip, INT32 xp, INT32 yp, INT16 sColor, UINT8 *pScreen );
|
||||
|
||||
// Flugente: alter the colour of existing pixels instead of fully replacing the colour
|
||||
void PixelAlterColour( BOOLEAN fClip, INT32 xp, INT32 yp, INT16 sColor, UINT8 *pScreen );
|
||||
|
||||
void LineDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr);
|
||||
void LineDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr);
|
||||
void LineDraw8( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr);
|
||||
void RectangleDraw( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr);
|
||||
void RectangleDraw8( BOOL fClip, int XStart, int YStart, int XEnd, int YEnd, short Color, UINT8 *ScreenPtr);
|
||||
|
||||
// *****************************************************************************
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
// EOF *************************************************************************
|
||||
+1885
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,278 @@
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Filename : MouseSystem.h
|
||||
//
|
||||
// Purpose : Defines and typedefs for the "mousesystem" mouse region handler
|
||||
//
|
||||
// Modification history :
|
||||
//
|
||||
// 30jan97:Bret ->Creation
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
#include "mousesystem_macros.h"
|
||||
|
||||
#ifndef _MOUSE_SYSTEM_H_
|
||||
#define _MOUSE_SYSTEM_H_
|
||||
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Typedefs
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
#define _JA2_RENDER_DIRTY // Undef this if not using the JA2 Dirty Rectangle System.
|
||||
|
||||
typedef void (*MOUSE_CALLBACK)(struct _MOUSE_REGION *,INT32); // Define MOUSE_CALLBACK type as pointer to void
|
||||
typedef void (*MOUSE_HELPTEXT_DONE_CALLBACK)( ); // the help is done callback
|
||||
|
||||
typedef struct _MOUSE_REGION {
|
||||
UINT16 IDNumber; // Region's ID number, set by mouse system
|
||||
INT8 PriorityLevel; // Region's Priority, set by system and/or caller
|
||||
UINT32 uiFlags; // Region's state flags
|
||||
INT16 RegionTopLeftX; // Screen area affected by this region (absolute coordinates)
|
||||
INT16 RegionTopLeftY;
|
||||
INT16 RegionBottomRightX;
|
||||
INT16 RegionBottomRightY;
|
||||
INT16 MouseXPos; // Mouse's Coordinates in absolute screen coordinates
|
||||
INT16 MouseYPos;
|
||||
INT16 RelativeXPos; // Mouse's Coordinates relative to the Top-Left corner of the region
|
||||
INT16 RelativeYPos;
|
||||
UINT16 ButtonState; // Current state of the mouse buttons
|
||||
INT16 WheelState; // Wheel state +/-number of wheel units
|
||||
UINT16 Cursor; // Cursor to use when mouse in this region (see flags)
|
||||
MOUSE_CALLBACK MovementCallback; // Pointer to callback function if movement occured in this region
|
||||
MOUSE_CALLBACK ButtonCallback; // Pointer to callback function if button action occured in this region
|
||||
INT32 UserData[4]; // User Data, can be set to anything!
|
||||
|
||||
//Fast help vars.
|
||||
INT16 FastHelpTimer; // Countdown timer for FastHelp text
|
||||
CHAR16 *FastHelpText; // Text string for the FastHelp (describes buttons if left there a while)
|
||||
INT32 FastHelpRect;
|
||||
MOUSE_HELPTEXT_DONE_CALLBACK HelpDoneCallback;
|
||||
|
||||
struct _MOUSE_REGION *next; // List maintenance, do NOT touch these entries
|
||||
struct _MOUSE_REGION *prev;
|
||||
} MOUSE_REGION;
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
// *****************************************************************************
|
||||
|
||||
// Mouse Region Flags
|
||||
#define MSYS_NO_FLAGS 0x00000000
|
||||
#define MSYS_MOUSE_IN_AREA 0x00000001
|
||||
#define MSYS_SET_CURSOR 0x00000002
|
||||
#define MSYS_MOVE_CALLBACK 0x00000004
|
||||
#define MSYS_BUTTON_CALLBACK 0x00000008
|
||||
#define MSYS_REGION_EXISTS 0x00000010
|
||||
#define MSYS_SYSTEM_INIT 0x00000020
|
||||
#define MSYS_REGION_ENABLED 0x00000040
|
||||
#define MSYS_FASTHELP 0x00000080
|
||||
#define MSYS_GOT_BACKGROUND 0x00000100
|
||||
#define MSYS_HAS_BACKRECT 0x00000200
|
||||
#define MSYS_FASTHELP_RESET 0x00000400
|
||||
#define MSYS_ALLOW_DISABLED_FASTHELP 0x00000800
|
||||
|
||||
// Mouse region IDs
|
||||
#define MSYS_ID_BASE 1
|
||||
#define MSYS_ID_MAX 0xfffffff // ( INT32 max )
|
||||
#define MSYS_ID_SYSTEM 0
|
||||
|
||||
// Mouse region priorities
|
||||
#define MSYS_PRIORITY_LOWEST 0
|
||||
#define MSYS_PRIORITY_LOW 15
|
||||
#define MSYS_PRIORITY_BASE 31
|
||||
#define MSYS_PRIORITY_NORMAL 31
|
||||
#define MSYS_PRIORITY_HIGH 63
|
||||
#define MSYS_PRIORITY_HIGHEST 127
|
||||
#define MSYS_PRIORITY_SYSTEM -1
|
||||
#define MSYS_PRIORITY_AUTO -1
|
||||
|
||||
// Mouse system defines used during updates
|
||||
#define MSYS_NO_ACTION 0
|
||||
#define MSYS_DO_MOVE 1
|
||||
#define MSYS_DO_LBUTTON_DWN 2
|
||||
#define MSYS_DO_LBUTTON_UP 4
|
||||
#define MSYS_DO_RBUTTON_DWN 8
|
||||
#define MSYS_DO_RBUTTON_UP 16
|
||||
#define MSYS_DO_LBUTTON_REPEAT 32
|
||||
#define MSYS_DO_RBUTTON_REPEAT 64
|
||||
#define MSYS_DO_MBUTTON_DWN 128
|
||||
#define MSYS_DO_MBUTTON_UP 256
|
||||
#define MSYS_DO_MBUTTON_REPEAT 512
|
||||
|
||||
#define MSYS_DO_X1BUTTON_DWN 1024
|
||||
#define MSYS_DO_X1BUTTON_UP 2048
|
||||
#define MSYS_DO_X1BUTTON_REPEAT 4096
|
||||
#define MSYS_DO_X2BUTTON_DWN 8192
|
||||
#define MSYS_DO_X2BUTTON_UP 16384
|
||||
#define MSYS_DO_X2BUTTON_REPEAT 32768
|
||||
|
||||
#define MSYS_DO_WHEEL_UP 65536
|
||||
#define MSYS_DO_WHEEL_DOWN 131072
|
||||
|
||||
#define MSYS_DO_BUTTONS (MSYS_DO_LBUTTON_DWN|MSYS_DO_LBUTTON_UP|MSYS_DO_LBUTTON_REPEAT|\
|
||||
MSYS_DO_RBUTTON_DWN|MSYS_DO_RBUTTON_UP|MSYS_DO_RBUTTON_REPEAT|\
|
||||
MSYS_DO_MBUTTON_DWN|MSYS_DO_MBUTTON_UP|MSYS_DO_MBUTTON_REPEAT|\
|
||||
MSYS_DO_X1BUTTON_DWN|MSYS_DO_X1BUTTON_UP|MSYS_DO_X1BUTTON_REPEAT|\
|
||||
MSYS_DO_X2BUTTON_DWN|MSYS_DO_X2BUTTON_UP|MSYS_DO_X2BUTTON_REPEAT)
|
||||
|
||||
#define MSYS_DO_WHEEL (MSYS_DO_WHEEL_UP|MSYS_DO_WHEEL_DOWN)
|
||||
//#define MSYS_DO_BUTTONS (MSYS_DO_LBUTTON_DWN|MSYS_DO_LBUTTON_UP|MSYS_DO_RBUTTON_DWN|MSYS_DO_RBUTTON_UP|MSYS_DO_RBUTTON_REPEAT|MSYS_DO_LBUTTON_REPEAT)
|
||||
|
||||
// Mouse system button masks
|
||||
#define MSYS_LEFT_BUTTON 1
|
||||
#define MSYS_RIGHT_BUTTON 2
|
||||
#define MSYS_MIDDLE_BUTTON 4
|
||||
#define MSYS_X1_BUTTON 8
|
||||
#define MSYS_X2_BUTTON 16
|
||||
|
||||
// Mouse system special values
|
||||
#define MSYS_NO_CALLBACK NULL
|
||||
#define MSYS_NO_CURSOR 65534
|
||||
|
||||
// Mouse system callback reasons
|
||||
#define MSYS_CALLBACK_REASON_NONE 0
|
||||
#define MSYS_CALLBACK_REASON_INIT 1
|
||||
#define MSYS_CALLBACK_REASON_MOVE 2
|
||||
#define MSYS_CALLBACK_REASON_LBUTTON_DWN 4
|
||||
#define MSYS_CALLBACK_REASON_LBUTTON_UP 8
|
||||
#define MSYS_CALLBACK_REASON_RBUTTON_DWN 16
|
||||
#define MSYS_CALLBACK_REASON_RBUTTON_UP 32
|
||||
//#define MSYS_CALLBACK_REASON_BUTTONS (MSYS_CALLBACK_REASON_LBUTTON_DWN|MSYS_CALLBACK_REASON_LBUTTON_UP| \
|
||||
// MSYS_CALLBACK_REASON_RBUTTON_DWN|MSYS_CALLBACK_REASON_RBUTTON_UP)
|
||||
#define MSYS_CALLBACK_REASON_LOST_MOUSE 64
|
||||
#define MSYS_CALLBACK_REASON_GAIN_MOUSE 128
|
||||
|
||||
#define MSYS_CALLBACK_REASON_LBUTTON_REPEAT 256
|
||||
#define MSYS_CALLBACK_REASON_RBUTTON_REPEAT 512
|
||||
|
||||
//Kris: Nov 31, 1999
|
||||
//Added support for double clicks. The DOUBLECLICK event is passed combined with
|
||||
//the LBUTTON_DWN event if two LBUTTON_DWN events are detected on the same button/region
|
||||
//within the delay defined by MSYS_DOUBLECLICK_DELAY (in milliseconds). If your button/region
|
||||
//supports double clicks and single clicks, make sure the DOUBLECLICK event is checked first (rejecting
|
||||
//the LBUTTON_DWN event if detected)
|
||||
#define MSYS_CALLBACK_REASON_LBUTTON_DOUBLECLICK 1024
|
||||
#define MSYS_CALLBACK_REASON_MBUTTON_DWN 2048
|
||||
#define MSYS_CALLBACK_REASON_MBUTTON_UP 4096
|
||||
#define MSYS_CALLBACK_REASON_MBUTTON_REPEAT 8192
|
||||
#define MSYS_CALLBACK_REASON_WHEEL_UP 16384
|
||||
#define MSYS_CALLBACK_REASON_WHEEL_DOWN 32768
|
||||
#define MSYS_CALLBACK_REASON_X1BUTTON_DWN 65536
|
||||
#define MSYS_CALLBACK_REASON_X1BUTTON_UP 131072
|
||||
#define MSYS_CALLBACK_REASON_X1BUTTON_REPEAT 262144
|
||||
#define MSYS_CALLBACK_REASON_X2BUTTON_DWN 524288
|
||||
#define MSYS_CALLBACK_REASON_X2BUTTON_UP 1048576
|
||||
#define MSYS_CALLBACK_REASON_X2BUTTON_REPEAT 2097152
|
||||
|
||||
|
||||
#define MSYS_CALLBACK_REASON_BUTTONS (MSYS_CALLBACK_REASON_LBUTTON_DWN|MSYS_CALLBACK_REASON_LBUTTON_UP| \
|
||||
MSYS_CALLBACK_REASON_RBUTTON_DWN|MSYS_CALLBACK_REASON_RBUTTON_UP| \
|
||||
MSYS_CALLBACK_REASON_MBUTTON_DWN|MSYS_CALLBACK_REASON_MBUTTON_UP|\
|
||||
MSYS_CALLBACK_REASON_X1BUTTON_DWN|MSYS_CALLBACK_REASON_X1BUTTON_UP|\
|
||||
MSYS_CALLBACK_REASON_X2BUTTON_DWN|MSYS_CALLBACK_REASON_X2BUTTON_UP)
|
||||
|
||||
#define MSYS_CALLBACK_REASON_WHEEL (MSYS_CALLBACK_REASON_WHEEL_UP|MSYS_CALLBACK_REASON_WHEEL_DOWN)
|
||||
|
||||
|
||||
// Mouse grabbing return codes
|
||||
#define MSYS_GRABBED_OK 0
|
||||
#define MSYS_ALREADY_GRABBED 1
|
||||
#define MSYS_REGION_NOT_IN_LIST 2
|
||||
|
||||
// *****************************************************************************
|
||||
//
|
||||
// Prototypes
|
||||
//
|
||||
// *****************************************************************************
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
// *****************************************************************************
|
||||
|
||||
|
||||
// Note:
|
||||
// The prototype for MSYS_SGP_Mouse_Handler_Hook() is defined in mousesystem_macros.h
|
||||
|
||||
// Internal Functions
|
||||
INT32 MSYS_GetNewID(void);
|
||||
void MSYS_TrashRegList(void);
|
||||
void MSYS_AddRegionToList(MOUSE_REGION *region);
|
||||
INT32 MSYS_RegionInList(MOUSE_REGION *region);
|
||||
void MSYS_DeleteRegionFromList(MOUSE_REGION *region);
|
||||
void MSYS_UpdateMouseRegion(void);
|
||||
void MSYS_SetCurrentCursor(UINT16 Cursor);
|
||||
|
||||
// External
|
||||
INT32 MSYS_Init(void);
|
||||
void MSYS_Shutdown(void);
|
||||
void MSYS_DefineRegion(MOUSE_REGION *region,UINT16 tlx,UINT16 tly,UINT16 brx,UINT16 bry,INT8 priority,
|
||||
UINT16 crsr,MOUSE_CALLBACK movecallback,MOUSE_CALLBACK buttoncallback);
|
||||
void MSYS_ChangeRegionCursor(MOUSE_REGION *region,UINT16 crsr);
|
||||
INT32 MSYS_AddRegion(MOUSE_REGION *region);
|
||||
void MSYS_RemoveRegion(MOUSE_REGION *region);
|
||||
void MSYS_EnableRegion(MOUSE_REGION *region);
|
||||
void MSYS_DisableRegion(MOUSE_REGION *region);
|
||||
void MSYS_ChangeRegionPriority(MOUSE_REGION *region,INT8 priority);
|
||||
void MSYS_SetRegionUserData(MOUSE_REGION *region,INT32 index,INT32 userdata);
|
||||
INT32 MSYS_GetRegionUserData(MOUSE_REGION *region,INT32 index);
|
||||
|
||||
INT32 MSYS_GrabMouse(MOUSE_REGION *region);
|
||||
void MSYS_ReleaseMouse(MOUSE_REGION *region);
|
||||
void MSYS_MoveMouseRegionBy( MOUSE_REGION *region, INT16 sDeltaX, INT16 sDeltaY);
|
||||
void MSYS_MoveMouseRegionTo( MOUSE_REGION *region, INT16 sX, INT16 sY);
|
||||
|
||||
void MSYS_AllowDisabledRegionFastHelp( MOUSE_REGION *region, BOOLEAN fAllow );
|
||||
|
||||
// arynn : render mouse regions
|
||||
// functions to help externalize mouse region data
|
||||
MOUSE_REGION *get_first_entry_in_MSYS_RegList(void); //list iteration initialize
|
||||
MOUSE_REGION *get_next_entry_in_MSYS_RegList(MOUSE_REGION *current_region); //list iteration increment
|
||||
|
||||
// This function will force a re-evaluation of mous regions
|
||||
// Usually used to force change of mouse cursor if panels switch, etc
|
||||
void RefreshMouseRegions( );
|
||||
|
||||
void SetRegionFastHelpText( MOUSE_REGION *region, const STR16 szText );
|
||||
|
||||
void SetRegionHelpEndCallback( MOUSE_REGION *region, MOUSE_HELPTEXT_DONE_CALLBACK CallbackFxn );
|
||||
|
||||
// Now also used by Wizardry -- DB
|
||||
void DisplayFastHelp( MOUSE_REGION *region );
|
||||
void RenderFastHelp();
|
||||
|
||||
void SetFastHelpDelay( INT16 sFastHelpDelay );
|
||||
void EnableMouseFastHelp( void );
|
||||
void DisableMouseFastHelp( void );
|
||||
|
||||
void ResetClickedMode(void);
|
||||
void ResetWheelState( MOUSE_REGION *region );
|
||||
#ifdef _JA2_RENDER_DIRTY
|
||||
|
||||
BOOLEAN SetRegionSavedRect( MOUSE_REGION *region);
|
||||
void FreeRegionSavedRect( MOUSE_REGION *region );
|
||||
|
||||
#endif
|
||||
|
||||
// *****************************************************************************
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
|
||||
// EOF *************************************************************************
|
||||
@@ -0,0 +1,40 @@
|
||||
//=================================================================================================
|
||||
// MouseSystem_Macros.h
|
||||
//
|
||||
// Macro definitions for the "mousesystem" mouse region handler.
|
||||
//
|
||||
// This file is included by "mousesystem.h" or can be included by itself.
|
||||
//
|
||||
// Written by Bret Rowdon. Jan 30 '97
|
||||
//=================================================================================================
|
||||
|
||||
#ifndef _MOUSE_SYSTEM_MACROS_H_
|
||||
#define _MOUSE_SYSTEM_MACROS_H_
|
||||
|
||||
// Special macro hook for the mouse handler. Allows a call to a secondary mouse handler.
|
||||
// Define the label _MOUSE_SYSTEM_HOOK_ to activate. Undef it to deactivate.
|
||||
//
|
||||
// The actual function prototype is shown below
|
||||
|
||||
#define _MOUSE_SYSTEM_HOOK_
|
||||
|
||||
#ifdef _MOUSE_SYSTEM_HOOK_
|
||||
#define MouseSystemHook(t,x,y,l,r) MSYS_SGP_Mouse_Handler_Hook(t,x,y,l,r)
|
||||
#else
|
||||
#define MouseSystemHook(t,x,y,l,r)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Special prototype for mouse handler hook
|
||||
extern void MSYS_SGP_Mouse_Handler_Hook(UINT16 Type, UINT16 Xcoord, UINT16 Ycoord, BOOLEAN LeftButton, BOOLEAN RightButton);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef __PCX_
|
||||
#define __PCX_
|
||||
|
||||
#include "types.h"
|
||||
#include "himage.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 ubManufacturer;
|
||||
UINT8 ubVersion;
|
||||
UINT8 ubEncoding;
|
||||
UINT8 ubBitsPerPixel;
|
||||
UINT16 usLeft, usTop;
|
||||
UINT16 usRight, usBottom;
|
||||
UINT16 usHorRez, usVerRez;
|
||||
UINT8 ubEgaPalette[48];
|
||||
UINT8 ubReserved;
|
||||
UINT8 ubColorPlanes;
|
||||
UINT16 usBytesPerLine;
|
||||
UINT16 usPaletteType;
|
||||
UINT8 ubFiller[58];
|
||||
|
||||
} PcxHeader;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 *pPcxBuffer;
|
||||
UINT8 ubPalette[768];
|
||||
UINT16 usWidth, usHeight;
|
||||
UINT32 uiBufferSize;
|
||||
UINT16 usPcxFlags;
|
||||
|
||||
} PcxObject;
|
||||
|
||||
BOOLEAN LoadPCXFileToImage( HIMAGE hImage, UINT16 fContents );
|
||||
PcxObject *LoadPcx(STR8 pFilename);
|
||||
BOOLEAN BlitPcxToBuffer( PcxObject *pCurrentPcxObject, UINT8 *pBuffer, UINT16 usBufferWidth, UINT16 usBufferHeight, UINT16 usX, UINT16 usY, BOOLEAN fTransp);
|
||||
|
||||
#endif
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
// __RAD16__ means 16 bit code (Win16)
|
||||
// __RAD32__ means 32 bit code (DOS, Win386, Win32s, Mac)
|
||||
|
||||
// __RADDOS__ means DOS code (16 or 32 bit)
|
||||
// __RADWIN__ means Windows code (Win16, Win386, Win32s)
|
||||
// __RADWINEXT__ means Windows 386 extender (Win386)
|
||||
// __RADNT__ means Win32s code
|
||||
// __RADMAC__ means Macintosh
|
||||
// __RADXBOX__ means the XBox console
|
||||
// __RADNGC__ means the Nintendo GameCube
|
||||
|
||||
// __RADX86__ means Intel x86
|
||||
// __RADMMX__ means Intel x86 MMX instructions are allowed
|
||||
// __RAD68K__ means 68K
|
||||
// __RADPPC__ means PowerPC
|
||||
|
||||
// __RADLITTLEENDIAN__ means processor is little-endian (x86)
|
||||
// __RADBIGENDIAN__ means processor is big-endian (680x0, PPC)
|
||||
|
||||
#ifndef __RADBASEH__
|
||||
#define __RADBASEH__
|
||||
|
||||
#if defined(GEKKO)
|
||||
|
||||
#define __RADNGC__
|
||||
#define __RAD32__
|
||||
#define __RADPPC__
|
||||
#define __RADBIGENDIAN__
|
||||
#define RADINLINE inline
|
||||
|
||||
#elif (defined(__MWERKS__) && !defined(__INTEL__)) || defined(__MRC__) || defined(THINK_C) || defined(powerc) || defined(macintosh) || defined(__powerc)
|
||||
|
||||
#define __RADMAC__
|
||||
#if defined(powerc) || defined(__powerc)
|
||||
#define __RADPPC__
|
||||
#else
|
||||
#define __RAD68K__
|
||||
#endif
|
||||
|
||||
#define __RAD32__
|
||||
#define __RADBIGENDIAN__
|
||||
|
||||
#if defined(__MWERKS__)
|
||||
#if (defined(__cplusplus) || ! __option(only_std_keywords))
|
||||
#define RADINLINE inline
|
||||
#endif
|
||||
#elif defined(__MRC__)
|
||||
#if defined(__cplusplus)
|
||||
#define RADINLINE inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define __RADX86__
|
||||
#define __RADMMX__
|
||||
|
||||
#ifdef __MWERKS__
|
||||
#define _WIN32
|
||||
#endif
|
||||
|
||||
#ifdef __DOS__
|
||||
#define __RADDOS__
|
||||
#endif
|
||||
|
||||
#ifdef __386__
|
||||
#define __RAD32__
|
||||
#endif
|
||||
|
||||
#ifdef _Windows //For Borland
|
||||
#ifdef __WIN32__
|
||||
#define WIN32
|
||||
#else
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WINDOWS //For MS
|
||||
#ifndef _WIN32
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef _XBOX
|
||||
#define __RADXBOX__
|
||||
#else
|
||||
#define __RADNT__
|
||||
#endif
|
||||
#define __RADWIN__
|
||||
#define __RAD32__
|
||||
#else
|
||||
#ifdef __NT__
|
||||
#ifdef _XBOX
|
||||
#define __RADXBOX__
|
||||
#else
|
||||
#define __RADNT__
|
||||
#endif
|
||||
#define __RADWIN__
|
||||
#define __RAD32__
|
||||
#else
|
||||
#ifdef __WINDOWS_386__
|
||||
#define __RADWIN__
|
||||
#define __RADWINEXT__
|
||||
#define __RAD32__
|
||||
#else
|
||||
#ifdef __WINDOWS__
|
||||
#define __RADWIN__
|
||||
#define __RAD16__
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#ifdef _XBOX
|
||||
#define __RADXBOX__
|
||||
#else
|
||||
#define __RADNT__
|
||||
#endif
|
||||
#define __RADWIN__
|
||||
#define __RAD32__
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define __RADLITTLEENDIAN__
|
||||
#define RADINLINE __inline
|
||||
#endif
|
||||
|
||||
#if (!defined(__RADDOS__) && !defined(__RADWIN__) && !defined(__RADMAC__) && !defined(__RADNGC__) && !defined(__RADXBOX__))
|
||||
#error "RAD.H did not detect your platform. Define __DOS__, __WINDOWS__, WIN32, macintosh, or powerc."
|
||||
#endif
|
||||
|
||||
#ifdef __RADFINAL__
|
||||
#define RADTODO(str) { char __str[0]=str; }
|
||||
#else
|
||||
#define RADTODO(str)
|
||||
#endif
|
||||
|
||||
#ifdef __RADNGC__
|
||||
|
||||
#define RADLINK
|
||||
#define RADEXPLINK
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#define RADASMLINK
|
||||
#define PTR4
|
||||
|
||||
#elif defined(__RADMAC__)
|
||||
|
||||
// this define is for CodeWarrior 11's stupid new libs (even though
|
||||
// we don't use longlong's).
|
||||
|
||||
#define __MSL_LONGLONG_SUPPORT__
|
||||
|
||||
#define RADLINK
|
||||
#define RADEXPLINK
|
||||
|
||||
#ifdef __CFM68K__
|
||||
#ifdef __RADINDLL__
|
||||
#define RADEXPFUNC RADDEFFUNC __declspec(export)
|
||||
#else
|
||||
#define RADEXPFUNC RADDEFFUNC __declspec(import)
|
||||
#endif
|
||||
#else
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
#define RADASMLINK
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __RADNT__
|
||||
#ifndef _WIN32
|
||||
#define _WIN32
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
#define WIN32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __RADWIN__
|
||||
#ifdef __RAD32__
|
||||
#ifdef __RADXBOX__
|
||||
|
||||
#define RADLINK __stdcall
|
||||
#define RADEXPLINK __stdcall
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
|
||||
#else
|
||||
#ifdef __RADNT__
|
||||
|
||||
#define RADLINK __stdcall
|
||||
#define RADEXPLINK __stdcall
|
||||
|
||||
#ifdef __RADINEXE__
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#else
|
||||
#ifndef __RADINDLL__
|
||||
#define RADEXPFUNC RADDEFFUNC __declspec(dllimport)
|
||||
#ifdef __BORLANDC__
|
||||
#if __BORLANDC__<=0x460
|
||||
#undef RADEXPFUNC
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define RADEXPFUNC RADDEFFUNC __declspec(dllexport)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define RADLINK __pascal
|
||||
#define RADEXPLINK __far __pascal
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define RADLINK __pascal
|
||||
#define RADEXPLINK __far __pascal __export
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
#else
|
||||
#define RADLINK __pascal
|
||||
#define RADEXPLINK __pascal
|
||||
#define RADEXPFUNC RADDEFFUNC
|
||||
#endif
|
||||
|
||||
#define RADASMLINK __cdecl
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __RADXBOX__
|
||||
#ifdef __RADWIN__
|
||||
#ifndef _WINDOWS
|
||||
#define _WINDOWS
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RADDEFFUNC
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define RADDEFFUNC extern "C"
|
||||
#define RADDEFSTART extern "C" {
|
||||
#define RADDEFEND }
|
||||
#define RADDEFINEDATA extern "C"
|
||||
#define RADDECLAREDATA extern "C"
|
||||
#define RADDEFAULT( val ) =val
|
||||
#else
|
||||
#define RADDEFFUNC
|
||||
#define RADDEFSTART
|
||||
#define RADDEFEND
|
||||
#define RADDEFINEDATA
|
||||
#define RADDECLAREDATA extern
|
||||
#define RADDEFAULT( val )
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __RADNGC__
|
||||
#define RAD_ATTRIBUTE_ALIGN(num) __attribute__ ((aligned (num)))
|
||||
#else
|
||||
#ifdef __RADX86__
|
||||
#define RAD_ATTRIBUTE_ALIGN(num) __declspec(align(num))
|
||||
#else
|
||||
#define RAD_ATTRIBUTE_ALIGN(num)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __RADX86__
|
||||
#ifdef __WATCOMC__
|
||||
#define RAD_ALIGN_TYPE double
|
||||
#define RAD_ALIGN_DEF 0.0
|
||||
#else
|
||||
#define RAD_ALIGN_TYPE double __declspec(align(8))
|
||||
#define RAD_ALIGN_DEF 0.0
|
||||
#endif
|
||||
#else
|
||||
#define RAD_ALIGN_TYPE double
|
||||
#define RAD_ALIGN_DEF 0.0
|
||||
#endif
|
||||
|
||||
#define RAD_ALIGN_ADD_TYPE(var) RAD_ALIGN_TYPE var##align = RAD_ALIGN_DEF
|
||||
|
||||
#define S8 signed char
|
||||
#define U8 unsigned char
|
||||
#define U32 unsigned long
|
||||
#define S32 signed long
|
||||
#define F32 float
|
||||
#define F64 double
|
||||
|
||||
#if defined(__MWERKS__) || defined(__MRC__) || defined( GEKKO )
|
||||
#define U64 unsigned long long
|
||||
#define S64 signed long long
|
||||
#else
|
||||
#define U64 unsigned __int64
|
||||
#define S64 signed __int64
|
||||
#endif
|
||||
|
||||
#ifdef __RAD32__
|
||||
#define PTR4
|
||||
#define U16 unsigned short
|
||||
#define S16 signed short
|
||||
#else
|
||||
#define PTR4 __far
|
||||
#define U16 unsigned int
|
||||
#define S16 signed int
|
||||
#endif
|
||||
|
||||
#ifndef RAD_NO_LOWERCASE_TYPES
|
||||
|
||||
#ifdef __RADNGC__
|
||||
|
||||
// Unfortunately dolphin\types.h typedefs the
|
||||
// same types that we use.
|
||||
// So we use the typedefs for this platform.
|
||||
|
||||
#include <dolphin\types.h>
|
||||
|
||||
#else
|
||||
|
||||
#ifndef u8
|
||||
#define u8 U8
|
||||
#endif
|
||||
#ifndef s8
|
||||
#define s8 S8
|
||||
#endif
|
||||
#ifndef u16
|
||||
#define u16 U16
|
||||
#endif
|
||||
#ifndef s16
|
||||
#define s16 S16
|
||||
#endif
|
||||
#ifndef u32
|
||||
#define u32 U32
|
||||
#endif
|
||||
#ifndef s32
|
||||
#define s32 S32
|
||||
#endif
|
||||
#ifndef u64
|
||||
#define u64 U64
|
||||
#endif
|
||||
#ifndef s64
|
||||
#define s64 S64
|
||||
#endif
|
||||
#ifndef f32
|
||||
#define f32 F32
|
||||
#endif
|
||||
#ifndef f64
|
||||
#define f64 F64
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef radassert
|
||||
#if defined(_DEBUG) && !defined(NDEBUG)
|
||||
#ifdef __RADNGC__
|
||||
#define radassert( cond ) { if (!(cond)) { OSReport("Assert: %s File: %s Line %i\n",#cond,__FILE__, __LINE__); BreakPoint(); } }
|
||||
#else
|
||||
#define radassert( cond ) { if (!(cond)) BreakPoint(); }
|
||||
#endif
|
||||
#else
|
||||
#define radassert( cond )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef void PTR4* (RADLINK PTR4* RADMEMALLOC) (U32 bytes);
|
||||
typedef void (RADLINK PTR4* RADMEMFREE) (void PTR4* ptr);
|
||||
|
||||
#endif
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
#ifndef __RANDOM_
|
||||
#define __RANDOM_
|
||||
|
||||
#define BMP_RANDOM
|
||||
|
||||
#include "Types.h"
|
||||
#include "Debug.h"
|
||||
#include "GameSettings.h"
|
||||
|
||||
//IMPORTANT: Changing this define will invalidate the JA2 save. If this is necessary, please ifdef your own value.
|
||||
#define MAX_PREGENERATED_NUMS 256
|
||||
|
||||
|
||||
#ifdef BMP_RANDOM//dnl ch55 111009 !!!Do not undefine this if plan play Big maps, old random generator not work properly and return only 2^15 different values although seems that should return all posible INT32 values
|
||||
|
||||
extern UINT32 guiPreRandomIndex;
|
||||
extern UINT32 guiPreRandomNums[MAX_PREGENERATED_NUMS];
|
||||
extern void InitializeRandom(void);
|
||||
extern UINT32 GetRndNum(UINT32 maxnum);
|
||||
extern bool gfMPDebugOutputRandoms;
|
||||
|
||||
UINT32 NewRandom(UINT32 max);
|
||||
|
||||
extern GAME_EXTERNAL_OPTIONS gGameExternalOptions;
|
||||
|
||||
inline UINT32 Random(UINT32 uiRange)
|
||||
{
|
||||
if (gGameExternalOptions.fNewRandom)
|
||||
return NewRandom(uiRange);
|
||||
else
|
||||
return GetRndNum(uiRange);
|
||||
}
|
||||
|
||||
/*inline INT32 iRandom(UINT32 uiRange)
|
||||
{
|
||||
return(GetRndNum(uiRange));
|
||||
}*/
|
||||
|
||||
inline BOOLEAN Chance( UINT32 uiChance )
|
||||
{
|
||||
return((BOOLEAN)(Random(100) < uiChance));
|
||||
}
|
||||
|
||||
inline UINT32 PreRandom(UINT32 uiRange)
|
||||
{
|
||||
return Random(uiRange);
|
||||
//return(GetRndNum(uiRange));
|
||||
}
|
||||
|
||||
inline BOOLEAN PreChance( UINT32 uiChance )
|
||||
{
|
||||
return((BOOLEAN)(PreRandom(100) < uiChance));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
extern UINT32 guiPreRandomIndex;
|
||||
extern std::vector<UINT32> guiPreRandomNums;
|
||||
|
||||
extern void InitializeRandom(void);
|
||||
|
||||
|
||||
// WDS 04/20/2009 -- Random functions were moved to inline functions here in the header file
|
||||
// to speed up the whole program a bit.
|
||||
|
||||
|
||||
// Returns a pseudo-random unsigned integer between 0 and uiRange-1 inclusive.
|
||||
// NOTE THE -1! So if you call Random(100) the numbers returned will
|
||||
// be between 0 and 99 inclusive.
|
||||
inline UINT32 Random(UINT32 uiRange)
|
||||
{
|
||||
// Always return 0, if no range given (it's not an error)
|
||||
if (uiRange == 0)
|
||||
return(0);
|
||||
return rand() * uiRange / RAND_MAX % uiRange;
|
||||
}
|
||||
|
||||
|
||||
// Returns a pseudo-random integer between 0 and uiRange-1
|
||||
/*inline INT32 iRandom(UINT32 uiRange)
|
||||
{
|
||||
// Always return 0, if no range given (it's not an error)
|
||||
if (uiRange == 0)
|
||||
return(0);
|
||||
return rand() * uiRange / RAND_MAX % uiRange;
|
||||
}*/
|
||||
|
||||
|
||||
//Chance( 74 ) returns TRUE 74% of the time. If uiChance >= 100, then it will always return TRUE.
|
||||
inline BOOLEAN Chance( UINT32 uiChance )
|
||||
{
|
||||
//AssertLE(uiChance, 100);
|
||||
// lalien: since uiChance calculation is based on different values it can happen that uiChance is > than 100%
|
||||
// It's not critical because uiChance >= 100 will always return TRUE. No need to crash the entire game.
|
||||
// Make sure that uiChance value is not < than 0, or it can switch to positive
|
||||
return (BOOLEAN)(Random( 100 ) < uiChance);
|
||||
}
|
||||
|
||||
|
||||
//Returns a pregenerated random number.
|
||||
//Used to deter Ian's tactic of shoot, miss, restore saved game :)
|
||||
inline UINT32 PreRandom( UINT32 uiRange )
|
||||
{
|
||||
UINT32 uiNum;
|
||||
if( uiRange == 0 )
|
||||
return 0;
|
||||
//Extract the current pregenerated number
|
||||
uiNum = guiPreRandomNums[ guiPreRandomIndex ] * uiRange / RAND_MAX % uiRange;
|
||||
|
||||
//Go to the next index.
|
||||
guiPreRandomIndex++;
|
||||
|
||||
// Reload the random numbers even so often
|
||||
if (guiPreRandomIndex == MAX_PREGENERATED_NUMS / 2) {
|
||||
// [0..(MAX_PREGENERATED_NUMS/2) -1]
|
||||
for( unsigned idx = 0; idx < MAX_PREGENERATED_NUMS / 2; ++idx ) {
|
||||
guiPreRandomNums[ idx ] = rand();
|
||||
}
|
||||
} else if (guiPreRandomIndex >= (UINT32)MAX_PREGENERATED_NUMS ) {
|
||||
// [MAX_PREGENERATED_NUMS/2 .. MAX_PREGENERATED_NUMS-1]
|
||||
for( unsigned idx = MAX_PREGENERATED_NUMS / 2; idx < MAX_PREGENERATED_NUMS; ++idx ) {
|
||||
guiPreRandomNums[ idx ] = rand();
|
||||
}
|
||||
guiPreRandomIndex = 0;
|
||||
}
|
||||
return uiNum;
|
||||
}
|
||||
|
||||
inline BOOLEAN PreChance( UINT32 uiChance )
|
||||
{
|
||||
//AssertLE(uiChance, 100);
|
||||
// lalien: since uiChance calculation is based on different values it can happen that uiChance is > than 100%
|
||||
// It's not critical because uiChance >= 100 will always return TRUE. No need to crash the entire game.
|
||||
// Make sure that uiChance value is not < than 0, or it can switch to positive
|
||||
|
||||
return (BOOLEAN)(PreRandom( 100 ) < uiChance);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+1463
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
#ifndef __SGP_
|
||||
#define __SGP_
|
||||
|
||||
#include "local.h"
|
||||
#include "types.h"
|
||||
#include "timer.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "video.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern BOOLEAN gfProgramIsRunning; // Turn this to FALSE to exit program
|
||||
extern CHAR8 gzCommandLine[100]; // Command line given
|
||||
extern UINT8 gbPixelDepth; // GLOBAL RUN-TIME SETTINGS
|
||||
extern BOOLEAN gfDontUseDDBlits; // GLOBAL FOR USE OF DD BLITTING
|
||||
|
||||
|
||||
// function prototypes
|
||||
void SGPExit(void);
|
||||
void ShutdownWithErrorBox(CHAR8 *pcMessage);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
#ifndef _SGP_AUTO_MEMORY_H_
|
||||
#define _SGP_AUTO_MEMORY_H_
|
||||
|
||||
namespace sgp
|
||||
{
|
||||
/************************************************************/
|
||||
|
||||
template<typename T>
|
||||
class TAutoArray
|
||||
{
|
||||
public:
|
||||
T& operator[](size_t index)
|
||||
{
|
||||
return _array[index];
|
||||
}
|
||||
|
||||
T* operator()()
|
||||
{
|
||||
return _array;
|
||||
}
|
||||
T* operator->()
|
||||
{
|
||||
return _array;
|
||||
}
|
||||
T& operator*()
|
||||
{
|
||||
return *_array;
|
||||
}
|
||||
bool operator!()
|
||||
{
|
||||
// NULL == _array
|
||||
return !_array;
|
||||
}
|
||||
|
||||
T* release()
|
||||
{
|
||||
T* tmp = _array;
|
||||
_array = NULL;
|
||||
return tmp;
|
||||
}
|
||||
protected:
|
||||
T* _array;
|
||||
};
|
||||
|
||||
/************************************************************/
|
||||
|
||||
template<typename T>
|
||||
class AutoArray : public TAutoArray<T>
|
||||
{
|
||||
public:
|
||||
AutoArray(size_t size)
|
||||
{
|
||||
_array = new T[size];
|
||||
}
|
||||
~AutoArray()
|
||||
{
|
||||
if(_array)
|
||||
{
|
||||
delete[] _array;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/************************************************************/
|
||||
|
||||
template<typename T, typename void*(*Alloc)(size_t) = malloc, typename void(*Dealloc)(void*) = free>
|
||||
class AutoCArray : public TAutoArray<T>
|
||||
{
|
||||
public:
|
||||
AutoCArray(size_t size = 1, size_t sizeof_elem=1)
|
||||
{
|
||||
_array = (T*)Alloc( size * sizeof_elem );
|
||||
}
|
||||
~AutoCArray()
|
||||
{
|
||||
if(_array)
|
||||
{
|
||||
Dealloc(_array);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/************************************************************/
|
||||
|
||||
} // namespace sgp
|
||||
|
||||
|
||||
#include "MemMan.h"
|
||||
|
||||
namespace sgp
|
||||
{
|
||||
template<typename T>
|
||||
class AutoMMArray : public sgp::TAutoArray<T>
|
||||
{
|
||||
public:
|
||||
AutoMMArray(size_t size, size_t sizeof_elem=1)
|
||||
{
|
||||
_array = (T*)MemAlloc( size * sizeof_elem );
|
||||
}
|
||||
~AutoMMArray()
|
||||
{
|
||||
if(_array)
|
||||
{
|
||||
MemFree(_array);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // _SGP_AUTO_MEMORY_H_
|
||||
@@ -0,0 +1,236 @@
|
||||
#include "sgp_logger.h"
|
||||
#include "Debug.h"
|
||||
#include "Font Control.h"
|
||||
|
||||
#include "Message.h"
|
||||
#include <iostream>
|
||||
|
||||
static inline void flush_screen(std::wstringstream& stream)
|
||||
{
|
||||
std::wstring str = stream.str();
|
||||
if(!str.empty())
|
||||
{
|
||||
ScreenMsg(MSG_FONT_YELLOW, 255, (STR16)str.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
int sgp::Logger::_next_log_id = -1;
|
||||
|
||||
//std::vector<sgp::Logger::STimeLog> sgp::Logger::_logs;
|
||||
std::vector<sgp::Logger::LogData> sgp::Logger::_logs;
|
||||
|
||||
sgp::Logger::Logger()
|
||||
{
|
||||
connectFile(this->createLogger(), L"game_log.log", false, sgp::Logger::FLUSH_ON_ENDL);
|
||||
}
|
||||
|
||||
sgp::Logger::~Logger()
|
||||
{
|
||||
}
|
||||
|
||||
sgp::Logger& sgp::Logger::instance()
|
||||
{
|
||||
static Logger _logger;
|
||||
return _logger;
|
||||
}
|
||||
|
||||
bool sgp::Logger::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sgp::Logger::shutdown()
|
||||
{
|
||||
for(::size_t i=0; i < _logs.size(); ++i)
|
||||
{
|
||||
disconnectFile(i);
|
||||
disconnectStream(i);
|
||||
disconnectScreen(i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
sgp::Logger_ID sgp::Logger::createLogger()
|
||||
{
|
||||
_logs.push_back(sgp::Logger::LogData());
|
||||
Logger_ID id = _logs.size() - 1;
|
||||
_logs[id].timer.startTimer();
|
||||
return id;
|
||||
}
|
||||
|
||||
sgp::Logger::FlushMode sgp::Logger::flushMode(sgp::Logger_ID id)
|
||||
{
|
||||
sgp::Logger::FlushMode fmode = (sgp::Logger::FlushMode)-1;
|
||||
if(id >= 0 && id < _logs.size())
|
||||
{
|
||||
if(_logs[id].file)
|
||||
{
|
||||
vfs::Log::EFlushMode fm = _logs[id].file->flushMode();
|
||||
|
||||
if (fm == vfs::Log::FLUSH_ON_DELETE) fmode = sgp::Logger::FLUSH_ON_DELETE;
|
||||
else if(fm == vfs::Log::FLUSH_IMMEDIATELY) fmode = sgp::Logger::FLUSH_IMMIDIATELY;
|
||||
else if(fm == vfs::Log::FLUSH_BUFFER) fmode = sgp::Logger::FLUSH_FULL_BUFFER;
|
||||
else if(fm == vfs::Log::FLUSH_ON_ENDL) fmode = sgp::Logger::FLUSH_ON_ENDL;
|
||||
}
|
||||
}
|
||||
return fmode;
|
||||
}
|
||||
|
||||
void sgp::Logger::flushMode(sgp::Logger_ID id, sgp::Logger::FlushMode fmode)
|
||||
{
|
||||
if(id >= 0 && id < _logs.size())
|
||||
{
|
||||
vfs::Log::EFlushMode fm;
|
||||
if (fmode == sgp::Logger::FLUSH_ON_DELETE) fm = vfs::Log::FLUSH_ON_DELETE;
|
||||
else if(fmode == sgp::Logger::FLUSH_IMMIDIATELY) fm = vfs::Log::FLUSH_IMMEDIATELY;
|
||||
else if(fmode == sgp::Logger::FLUSH_FULL_BUFFER) fm = vfs::Log::FLUSH_BUFFER;
|
||||
else if(fmode == sgp::Logger::FLUSH_ON_ENDL) fm = vfs::Log::FLUSH_ON_ENDL;
|
||||
else fm = vfs::Log::FLUSH_IMMEDIATELY;
|
||||
|
||||
if(_logs[id].file)
|
||||
{
|
||||
_logs[id].file->releaseFile();
|
||||
_logs[id].file->flushMode(fm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void sgp::Logger::connectFile(sgp::Logger_ID id, vfs::Path const& log_file, bool append, FlushMode fmode)
|
||||
{
|
||||
if(id >= 0 && id < _logs.size())
|
||||
{
|
||||
vfs::Log::EFlushMode fm;
|
||||
if (fmode == sgp::Logger::FLUSH_ON_DELETE) fm = vfs::Log::FLUSH_ON_DELETE;
|
||||
else if(fmode == sgp::Logger::FLUSH_IMMIDIATELY) fm = vfs::Log::FLUSH_IMMEDIATELY;
|
||||
else if(fmode == sgp::Logger::FLUSH_FULL_BUFFER) fm = vfs::Log::FLUSH_BUFFER;
|
||||
else if(fmode == sgp::Logger::FLUSH_ON_ENDL) fm = vfs::Log::FLUSH_ON_ENDL;
|
||||
else fm = vfs::Log::FLUSH_IMMEDIATELY;
|
||||
|
||||
_logs[id].file = vfs::Log::create(log_file,append,fm);
|
||||
}
|
||||
}
|
||||
void sgp::Logger::disconnectFile(sgp::Logger_ID id)
|
||||
{
|
||||
if(id >= 0 && id < _logs.size())
|
||||
{
|
||||
if(_logs[id].file)
|
||||
{
|
||||
_logs[id].file->destroy();
|
||||
_logs[id].file = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sgp::Logger::connectStream(sgp::Logger_ID id, std::ostream& stream)
|
||||
{
|
||||
if(id >= 0 && id < _logs.size())
|
||||
{
|
||||
_logs[id].stream = &std::wcout;
|
||||
}
|
||||
}
|
||||
void sgp::Logger::disconnectStream(sgp::Logger_ID id)
|
||||
{
|
||||
if(id >= 0 && id < _logs.size())
|
||||
{
|
||||
_logs[id].stream = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void sgp::Logger::connectScreen(sgp::Logger_ID id)
|
||||
{
|
||||
if(id >= 0 && id < _logs.size())
|
||||
{
|
||||
if(_logs[id].screen)
|
||||
{
|
||||
disconnectScreen(id);
|
||||
}
|
||||
_logs[id].screen = new std::wstringstream;
|
||||
}
|
||||
}
|
||||
void sgp::Logger::disconnectScreen(sgp::Logger_ID id)
|
||||
{
|
||||
if(id >= 0 && id < _logs.size())
|
||||
{
|
||||
if(_logs[id].screen)
|
||||
{
|
||||
flush_screen(*_logs[id].screen);
|
||||
delete _logs[id].screen;
|
||||
_logs[id].screen = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sgp::Logger::LogInstance sgp::Logger::logger(sgp::Logger_ID id)
|
||||
{
|
||||
if(id < _logs.size())
|
||||
{
|
||||
std::wstringstream tmp;
|
||||
tmp << L"[" << _logs[id].timer.running() << L"] : ";
|
||||
std::wstring str(tmp.str());
|
||||
|
||||
LogData& ld = _logs[id];
|
||||
if(ld.file) {
|
||||
(*ld.file).lock();
|
||||
(*ld.file) << str;
|
||||
}
|
||||
if(ld.stream) {
|
||||
(*ld.stream) << str;
|
||||
}
|
||||
if(ld.screen) {
|
||||
(*ld.screen) << str;
|
||||
}
|
||||
return sgp::Logger::LogInstance(&ld);
|
||||
}
|
||||
SGP_THROW(L"Unknown log id");
|
||||
}
|
||||
|
||||
template <>
|
||||
sgp::Logger::LogInstance& sgp::Logger::LogInstance::operator<< <sgp::_flush>(sgp::_flush const& e)
|
||||
{
|
||||
if(_log.file)
|
||||
{
|
||||
(*_log.file).flush();
|
||||
(*_log.file).unlock();
|
||||
}
|
||||
if(_log.stream)
|
||||
{
|
||||
(*_log.stream).flush();
|
||||
}
|
||||
if(_log.screen)
|
||||
{
|
||||
flush_screen(*_log.screen);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <>
|
||||
sgp::Logger::LogInstance& sgp::Logger::LogInstance::operator<< <sgp::_endl>(sgp::_endl const& e)
|
||||
{
|
||||
if(_log.file)
|
||||
{
|
||||
(*_log.file) << vfs::Log::endl;
|
||||
if(_log.file->flushMode() == vfs::Log::FLUSH_ON_ENDL)
|
||||
{
|
||||
(*_log.file).flush();
|
||||
}
|
||||
(*_log.file).unlock();
|
||||
}
|
||||
if(_log.stream)
|
||||
{
|
||||
(*_log.stream) << std::endl;
|
||||
(*_log.stream).flush();
|
||||
}
|
||||
if(_log.screen)
|
||||
{
|
||||
flush_screen(*_log.screen);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <>
|
||||
sgp::Logger::LogInstance& sgp::Logger::LogInstance::operator<< <sgp::_lock>(sgp::_lock const& l)
|
||||
{
|
||||
_log.file->lock();
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
#ifndef SGP_LOGGER_H
|
||||
#define SGP_LOGGER_H
|
||||
|
||||
#include <vector>
|
||||
#include <vfs/Core/vfs_string.h>
|
||||
#include <vfs/Tools/vfs_log.h>
|
||||
#include <vfs/Tools/vfs_hp_timer.h>
|
||||
|
||||
namespace sgp
|
||||
{
|
||||
typedef unsigned int Logger_ID;
|
||||
|
||||
enum _endl{endl};
|
||||
enum _lock{lock};
|
||||
enum _flush{flush};
|
||||
|
||||
class Logger
|
||||
{
|
||||
struct LogData
|
||||
{
|
||||
LogData() : file(NULL), stream(NULL), screen(NULL) {};
|
||||
vfs::HPTimer timer;
|
||||
vfs::Log* file;
|
||||
std::wostream* stream;
|
||||
std::wstringstream* screen;
|
||||
};
|
||||
public:
|
||||
|
||||
enum FlushMode
|
||||
{
|
||||
FLUSH_ON_DELETE,
|
||||
FLUSH_ON_ENDL,
|
||||
FLUSH_ON_FLUSH,
|
||||
FLUSH_FULL_BUFFER,
|
||||
FLUSH_IMMIDIATELY,
|
||||
};
|
||||
|
||||
// need to lock/unlock on every logging operation, as they can be called from multiple threads
|
||||
class LogInstance
|
||||
{
|
||||
friend class Logger;
|
||||
LogInstance(LogData* ld) : _log(*ld) {};
|
||||
public:
|
||||
template <typename T>
|
||||
LogInstance& operator<<(T const& t){
|
||||
if(_log.stream) (*_log.stream) << t;
|
||||
if(_log.screen) (*_log.screen) << t;
|
||||
if(_log.file ) (*_log.file) << t;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
LogData& _log;
|
||||
};
|
||||
|
||||
|
||||
static Logger& instance();
|
||||
|
||||
bool init();
|
||||
bool shutdown();
|
||||
|
||||
LogInstance logger(Logger_ID id);
|
||||
|
||||
Logger_ID createLogger();
|
||||
|
||||
void connectFile(Logger_ID id, vfs::Path const& log_file, bool append, FlushMode fp);
|
||||
void disconnectFile(Logger_ID id);
|
||||
void connectStream(Logger_ID id, std::ostream& stream);
|
||||
void disconnectStream(Logger_ID id);
|
||||
|
||||
void connectScreen(Logger_ID id);
|
||||
void disconnectScreen(Logger_ID id);
|
||||
|
||||
void flushMode(Logger_ID id, FlushMode fmode);
|
||||
FlushMode flushMode(Logger_ID id);
|
||||
private:
|
||||
Logger();
|
||||
~Logger();
|
||||
|
||||
private:
|
||||
static int _next_log_id;
|
||||
|
||||
static std::vector<LogData> _logs;
|
||||
};
|
||||
|
||||
template <>
|
||||
Logger::LogInstance& Logger::LogInstance::operator<< <_endl>(_endl const& e);
|
||||
template <>
|
||||
Logger::LogInstance& Logger::LogInstance::operator<< <_lock>(_lock const& l);
|
||||
template <>
|
||||
Logger::LogInstance& Logger::LogInstance::operator<< <_flush>(_flush const& f);
|
||||
}
|
||||
|
||||
inline sgp::Logger::LogInstance SGP_LOG(sgp::Logger_ID id, vfs::String const& str){
|
||||
return sgp::Logger::instance().logger(id) << (str) << sgp::endl;
|
||||
}
|
||||
inline sgp::Logger::LogInstance SGP_LOG(sgp::Logger_ID id){
|
||||
return sgp::Logger::instance().logger(id);
|
||||
}
|
||||
|
||||
inline sgp::Logger::LogInstance SGP_INFO(vfs::String const& str){
|
||||
return sgp::Logger::instance().logger(0) << str << sgp::endl;
|
||||
}
|
||||
inline sgp::Logger::LogInstance SGP_INFO(){
|
||||
return sgp::Logger::instance().logger(0);
|
||||
}
|
||||
|
||||
inline sgp::Logger::LogInstance SGP_WARNING(vfs::String const& str){
|
||||
return sgp::Logger::instance().logger(0) << "WARNING : " << str << sgp::endl;
|
||||
}
|
||||
inline sgp::Logger::LogInstance SGP_WARNING(){
|
||||
return sgp::Logger::instance().logger(0) << "WARNING : ";
|
||||
}
|
||||
|
||||
inline sgp::Logger::LogInstance SGP_ERROR(vfs::String const& str){
|
||||
return sgp::Logger::instance().logger(0) << "ERROR : " << str << sgp::endl;
|
||||
}
|
||||
inline sgp::Logger::LogInstance SGP_ERROR(){
|
||||
return sgp::Logger::instance().logger(0) << "ERROR : ";
|
||||
}
|
||||
|
||||
#endif // SGP_LOGGER_H
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
#include "DirectDraw Calls.h"
|
||||
#include <stdio.h>
|
||||
#include "debug.h"
|
||||
#include "video.h"
|
||||
#include "himage.h"
|
||||
#include "vobject.h"
|
||||
#include "vobject_blitters.h"
|
||||
#include "shading.h"
|
||||
|
||||
BOOLEAN ShadesCalculateTables(SGPPaletteEntry *p8BPPPalette);
|
||||
BOOLEAN ShadesCalculatePalette(SGPPaletteEntry *pSrcPalette, SGPPaletteEntry *pDestPalette, UINT16 usRed, UINT16 usGreen, UINT16 usBlue, BOOLEAN fMono);
|
||||
void FindIndecies(SGPPaletteEntry *pSrcPalette, SGPPaletteEntry *pMapPalette, UINT8 *pTable);
|
||||
void FindMaskIndecies(UINT8 *, UINT8 *, UINT8 *);
|
||||
|
||||
SGPPaletteEntry Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES+3][256];
|
||||
UINT8 ubColorTables[HVOBJECT_SHADE_TABLES+3][256];
|
||||
|
||||
UINT16 IntensityTable[65536];
|
||||
UINT16 ShadeTable[65536];
|
||||
UINT16 White16BPPPalette[ 256 ];
|
||||
FLOAT guiShadePercent = (FLOAT)0.48;
|
||||
FLOAT guiBrightPercent = (FLOAT)1.1;
|
||||
|
||||
BOOLEAN ShadesCalculateTables(SGPPaletteEntry *p8BPPPalette)
|
||||
{
|
||||
UINT32 uiCount;
|
||||
|
||||
// Green palette
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[0], 0, 255, 0, TRUE);
|
||||
// Blue palette
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES], 0, 0, 255, TRUE);
|
||||
// Yellow palette
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES+1], 255, 255, 0, TRUE);
|
||||
// Red palette
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES+2], 255, 0, 0, TRUE);
|
||||
|
||||
// these are the brightening tables, 115%-150% brighter than original
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[1], 293, 293, 293, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[2], 281, 281, 281, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[3], 268, 268, 268, FALSE);
|
||||
|
||||
// palette 4 is the non-modified palette.
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[4], 255, 255, 255, FALSE);
|
||||
|
||||
// the rest are darkening tables, right down to all-black.
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[5], 195, 195, 195, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[6], 165, 165, 165, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[7], 135, 135, 135, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[8], 105, 105, 105, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[9], 75, 75, 75, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[10], 45, 45, 45, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[11], 36, 36, 36, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[12], 27, 27, 27, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[13], 18, 18, 18, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[14], 9, 9, 9, FALSE);
|
||||
ShadesCalculatePalette(p8BPPPalette, Shaded8BPPPalettes[15], 0, 0, 0, FALSE);
|
||||
|
||||
|
||||
// Remap the shade colors to the original palette
|
||||
for(uiCount=0; uiCount < (HVOBJECT_SHADE_TABLES+3); uiCount++)
|
||||
{
|
||||
FindIndecies(Shaded8BPPPalettes[uiCount], p8BPPPalette, ubColorTables[uiCount]);
|
||||
ubColorTables[uiCount][0]=0;
|
||||
}
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
BOOLEAN ShadesCalculatePalette(SGPPaletteEntry *pSrcPalette, SGPPaletteEntry *pDestPalette, UINT16 usRed, UINT16 usGreen, UINT16 usBlue, BOOLEAN fMono)
|
||||
{
|
||||
UINT32 cnt, lumin;
|
||||
UINT32 rmod, gmod, bmod;
|
||||
|
||||
Assert( pSrcPalette != NULL );
|
||||
Assert( pDestPalette != NULL );
|
||||
|
||||
for ( cnt = 0; cnt < 256; cnt++ )
|
||||
{
|
||||
if(fMono)
|
||||
{
|
||||
lumin=(pSrcPalette[ cnt ].peRed*299/1000)+ (pSrcPalette[ cnt ].peGreen*587/1000)+(pSrcPalette[ cnt ].peBlue*114/1000);
|
||||
rmod=usRed*lumin/255;
|
||||
gmod=usGreen*lumin/255;
|
||||
bmod=usBlue*lumin/255;
|
||||
}
|
||||
else
|
||||
{
|
||||
rmod = (usRed*pSrcPalette[ cnt ].peRed/255);
|
||||
gmod = (usGreen*pSrcPalette[ cnt ].peGreen/255);
|
||||
bmod = (usBlue*pSrcPalette[ cnt ].peBlue/255);
|
||||
}
|
||||
|
||||
pDestPalette[ cnt ].peRed = (UINT8)__min(rmod, 255);
|
||||
pDestPalette[ cnt ].peGreen = (UINT8)__min(gmod, 255);
|
||||
pDestPalette[ cnt ].peBlue = (UINT8)__min(bmod, 255);
|
||||
}
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FindIndecies(SGPPaletteEntry *pSrcPalette, SGPPaletteEntry *pMapPalette, UINT8 *pTable)
|
||||
{
|
||||
UINT16 usCurIndex, usCurDelta, usCurCount;
|
||||
UINT32 *pSavedPtr;
|
||||
|
||||
__asm {
|
||||
|
||||
// Assumes:
|
||||
// ESI = Pointer to source palette (shaded values)
|
||||
// EDI = Pointer to original palette (palette we'll end up using!)
|
||||
// EBX = Pointer to array of indecies
|
||||
|
||||
mov esi, pSrcPalette
|
||||
mov edi, pMapPalette
|
||||
mov ebx, pTable
|
||||
|
||||
mov BYTE PTR [ebx],0 ; Index 0 is always 0, for trans col
|
||||
inc ebx
|
||||
|
||||
add esi,4 ; Goto next color entry
|
||||
add edi,4
|
||||
mov pSavedPtr, edi ; Save pointer to original pal
|
||||
|
||||
mov usCurCount, 255 ; We'll check cols 1-255
|
||||
|
||||
DoNextIndex:
|
||||
|
||||
mov edi, pSavedPtr ; Restore saved ptr
|
||||
mov usCurIndex, 256 ; Set found index & delta to some
|
||||
mov usCurDelta, 0ffffh ; val so we get at least 1 col.
|
||||
|
||||
mov ecx,255 ; Check cols 1-255 of orig pal
|
||||
push ebx
|
||||
xor bx,bx
|
||||
|
||||
NextColor:
|
||||
xor ah,ah ; Calc delta between shaded color
|
||||
mov al,[edi] ; and a color in the orig palette.
|
||||
mov bl,[esi] ; Formula:
|
||||
sub ax,bx ; Delta = abs(red-origred) +
|
||||
or ax,ax ; abs(green-origgreen) +
|
||||
jns NC1
|
||||
neg ax
|
||||
NC1:mov dx,ax ; abs(blue-origblue)
|
||||
xor ah,ah
|
||||
mov al,[edi+1]
|
||||
mov bl,[esi+1]
|
||||
sub ax,bx
|
||||
or ax,ax ; abs(green-origgreen) +
|
||||
jns NC2
|
||||
neg ax
|
||||
NC2:add dx,ax
|
||||
xor ah,ah
|
||||
mov al,[edi+2]
|
||||
mov bl,[esi+2]
|
||||
sub ax,bx
|
||||
or ax,ax ; abs(green-origgreen) +
|
||||
jns NC3
|
||||
neg ax
|
||||
NC3:add dx,ax
|
||||
|
||||
cmp dx,usCurDelta ; If delta < old delta
|
||||
jae NotThisCol ; Save this delta and it's
|
||||
mov ax,256 ; palette index
|
||||
mov [usCurDelta],dx
|
||||
sub ax,cx
|
||||
mov [usCurIndex],ax
|
||||
NotThisCol:
|
||||
add edi,4 ; Try next color in orginal pal
|
||||
dec cx
|
||||
jnz NextColor
|
||||
|
||||
pop ebx
|
||||
mov ax,usCurIndex ; By now, usCurIndex holds pal index
|
||||
mov [ebx],al ; of closest color in orig pal
|
||||
inc ebx ; so save it, then repeat above
|
||||
add esi,4 ; for the other cols in shade pal
|
||||
dec usCurCount
|
||||
jnz DoNextIndex
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************************************
|
||||
BuildShadeTable
|
||||
|
||||
Builds a 16-bit color shading table. This function should be called only after the current
|
||||
video adapter's pixel format is known (IE: GetRgbDistribution() has been called, and the
|
||||
globals for masks and shifts have been initialized by that function), and before any
|
||||
blitting is done.
|
||||
|
||||
Using the table is a straight lookup. The pixel to be shaded down is used as the index into
|
||||
the table and the entry at that point will be a pixel that is 25% darker.
|
||||
|
||||
**********************************************************************************************/
|
||||
void BuildShadeTable(void)
|
||||
{
|
||||
UINT16 red, green, blue;
|
||||
UINT16 index = 0;
|
||||
|
||||
|
||||
for(red=0; red < 256; red+=4)
|
||||
for(green=0; green < 256; green+=4)
|
||||
for(blue=0; blue < 256; blue+=4)
|
||||
{
|
||||
index=Get16BPPColor(FROMRGB(red, green, blue));
|
||||
ShadeTable[index]=Get16BPPColor(FROMRGB(red*guiShadePercent, green*guiShadePercent, blue*guiShadePercent));
|
||||
}
|
||||
|
||||
memset( White16BPPPalette, 65535, sizeof( White16BPPPalette ) );
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************************
|
||||
BuildIntensityTable
|
||||
|
||||
Builds a 16-bit color shading table. This function should be called only after the current
|
||||
video adapter's pixel format is known (IE: GetRgbDistribution() has been called, and the
|
||||
globals for masks and shifts have been initialized by that function), and before any
|
||||
blitting is done.
|
||||
|
||||
|
||||
|
||||
**********************************************************************************************/
|
||||
void BuildIntensityTable(void)
|
||||
{
|
||||
UINT16 red, green, blue = 0;
|
||||
UINT16 index = 0;
|
||||
FLOAT dShadedPercent = (FLOAT)0.80;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for(red=0; red < 256; red+=4)
|
||||
for(green=0; green < 256; green+=4)
|
||||
for(blue=0; blue < 256; blue+=4)
|
||||
{
|
||||
index=Get16BPPColor(FROMRGB(red, green, blue));
|
||||
IntensityTable[index]=Get16BPPColor(FROMRGB(red*dShadedPercent, green*dShadedPercent, blue*dShadedPercent));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SetShadeTablePercent( FLOAT uiShadePercent )
|
||||
{
|
||||
guiShadePercent = uiShadePercent;
|
||||
BuildShadeTable( );
|
||||
}
|
||||
|
||||
|
||||
void Init8BitTables(void)
|
||||
{
|
||||
SGPPaletteEntry Pal[256];
|
||||
UINT32 uiCount;
|
||||
|
||||
// calculate a grey-scale table for the default palette
|
||||
for(uiCount=0; uiCount < 256; uiCount++)
|
||||
{
|
||||
Pal[uiCount].peRed=(UINT8)(uiCount%128)+128;
|
||||
Pal[uiCount].peGreen=(UINT8)(uiCount%128)+128;
|
||||
Pal[uiCount].peBlue=(UINT8)(uiCount%128)+128;
|
||||
}
|
||||
|
||||
Pal[0].peRed=0;
|
||||
Pal[0].peGreen=0;
|
||||
Pal[0].peBlue=0;
|
||||
|
||||
Set8BPPPalette(Shaded8BPPPalettes[4]);
|
||||
}
|
||||
|
||||
BOOLEAN Set8BitModePalette(SGPPaletteEntry *pPal)
|
||||
{
|
||||
ShadesCalculateTables(pPal);
|
||||
Set8BPPPalette(pPal);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef _SHADING_H_
|
||||
#define _SHADING_H_
|
||||
|
||||
|
||||
#include "himage.h" // For SGPPaletteEntry
|
||||
#include "vobject.h" // For HVOBJECT_SHADE_TABLES
|
||||
#include "vsurface.h" // For
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BOOLEAN ShadesCalculateTables(SGPPaletteEntry *p8BPPPalette);
|
||||
|
||||
void BuildShadeTable(void);
|
||||
void BuildIntensityTable(void);
|
||||
void SetShadeTablePercent( FLOAT uiShadePercent );
|
||||
|
||||
void Init8BitTables(void);
|
||||
BOOLEAN Set8BitModePalette(SGPPaletteEntry *pPal);
|
||||
|
||||
extern SGPPaletteEntry Shaded8BPPPalettes[HVOBJECT_SHADE_TABLES+3][256];
|
||||
extern UINT8 ubColorTables[HVOBJECT_SHADE_TABLES+3][256];
|
||||
|
||||
extern UINT16 IntensityTable[65536];
|
||||
extern UINT16 ShadeTable[65536];
|
||||
extern UINT16 White16BPPPalette[ 256 ];
|
||||
extern FLOAT guiShadePercent;
|
||||
extern FLOAT guiBrightPercent;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define DEFAULT_SHADE_LEVEL 4
|
||||
|
||||
#endif
|
||||
+1871
File diff suppressed because it is too large
Load Diff
+108
@@ -0,0 +1,108 @@
|
||||
#ifndef __SOUNDMAN_
|
||||
#define __SOUNDMAN_
|
||||
|
||||
#include "types.h"
|
||||
#include "fmod.h"
|
||||
#include "fmod_errors.h"
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
|
||||
// Sample status flags
|
||||
#define SAMPLE_ALLOCATED 0x00000001
|
||||
#define SAMPLE_LOCKED 0x00000002
|
||||
#define SAMPLE_RANDOM 0x00000004
|
||||
#define SAMPLE_RANDOM_MANUAL 0x00000008
|
||||
|
||||
// Sound error values (they're all the same)
|
||||
#define NO_SAMPLE 0xffffffff
|
||||
#define SOUND_ERROR 0xffffffff
|
||||
|
||||
// Maximum allowable priority value
|
||||
#define PRIORITY_MAX 0xfffffffe
|
||||
#define PRIORITY_RANDOM PRIORITY_MAX-1
|
||||
|
||||
|
||||
// Structure definition for sound parameters being passed down to the sample playing function
|
||||
typedef struct {
|
||||
UINT32 uiSpeed;
|
||||
UINT32 uiPitchBend; // Random pitch bend range +/-
|
||||
UINT32 uiVolume;
|
||||
UINT32 uiPan;
|
||||
UINT32 uiLoop;
|
||||
UINT32 uiPriority;
|
||||
void (*EOSCallback)(void *);
|
||||
void *pCallbackData;
|
||||
} SOUNDPARMS;
|
||||
|
||||
|
||||
// Structure definition for parameters to the random sample playing function
|
||||
typedef struct {
|
||||
UINT32 uiTimeMin, uiTimeMax;
|
||||
UINT32 uiSpeedMin, uiSpeedMax;
|
||||
UINT32 uiVolMin, uiVolMax;
|
||||
UINT32 uiPanMin, uiPanMax;
|
||||
UINT32 uiPriority;
|
||||
UINT32 uiMaxInstances;
|
||||
} RANDOMPARMS;
|
||||
|
||||
|
||||
// Global startup/shutdown functions
|
||||
extern BOOLEAN InitializeSoundManager(void);
|
||||
extern void ShutdownSoundManager(void);
|
||||
|
||||
// Configuration functions
|
||||
extern BOOLEAN SoundSetMemoryLimit(UINT32 uiLimit);
|
||||
extern BOOLEAN SoundSetCacheThreshhold(UINT32 uiThreshold);
|
||||
extern void * SoundGetDriverHandle( void );
|
||||
|
||||
// Master volume control functions
|
||||
extern void SoundSetDefaultVolume(UINT32 uiVolume);
|
||||
extern UINT32 SoundGetDefaultVolume(void);
|
||||
|
||||
// Cache control functions
|
||||
//extern UINT32 SoundLoadSample(STR pFilename);
|
||||
UINT32 SoundLoadSample(STR pFilename);
|
||||
|
||||
extern UINT32 SoundFreeSample(STR pFilename);
|
||||
extern UINT32 SoundLockSample(STR pFilename);
|
||||
extern UINT32 SoundUnlockSample(STR pFilename);
|
||||
extern BOOLEAN SoundEmptyCache(void);
|
||||
|
||||
// Play/service sample functions
|
||||
extern UINT32 SoundPlay(STR pFilename, SOUNDPARMS *pParms);
|
||||
extern UINT32 SoundPlayStreamedFile( STR pFilename, SOUNDPARMS *pParms );
|
||||
extern UINT32 SoundPlayRandom(STR pFilename, RANDOMPARMS *pParms);
|
||||
extern BOOLEAN SoundServiceStreams(void);
|
||||
extern BOOLEAN SoundServiceRandom(void);
|
||||
|
||||
// sevenfm
|
||||
void ResetSoundMap(void);
|
||||
|
||||
// Sound instance manipulation functions
|
||||
extern BOOLEAN SoundStopAll(void);
|
||||
extern BOOLEAN SoundStopAllRandom(void);
|
||||
extern BOOLEAN SoundStop(UINT32 uiSoundID);
|
||||
extern BOOLEAN SoundIsPlaying(UINT32 uiSoundID);
|
||||
extern BOOLEAN SoundSetVolume(UINT32 uiSoundID, UINT32 uiVolume);
|
||||
extern BOOLEAN SoundSetPan(UINT32 uiSoundID, UINT32 uiPan);
|
||||
extern UINT32 SoundGetVolume(UINT32 uiSoundID);
|
||||
extern UINT32 SoundGetPosition(UINT32 uiSoundID);
|
||||
|
||||
extern void SoundSetSampleFlags( UINT32 uiSample, UINT32 uiFlags );
|
||||
extern void SoundRemoveSampleFlags( UINT32 uiSample, UINT32 uiFlags );
|
||||
|
||||
extern void SoundEnableSound(BOOLEAN fEnable);
|
||||
|
||||
extern void SoundLog(CHAR8 *strMessage);
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Snap: Implementation of case-insensitive string comparison classes
|
||||
//
|
||||
#include "stringicmp.h"
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
|
||||
bool TStringiLess::operator() (std::string const& s1, std::string const& s2) const
|
||||
{
|
||||
// An MSVC compliance issue...
|
||||
//using std::toupper;
|
||||
|
||||
const char *p1 = s1.c_str();
|
||||
const char *p2 = s2.c_str();
|
||||
|
||||
while (*p1 && *p2 && toupper(*p1) == toupper(*p2)) {
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
|
||||
if (!*p1) return *p2 != 0;
|
||||
if (!*p2) return false;
|
||||
|
||||
return toupper(*p1) < toupper(*p2);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Snap: Declaration of case-insensitive string comparison classes
|
||||
//
|
||||
#pragma warning(disable:4786)
|
||||
#ifndef STRINGICMP_H
|
||||
#define STRINGICMP_H
|
||||
|
||||
#include <string>
|
||||
|
||||
// Function-object that compares strings (s1 < s2) ignoring case
|
||||
class TStringiLess {
|
||||
public:
|
||||
bool operator() (std::string const& s1, std::string const& s2) const;
|
||||
};
|
||||
|
||||
#endif // STRINGICMP_H
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "types.h"
|
||||
#include <windows.h>
|
||||
#include "video.h"
|
||||
#include "timer.h"
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
UINT32 guiStartupTime;
|
||||
UINT32 guiCurrentTime;
|
||||
|
||||
void CALLBACK Clock( HWND hWindow, UINT uMessage, UINT idEvent, DWORD dwTime )
|
||||
{
|
||||
guiCurrentTime = GetTickCount();
|
||||
if (guiCurrentTime < guiStartupTime)
|
||||
{ // Adjust guiCurrentTime because of loopback on the timer value
|
||||
guiCurrentTime = guiCurrentTime + (0xffffffff - guiStartupTime);
|
||||
}
|
||||
else
|
||||
{ // Adjust guiCurrentTime because of loopback on the timer value
|
||||
guiCurrentTime = guiCurrentTime - guiStartupTime;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN InitializeClockManager(void)
|
||||
{
|
||||
|
||||
// Register the start time (use WIN95 API call)
|
||||
guiCurrentTime = guiStartupTime = GetTickCount();
|
||||
SetTimer(ghWindow, MAIN_TIMER_ID, 10, (TIMERPROC)Clock);
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void ShutdownClockManager(void)
|
||||
{
|
||||
|
||||
// Make sure we kill the timer
|
||||
KillTimer(ghWindow, MAIN_TIMER_ID);
|
||||
|
||||
}
|
||||
|
||||
TIMER GetClock(void)
|
||||
{
|
||||
return guiCurrentTime;
|
||||
}
|
||||
|
||||
TIMER SetCountdownClock(UINT32 uiTimeToElapse)
|
||||
{
|
||||
return (guiCurrentTime + uiTimeToElapse);
|
||||
}
|
||||
|
||||
UINT32 ClockIsTicking(TIMER uiTimer)
|
||||
{
|
||||
if (uiTimer > guiCurrentTime)
|
||||
{ // Well timer still hasn't elapsed
|
||||
return (uiTimer - guiCurrentTime);
|
||||
}
|
||||
// Time's up
|
||||
return 0;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#ifndef __TIMER_
|
||||
#define __TIMER_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
typedef UINT32 TIMER;
|
||||
|
||||
#define MAIN_TIMER_ID 1
|
||||
|
||||
#define MILLISECONDS(a) (a)
|
||||
#define SECONDS(a) ((a) / 1000)
|
||||
#define MINUTES(a) (SECOND((a)) / 60)
|
||||
#define HOURS(a) (MINUTES((a)) / 60)
|
||||
#define DAYS(a) (HOURS((a)) / 24)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BOOLEAN InitializeClockManager(void);
|
||||
void ShutdownClockManager(void);
|
||||
TIMER GetClock(void);
|
||||
TIMER SetCountdownClock(UINT32 TimeToElapse);
|
||||
UINT32 ClockIsTicking(TIMER uiTimer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+3322
File diff suppressed because it is too large
Load Diff
+101
@@ -0,0 +1,101 @@
|
||||
#ifndef __VIDEO_
|
||||
#define __VIDEO_
|
||||
|
||||
#include <windows.h>
|
||||
#include <ddraw.h>
|
||||
#include <process.h>
|
||||
|
||||
#include "Local.h"
|
||||
#include "Debug.h"
|
||||
#include "Types.h"
|
||||
#include "DirectDraw Calls.h"
|
||||
#include "VSurface.h"
|
||||
|
||||
#define BUFFER_READY 0x00
|
||||
#define BUFFER_BUSY 0x01
|
||||
#define BUFFER_DIRTY 0x02
|
||||
#define BUFFER_DISABLED 0x03
|
||||
|
||||
#define MAX_CURSOR_WIDTH 64
|
||||
#define MAX_CURSOR_HEIGHT 64
|
||||
#define VIDEO_NO_CURSOR 0xFFFF
|
||||
|
||||
|
||||
extern HWND ghWindow;
|
||||
extern UINT32 guiMouseBufferState; // BUFFER_READY, BUFFER_DIRTY, BUFFER_DISABLED
|
||||
//#ifdef WINFONTS
|
||||
extern UINT32 CurrentSurface;
|
||||
//#endif
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
|
||||
extern BOOLEAN InitializeVideoManager(HINSTANCE hInstance, UINT16 usCommandShow, void *WindowProc);
|
||||
extern void ShutdownVideoManager(void);
|
||||
extern void SuspendVideoManager(void);
|
||||
extern BOOLEAN RestoreVideoManager(void);
|
||||
extern void GetCurrentVideoSettings(UINT16 *usWidth, UINT16 *usHeight, UINT8 *ubBitDepth);
|
||||
extern BOOLEAN CanBlitToFrameBuffer(void);
|
||||
extern BOOLEAN CanBlitToMouseBuffer(void);
|
||||
extern void InvalidateRegion(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom);
|
||||
extern void InvalidateRegions(SGPRect *pArrayOfRegions, UINT32 uiRegionCount);
|
||||
extern void InvalidateScreen(void);
|
||||
extern void InvalidateFrameBuffer(void);
|
||||
extern void SetFrameBufferRefreshOverride(PTR pFrameBufferRefreshOverride);
|
||||
extern LPDIRECTDRAW2 GetDirectDraw2Object(void);
|
||||
extern LPDIRECTDRAWSURFACE2 GetPrimarySurfaceObject(void);
|
||||
extern LPDIRECTDRAWSURFACE2 GetBackBufferObject(void);
|
||||
extern LPDIRECTDRAWSURFACE2 GetFrameBufferObject(void);
|
||||
extern LPDIRECTDRAWSURFACE2 GetMouseBufferObject(void);
|
||||
extern PTR LockPrimarySurface(UINT32 *uiPitch);
|
||||
extern void UnlockPrimarySurface(void);
|
||||
extern PTR LockBackBuffer(UINT32 *uiPitch);
|
||||
extern void UnlockBackBuffer(void);
|
||||
extern PTR LockFrameBuffer(UINT32 *uiPitch);
|
||||
extern void UnlockFrameBuffer(void);
|
||||
extern PTR LockMouseBuffer(UINT32 *uiPitch);
|
||||
extern void UnlockMouseBuffer(void);
|
||||
extern BOOLEAN GetRGBDistribution(void);
|
||||
extern BOOLEAN GetPrimaryRGBDistributionMasks(UINT32 *RedBitMask, UINT32 *GreenBitMask, UINT32 *BblueBitMask);
|
||||
extern BOOLEAN SetMouseCursorFromObject(UINT32 uiVideoObjectHandle, UINT16 usVideoObjectSubIndex, UINT16 usOffsetX, UINT16 usOffsetY );
|
||||
extern BOOLEAN HideMouseCursor(void);
|
||||
extern BOOLEAN LoadCursorFile(STR8 pFilename);
|
||||
extern BOOLEAN SetCurrentCursor(UINT16 usVideoObjectSubIndex, UINT16 usOffsetX, UINT16 usOffsetY );
|
||||
extern void StartFrameBufferRender(void);
|
||||
extern void EndFrameBufferRender(void);
|
||||
extern void PrintScreen(void);
|
||||
|
||||
|
||||
|
||||
extern BOOLEAN EraseMouseCursor( );
|
||||
extern BOOLEAN SetMouseCursorProperties( INT16 sOffsetX, INT16 sOffsetY, UINT16 usCursorHeight, UINT16 usCursorWidth );
|
||||
extern BOOLEAN BltToMouseCursor(UINT32 uiVideoObjectHandle, UINT16 usVideoObjectSubIndex, UINT16 usXPos, UINT16 usYPos );
|
||||
void DirtyCursor( );
|
||||
void EnableCursor( BOOLEAN fEnable );
|
||||
|
||||
BOOLEAN Set8BPPPalette(SGPPaletteEntry *pPalette);
|
||||
// 8-bit palette globals
|
||||
|
||||
void VideoCaptureToggle( void );
|
||||
|
||||
|
||||
void InvalidateRegionEx(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom, UINT32 uiFlags );
|
||||
|
||||
void RefreshScreen(void *DummyVariable);
|
||||
|
||||
|
||||
void FatalError( const STR8 pError, ...);
|
||||
|
||||
|
||||
extern SGPPaletteEntry gSgpPalette[256];
|
||||
extern LPDIRECTDRAWPALETTE gpDirectDrawPalette;
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif
|
||||
+1856
File diff suppressed because it is too large
Load Diff
+278
@@ -0,0 +1,278 @@
|
||||
#ifndef __VOBJECT_H
|
||||
#define __VOBJECT_H
|
||||
|
||||
#include "types.h"
|
||||
#include "himage.h"
|
||||
|
||||
// ************************************************************************************
|
||||
//
|
||||
// Video Object SGP Module
|
||||
//
|
||||
// ************************************************************************************
|
||||
|
||||
|
||||
// This definition mimics what is found in WINDOWS.H ( for Direct Draw compatiblity )
|
||||
typedef UINT32 COLORVAL;
|
||||
|
||||
// Defines for blitting
|
||||
#define VO_BLT_SRCTRANSPARENCY 0x000000002
|
||||
#define VO_BLT_DESTTRANSPARENCY 0x000000120
|
||||
#define VO_BLT_SHADOW 0x000000200
|
||||
#define VO_BLT_TRANSSHADOW 0x000000003
|
||||
#define VO_BLT_UNCOMPRESSED 0x000004000
|
||||
#define VO_BLT_CLIP 0x000000001
|
||||
#define VO_BLT_MIRROR_Y 0x000001000 // must be the same as VS_BLT_MIRROR_Y for Wiz!!!
|
||||
|
||||
// Defines for HVOBJECT limits
|
||||
#define HVOBJECT_SHADE_TABLES 48
|
||||
|
||||
#define HVOBJECT_GLOW_GREEN 0
|
||||
#define HVOBJECT_GLOW_BLUE 1
|
||||
#define HVOBJECT_GLOW_YELLOW 2
|
||||
#define HVOBJECT_GLOW_RED 3
|
||||
|
||||
// Effects structure for specialized blitting
|
||||
typedef struct
|
||||
{
|
||||
UINT32 uiShadowLevel;
|
||||
SGPRect ClipRect;
|
||||
|
||||
} blt_fx;
|
||||
|
||||
|
||||
// Z-buffer info structure for properly assigning Z values
|
||||
typedef struct
|
||||
{
|
||||
INT8 bInitialZChange; // difference in Z value between the leftmost and base strips
|
||||
UINT8 ubFirstZStripWidth; // # of pixels in the leftmost strip
|
||||
UINT8 ubNumberOfZChanges; // number of strips (after the first)
|
||||
INT8 * pbZChange; // change to the Z value in each strip (after the first)
|
||||
} ZStripInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT16 * p16BPPData;
|
||||
UINT16 usRegionIndex;
|
||||
UINT8 ubShadeLevel;
|
||||
UINT16 usWidth;
|
||||
UINT16 usHeight;
|
||||
INT16 sOffsetX;
|
||||
INT16 sOffsetY;
|
||||
} SixteenBPPObjectInfo;
|
||||
|
||||
// This definition mimics what is found in WINDOWS.H ( for Direct Draw compatiblity )
|
||||
// From RGB to COLORVAL
|
||||
#define FROMRGB(r, g ,b) ((UINT32) (((UINT8) (r) | ((UINT16) (g) << 8)) | (((UINT32) (UINT8) (b)) << 16)))
|
||||
|
||||
|
||||
// Video object creation flags
|
||||
// Used in the VOBJECT_DESC structure to describe creation flags
|
||||
|
||||
#define VOBJECT_CREATE_DEFAULT 0x00000020 // Creates and empty object of given width, height and BPP
|
||||
#define VOBJECT_CREATE_FROMFILE 0x00000040 // Creates a video object from a file ( using HIMAGE )
|
||||
#define VOBJECT_CREATE_FROMHIMAGE 0x00000080 // Creates a video object from a pre-loaded hImage
|
||||
#define VOBJECT_CREATE_FROMJPC 0x00010000 // replace file extension : sti -> jpc.7z
|
||||
#define VOBJECT_CREATE_FROMPNG 0x00020000 // replace file extension : sti -> png
|
||||
#define VOBJECT_CREATE_FROMJPC_FALLBACK 0x00100000 // replace file extension : sti -> jpc.7z, fall back to sti when it doesn't exist
|
||||
#define VOBJECT_CREATE_FROMPNG_FALLBACK 0x00200000 // replace file extension : sti -> png, fall back to sti when it doesn't exist
|
||||
|
||||
// VOBJECT FLAGS
|
||||
#define VOBJECT_FLAG_SHADETABLE_SHARED 0x00000100
|
||||
|
||||
// This structure is a video object.
|
||||
// The video object contains different data based on it's type, compressed or not
|
||||
typedef struct TAG_HVOBJECT
|
||||
{
|
||||
UINT32 fFlags; // Special flags
|
||||
UINT32 uiSizePixData; // ETRLE data size
|
||||
SGPPaletteEntry *pPaletteEntry; // 8BPP Palette
|
||||
COLORVAL TransparentColor; // Defaults to 0,0,0
|
||||
UINT16 *p16BPPPalette; // A 16BPP palette used for 8->16 blits
|
||||
|
||||
PTR pPixData; // ETRLE pixel data
|
||||
ETRLEObject *pETRLEObject; // Object offset data etc
|
||||
SixteenBPPObjectInfo *p16BPPObject;
|
||||
UINT16 *pShades[HVOBJECT_SHADE_TABLES]; // Shading tables
|
||||
UINT16 *pShadeCurrent;
|
||||
UINT16 *pGlow; // glow highlight table
|
||||
UINT8 *pShade8; // 8-bit shading index table
|
||||
UINT8 *pGlow8; // 8-bit glow table
|
||||
ZStripInfo **ppZStripInfo; // Z-value strip info arrays
|
||||
|
||||
UINT16 usNumberOf16BPPObjects;
|
||||
UINT16 usNumberOfObjects; // Total number of objects
|
||||
UINT8 ubBitDepth; // BPP
|
||||
SGPFILENAME ImageFile;
|
||||
} SGPVObject, *HVOBJECT;
|
||||
|
||||
|
||||
// This structure describes the creation parameters for a Video Object
|
||||
typedef struct
|
||||
{
|
||||
UINT32 fCreateFlags; // Specifies creation flags like from file or not
|
||||
union
|
||||
{
|
||||
//struct
|
||||
//{
|
||||
SGPFILENAME ImageFile; // Filename of image data to use
|
||||
//};
|
||||
//struct
|
||||
//{
|
||||
HIMAGE hImage;
|
||||
//};
|
||||
};
|
||||
UINT8 ubBitDepth; // BPP, ignored if given from file
|
||||
} VOBJECT_DESC;
|
||||
|
||||
// **********************************************************************************
|
||||
//
|
||||
// Video Object Manager Functions
|
||||
//
|
||||
// **********************************************************************************
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
// Creates a list to contain video objects
|
||||
BOOLEAN InitializeVideoObjectManager( );
|
||||
|
||||
int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep);
|
||||
|
||||
// Deletes any video object placed into list
|
||||
BOOLEAN ShutdownVideoObjectManager( );
|
||||
|
||||
// Creates and adds a video object to list
|
||||
#ifdef SGP_VIDEO_DEBUGGING
|
||||
void PerformVideoInfoDumpIntoFile( const STR8 filename, BOOLEAN fAppend );
|
||||
void DumpVObjectInfoIntoFile( const STR8 filename, BOOLEAN fAppend );
|
||||
BOOLEAN _AddAndRecordVObject( VOBJECT_DESC *VObjectDesc, UINT32 *uiIndex, UINT32 uiLineNum, const STR8 pSourceFile );
|
||||
#define AddVideoObject( a, b ) _AddAndRecordVObject( a, b, __LINE__, __FILE__ )
|
||||
#else
|
||||
#define AddVideoObject( a, b ) AddStandardVideoObject( a, b )
|
||||
#endif
|
||||
|
||||
BOOLEAN AddStandardVideoObject( VOBJECT_DESC *VObjectDesc, UINT32 *uiIndex );
|
||||
|
||||
// Removes a video object
|
||||
BOOLEAN DeleteVideoObjectFromIndex( UINT32 uiVObject );
|
||||
|
||||
UINT16 CreateObjectPaletteTables(HVOBJECT pObj, UINT32 uiType);
|
||||
|
||||
// Returns a HVOBJECT for the specified index
|
||||
BOOLEAN GetVideoObject( HVOBJECT *hVObject, UINT32 uiIndex );
|
||||
|
||||
// Blits a video object to another video object
|
||||
BOOLEAN BltVideoObject( UINT32 uiDestVSurface,
|
||||
HVOBJECT hVSrcObject,
|
||||
UINT16 usRegionIndex,
|
||||
INT32 iDestX,
|
||||
INT32 iDestY,
|
||||
UINT32 fBltFlags,
|
||||
blt_fx *pBltFx );
|
||||
BOOLEAN BltVideoObject(UINT32 uiDestVSurface, HVOBJECT hSrcVObject, UINT16 usRegionIndex, SGPRectangle Region, UINT32 fBltFlags, blt_fx* pBltFx);
|
||||
|
||||
BOOLEAN BltVideoObjectFromIndex( UINT32 uiDestVSurface,
|
||||
UINT32 uiSrcVObject,
|
||||
UINT16 usRegionIndex,
|
||||
INT32 iDestX,
|
||||
INT32 iDestY,
|
||||
UINT32 fBltFlags,
|
||||
blt_fx *pBltFx );
|
||||
|
||||
// Sets transparency
|
||||
BOOLEAN SetVideoObjectTransparency( UINT32 uiIndex, COLORVAL TransColor );
|
||||
|
||||
|
||||
// **********************************************************************************
|
||||
//
|
||||
// Video Object manipulation functions
|
||||
//
|
||||
// **********************************************************************************
|
||||
|
||||
|
||||
// Created from a VOBJECT_DESC structure. Can be from a file via HIMAGE or empty.
|
||||
HVOBJECT CreateVideoObject( VOBJECT_DESC *VObjectDesc );
|
||||
|
||||
// Sets Transparency color into HVOBJECT
|
||||
BOOLEAN SetVideoObjectTransparencyColor( HVOBJECT hVObject, COLORVAL TransColor );
|
||||
|
||||
// Sets HVOBJECT palette, creates if nessessary. Also sets 16BPP palette
|
||||
BOOLEAN SetVideoObjectPalette( HVOBJECT hVObject, SGPPaletteEntry *pSrcPalette );
|
||||
|
||||
// Deletes all data
|
||||
BOOLEAN DeleteVideoObject( HVOBJECT hVObject );
|
||||
|
||||
// Deletes the 16-bit palette tables
|
||||
BOOLEAN DestroyObjectPaletteTables(HVOBJECT hVObject);
|
||||
|
||||
// Sets the current object shade table
|
||||
UINT16 SetObjectShade(HVOBJECT pObj, UINT32 uiShade);
|
||||
|
||||
// Sets the current object shade table using a vobject handle
|
||||
UINT16 SetObjectHandleShade(UINT32 uiHandle, UINT32 uiShade);
|
||||
|
||||
// Fills a rectangular area of an object with a color
|
||||
UINT16 FillObjectRect(UINT32 iObj, INT32 x1, INT32 y1, INT32 x2, INT32 y2, COLORVAL color32);
|
||||
|
||||
// Retrieves an HVOBJECT pixel value
|
||||
BOOLEAN GetETRLEPixelValue( UINT8 * pDest, HVOBJECT hVObject, UINT16 usETLREIndex, UINT16 usX, UINT16 usY );
|
||||
|
||||
|
||||
// ****************************************************************************
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
// ****************************************************************************
|
||||
//
|
||||
// Macros
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
extern BOOLEAN gfVideoObjectsInit;
|
||||
#define VideoObjectsInitialized() (gfVideoObjectsInit)
|
||||
|
||||
// ****************************************************************************
|
||||
//
|
||||
// Blt Functions
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
// These blitting functions more-or less encapsolate all of the functionality of DirectDraw
|
||||
// Blitting, giving an API layer for portability.
|
||||
|
||||
BOOLEAN BltVideoObjectToBuffer( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, UINT16 usIndex, INT32 iDestX, INT32 iDestY, INT32 fBltFlags, blt_fx *pBltFx );
|
||||
|
||||
HVOBJECT GetPrimaryVideoObject( );
|
||||
HVOBJECT GetBackBufferVideoObject( );
|
||||
|
||||
BOOLEAN GetVideoObjectETRLEProperties( HVOBJECT hVObject, ETRLEObject *pETRLEObject, UINT16 usIndex );
|
||||
BOOLEAN GetVideoObjectETRLEPropertiesFromIndex( UINT32 uiVideoObject, ETRLEObject *pETRLEObject, UINT16 usIndex );
|
||||
BOOLEAN GetVideoObjectETRLESubregionProperties( UINT32 uiVideoObject, UINT16 usIndex, UINT16 *pusWidth, UINT16 *pusHeight );
|
||||
|
||||
BOOLEAN SetVideoObjectPalette8BPP(INT32 uiVideoObject, SGPPaletteEntry *pPal8);
|
||||
BOOLEAN SetVideoObjectPalette16BPP(INT32 uiVideoObject, UINT16 *pPal16);
|
||||
BOOLEAN GetVideoObjectPalette16BPP(INT32 uiVideoObject, UINT16 **ppPal16);
|
||||
BOOLEAN CopyVideoObjectPalette16BPP(INT32 uiVideoObject, UINT16 *ppPal16);
|
||||
|
||||
BOOLEAN ConvertVObjectRegionTo16BPP( HVOBJECT hVObject, UINT16 usRegionIndex, UINT8 ubShadeLevel );
|
||||
BOOLEAN CheckFor16BPPRegion( HVOBJECT hVObject, UINT16 usRegionIndex, UINT8 ubShadeLevel, UINT16 * pusIndex );
|
||||
|
||||
BOOLEAN BltVideoObjectOutlineFromIndex(UINT32 uiDestVSurface, UINT32 uiSrcVObject, UINT16 usIndex, INT32 iDestX, INT32 iDestY, INT16 s16BPPColor, BOOLEAN fDoOutline );
|
||||
BOOLEAN BltVideoObjectOutline(UINT32 uiDestVSurface, HVOBJECT hSrcVObject, UINT16 usIndex, INT32 iDestX, INT32 iDestY, INT16 s16BPPColor, BOOLEAN fDoOutline );
|
||||
BOOLEAN BltVideoObjectOutlineShadowFromIndex(UINT32 uiDestVSurface, UINT32 uiSrcVObject, UINT16 usIndex, INT32 iDestX, INT32 iDestY );
|
||||
BOOLEAN BltVideoObjectOutlineShadow(UINT32 uiDestVSurface, HVOBJECT hSrcVObject, UINT16 usIndex, INT32 iDestX, INT32 iDestY );
|
||||
BOOLEAN PixelateVideoObjectRect( UINT32 uiDestVSurface, INT32 X1, INT32 Y1, INT32 X2, INT32 Y2);
|
||||
|
||||
// Flugente: retrieve width and height of video object
|
||||
void GetVideoObjectDimensions( HVOBJECT hSrcVObject, UINT16 usIndex, UINT16& rusWidth, UINT16& rusHeight );
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,237 @@
|
||||
#ifndef __VOBJECT_BLITTERS
|
||||
#define __VOBJECT_BLITTERS
|
||||
|
||||
#include "shading.h"
|
||||
#include "vsurface.h"
|
||||
#include "vobject.h"
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
|
||||
class ClipRectangle
|
||||
{
|
||||
public:
|
||||
enum ClipType
|
||||
{
|
||||
NoClip, PartialClip, FullClip,
|
||||
};
|
||||
public:
|
||||
ClipRectangle();
|
||||
|
||||
void SetRect(SGPRect const& rect);
|
||||
void SetRect(unsigned int w, unsigned int h, int x=0, int y=0);
|
||||
void Set(int x1, int y1, int x2, int y2);
|
||||
|
||||
/**
|
||||
* @returns:
|
||||
* NoClip : value references are not modified
|
||||
* FullClip : value references are not modified, as the values lie completely outside. Why bother doing the extra work.
|
||||
* PartialClip : value references are modified
|
||||
*/
|
||||
ClipType Clip(int& x, int& y, unsigned int& w, unsigned int& h);
|
||||
ClipType Clip(int& x1, int& y1, int& x2, int& y2);
|
||||
private:
|
||||
SGPRect cr;
|
||||
};
|
||||
|
||||
extern SGPRect ClippingRect;
|
||||
extern UINT32 guiTranslucentMask;
|
||||
extern UINT16 White16BPPPalette[ 256 ];
|
||||
|
||||
unsigned short blendWithAlpha(unsigned int rgb565New, unsigned int rgb565Old, unsigned int alpha);
|
||||
|
||||
extern void SetClippingRect(SGPRect *clip);
|
||||
void GetClippingRect(SGPRect *clip);
|
||||
|
||||
BOOLEAN BltIsClipped(HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
CHAR8 BltIsClippedOrOffScreen( HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion );
|
||||
|
||||
|
||||
UINT16 *InitZBuffer(UINT32 uiPitch, UINT32 uiHeight);
|
||||
BOOLEAN ShutdownZBuffer(UINT16 *pBuffer);
|
||||
|
||||
// 8-Bit to 8-Bit Blitters
|
||||
|
||||
//BOOLEAN Blt8BPPDataTo8BPPBufferTransZIncClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZNBColor( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT8 ubColor);
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZNBClipColor( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT8 ubColor);
|
||||
|
||||
// pixelation blitters
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZPixelate( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZClipPixelate( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZNBPixelate( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZNBClipPixelate( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferMonoShadowClip( UINT8 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT8 ubForeground, UINT8 ubBackground);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransparent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransparentClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransMirror( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZ( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZNB( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransZNBClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferShadowZ( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferShadowZNB( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferShadowZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferShadowZNBClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransShadowZ( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette );
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransShadowZNB( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette );
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransShadowZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette );
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferTransShadowZNBClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette );
|
||||
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferShadowClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo8BPPBufferShadow( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo8BPPBuffer( UINT8 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
|
||||
// 8-Bit to 16-Bit Blitters
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZNBColor( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 usColor);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZNBClipColor( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 usColor);
|
||||
|
||||
// pixelation blitters
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZPixelate( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZClipPixelate( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZNBPixelate( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZNBClipPixelate( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
|
||||
|
||||
// translucency blitters
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZTranslucent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZClipTranslucent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZNBTranslucent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZNBClipTranslucent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferMonoShadowClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 usForeground, UINT16 usBackground, UINT16 usShadow );
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZ( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZNB( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZNBClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZ(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowClip(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowClipAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNB(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNBAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferShadowZNB( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferShadowZNBClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferShadowZ( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferShadowZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZClip(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZClipAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNBClip(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNBClipAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
|
||||
// Next blitters are for blitting mask as intensity
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferIntensityZNB( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferIntensityZNBClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferIntensityZ( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferIntensityZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferIntensityClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferIntensity( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransparentClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransparent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadow(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferShadowClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN DDBlt8BPPDataTo16BPPBufferShadow( HVOBJECT hDestVObject, HVOBJECT hSrcVObject, UINT8 level, COLORVAL maskrgb, UINT16 usX, UINT16 usY, SGPRect *srcRect);
|
||||
|
||||
BOOLEAN Blt8BPPTo8BPP(UINT8 *pDest, UINT32 uiDestPitch, UINT8 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight);
|
||||
BOOLEAN Blt16BPPTo16BPP(UINT16 *pDest, UINT32 uiDestPitch, UINT16 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight);
|
||||
BOOLEAN Blt16BPPTo16BPPTrans(UINT16 *pDest, UINT32 uiDestPitch, UINT16 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight, UINT16 usTrans);
|
||||
BOOLEAN Blt16BPPTo16BPPTransShadow(UINT16 *pDest, UINT32 uiDestPitch, UINT16 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight, UINT16 usTrans);
|
||||
BOOLEAN Blt16BPPTo16BPPFog(UINT16 *pDest, UINT32 uiDestPitch, UINT16 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight, UINT8 *pFog, UINT16 usFogPitch);
|
||||
BOOLEAN Blt16BPPTo16BPPMirror(UINT16 *pDest, UINT32 uiDestPitch, UINT16 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferFogZ( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferFogZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferFogZNB( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferFogZNBClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
|
||||
BOOLEAN Blt16BPPBufferPixelateRectWithColor( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, SGPRect *area, UINT8 Pattern[8][8], UINT16 usColor );
|
||||
BOOLEAN Blt16BPPBufferPixelateRect(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, SGPRect *area, UINT8 Pattern[8][8]);
|
||||
|
||||
//A wrapper for the Blt16BPPBufferPixelateRect that automatically passes a hatch pattern.
|
||||
BOOLEAN Blt16BPPBufferHatchRectWithColor(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, SGPRect *area, UINT16 usColor );
|
||||
BOOLEAN Blt16BPPBufferHatchRect(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, SGPRect *area );
|
||||
BOOLEAN Blt16BPPBufferLooseHatchRectWithColor(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, SGPRect *area, UINT16 usColor );
|
||||
BOOLEAN Blt16BPPBufferLooseHatchRect(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, SGPRect *area );
|
||||
|
||||
BOOLEAN Blt16BPPBufferShadowRect(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, SGPRect *area);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferShadow( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBuffer( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVSURFACE hSrcVSurface, UINT8 *pSrcBuffer, INT32 iX, INT32 iY);
|
||||
BOOLEAN Blt8BPPDataSubTo16BPPBuffer( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVSURFACE hSrcVSurface, UINT8 *pSrcBuffer, UINT32 uiSrcPitch, INT32 iX, INT32 iY, SGPRect *pRect);
|
||||
|
||||
// Blits from flat 8bpp source, to 16bpp dest, divides in half
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferHalf( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVSURFACE hSrcVSurface, UINT8 *pSrcBuffer, UINT32 uiSrcPitch, INT32 iX, INT32 iY);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferHalfRect( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVSURFACE hSrcVSurface, UINT8 *pSrcBuffer, UINT32 uiSrcPitch, INT32 iX, INT32 iY, SGPRect *pRect);
|
||||
|
||||
BOOLEAN DDBlt8BPPDataTo16BPPBuffer( HVOBJECT hDestVObject, HVOBJECT hSrcVObject, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
BOOLEAN DDBlt8BPPDataTo16BPPBufferFullTransparent( HVOBJECT hDestVObject, HVOBJECT hSrcVObject, UINT16 usX, UINT16 usY, SGPRect *srcRect );
|
||||
BOOLEAN DDFillSurface( HVOBJECT hDestVObject, blt_fx *pBltFx );
|
||||
BOOLEAN DDFillSurfaceRect( HVOBJECT hDestVObject, blt_fx *pBltFx );
|
||||
BOOLEAN BltVObjectUsingDD( HVOBJECT hDestVObject, HVOBJECT hSrcVObject, UINT32 fBltFlags, INT32 iDestX, INT32 iDestY, RECT *SrcRect );
|
||||
|
||||
|
||||
BOOLEAN BlitZRect(UINT16 *pZBuffer, UINT32 uiPitch, INT16 sLeft, INT16 sTop, INT16 sRight, INT16 sBottom, UINT16 usZValue);
|
||||
|
||||
// New 16/16 blitters
|
||||
|
||||
BOOLEAN Blt32BPPTo16BPPTrans(UINT16 *pDest, UINT32 uiDestPitch, UINT32 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight);
|
||||
BOOLEAN Blt32BPPTo16BPPTransShadow(UINT16 *pDest, UINT32 uiDestPitch, UINT32 *pSrc, UINT32 uiSrcPitch, INT32 iDestXPos, INT32 iDestYPos, INT32 iSrcXPos, INT32 iSrcYPos, UINT32 uiWidth, UINT32 uiHeight);
|
||||
|
||||
BOOLEAN Blt16BPPDataTo16BPPBufferTransparentClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt16BPPDataTo16BPPBufferTransZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt16BPPDataTo16BPPBufferTransparent( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
// ATE: New blitters for showing an outline at color 254
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutline( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, INT16 s16BPPColor, BOOLEAN fDoOutline );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutlineClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, INT16 s16BPPColor, BOOLEAN fDoOutline, SGPRect *clipregion );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutlineZ( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, INT16 s16BPPColor, BOOLEAN fDoOutline );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutlineShadow( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutlineShadowClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutlineZNB( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, INT16 s16BPPColor, BOOLEAN fDoOutline );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutlineZPixelateObscured( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, INT16 s16BPPColor, BOOLEAN fDoOutline );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutlineZPixelateObscuredClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, INT16 s16BPPColor, BOOLEAN fDoOutline, SGPRect *clipregion );
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferOutlineZClip( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, INT16 s16BPPColor, BOOLEAN fDoOutline, SGPRect *clipregion );
|
||||
|
||||
|
||||
// ATE: New blitter for included shadow, but pixellate if obscured by z
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNBObscured(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows = FALSE);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNBObscuredTest(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows = FALSE);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNBObscuredAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows = FALSE);
|
||||
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNBObscuredClip(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransShadowZNBObscuredClipAlpha(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, HVOBJECT hAlphaVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion, UINT16 *p16BPPPalette, BOOLEAN fIgnoreShadows);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZClipPixelateObscured( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex, SGPRect *clipregion);
|
||||
BOOLEAN Blt8BPPDataTo16BPPBufferTransZPixelateObscured( UINT16 *pBuffer, UINT32 uiDestPitchBYTES, UINT16 *pZBuffer, UINT16 usZValue, HVOBJECT hSrcVObject, INT32 iX, INT32 iY, UINT16 usIndex );
|
||||
|
||||
BOOLEAN FillRect8BPP(UINT8 *pBuffer, UINT32 uiDestPitchBYTES, INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT8 color);
|
||||
BOOLEAN FillRect16BPP(UINT16 *pBuffer, UINT32 uiDestPitchBYTES, INT32 x1, INT32 y1, INT32 x2, INT32 y2, UINT16 color);
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
+2803
File diff suppressed because it is too large
Load Diff
+288
@@ -0,0 +1,288 @@
|
||||
#ifndef __VSURFACE_H
|
||||
#define __VSURFACE_H
|
||||
|
||||
#include "types.h"
|
||||
#include "himage.h"
|
||||
#include "vobject.h"
|
||||
#include <vector>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Video Surface SGP Module
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Defines for special video object handles given to blit function
|
||||
//
|
||||
|
||||
#define PRIMARY_SURFACE 0xFFFFFFF0
|
||||
#define BACKBUFFER 0xFFFFFFF1
|
||||
#define FRAME_BUFFER 0xFFFFFFF2
|
||||
#define MOUSE_BUFFER 0xFFFFFFF3
|
||||
|
||||
//
|
||||
// Defines for blitting
|
||||
//
|
||||
|
||||
#define VS_BLT_COLORFILL 0x000000020
|
||||
#define VS_BLT_USECOLORKEY 0x000000002
|
||||
#define VS_BLT_USEDESTCOLORKEY 0x000000200
|
||||
#define VS_BLT_FAST 0x000000004
|
||||
#define VS_BLT_CLIPPED 0x000000008
|
||||
#define VS_BLT_SRCREGION 0x000000010
|
||||
#define VS_BLT_DESTREGION 0x000000080
|
||||
#define VS_BLT_SRCSUBRECT 0x000000040
|
||||
#define VS_BLT_COLORFILLRECT 0x000000100
|
||||
#define VS_BLT_MIRROR_Y 0x000001000
|
||||
|
||||
//
|
||||
// Effects structure for specialized blitting
|
||||
//
|
||||
|
||||
typedef struct
|
||||
{
|
||||
COLORVAL ColorFill; // Used for fill effect
|
||||
SGPRect SrcRect; // Given SRC subrect instead of srcregion
|
||||
SGPRect FillRect; // Given SRC subrect instead of srcregion
|
||||
UINT16 DestRegion; // Given a DEST region for dest positions within the VO
|
||||
|
||||
} blt_vs_fx;
|
||||
|
||||
//
|
||||
// Video Surface Flags
|
||||
// Used to describe the memory usage of a video Surface
|
||||
//
|
||||
|
||||
#define VSURFACE_DEFAULT_MEM_USAGE 0x00000001 // Default mem usage is same as DD, try video and then try system. Will usually work
|
||||
#define VSURFACE_VIDEO_MEM_USAGE 0x00000002 // Will force surface into video memory and will fail if it can't
|
||||
#define VSURFACE_SYSTEM_MEM_USAGE 0x00000004 // Will force surface into system memory and will fail if it can't
|
||||
#define VSURFACE_RESERVED_SURFACE 0x00000100 // Reserved for special purposes, like a primary surface
|
||||
|
||||
//
|
||||
// Video Surface creation flags
|
||||
// Used in the VSurface_DESC structure to describe creation flags
|
||||
//
|
||||
|
||||
#define VSURFACE_CREATE_DEFAULT 0x00000020 // Creates and empty Surface of given width, height and BPP
|
||||
#define VSURFACE_CREATE_FROMFILE 0x00000040 // Creates a video Surface from a file ( using HIMAGE )
|
||||
|
||||
#define VSURFACE_CREATE_FROMJPC 0x00010000 // replace file extension : sti -> jpc.7z
|
||||
#define VSURFACE_CREATE_FROMPNG 0x00020000 // replace file extension : sti -> png
|
||||
#define VSURFACE_CREATE_FROMJPC_FALLBACK 0x00100000 // replace file extension : sti -> jpc.7z, fall back to sti when it doesn't exist
|
||||
#define VSURFACE_CREATE_FROMPNG_FALLBACK 0x00200000 // replace file extension : sti -> png, fall back to sti when it doesn't exist
|
||||
|
||||
//
|
||||
// The following structure is used to define a region of the video Surface
|
||||
// These regions are stored via a HLIST
|
||||
//
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SGPRect RegionCoords; // Rectangle describing coordinates of region
|
||||
SGPPoint Origin; // Origin used for hot spots, etc
|
||||
UINT8 ubHitMask; // Byte flags for hit detection
|
||||
|
||||
} VSURFACE_REGION;
|
||||
|
||||
//
|
||||
// This structure is a video Surface. Contains a HLIST of regions
|
||||
//
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT16 usHeight; // Height of Video Surface
|
||||
UINT16 usWidth; // Width of Video Surface
|
||||
UINT8 ubBitDepth; // BPP ALWAYS 16!
|
||||
PTR pSurfaceData; // A void pointer, but for this implementation, is really a lpDirectDrawSurface;
|
||||
PTR pSurfaceData1; // Direct Draw One Interface
|
||||
PTR pSavedSurfaceData1; // A void pointer, but for this implementation, is really a lpDirectDrawSurface;
|
||||
// pSavedSurfaceData is used to hold all video memory Surfaces so that they my be restored
|
||||
PTR pSavedSurfaceData; // A void pointer, but for this implementation, is really a lpDirectDrawSurface;
|
||||
// pSavedSurfaceData is used to hold all video memory Surfaces so that they my be restored
|
||||
UINT32 fFlags; // Used to describe memory usage, etc
|
||||
PTR pPalette; // A void pointer, but for this implementation a DDPalette
|
||||
UINT16 *p16BPPPalette; // A 16BPP palette used for 8->16 blits
|
||||
COLORVAL TransparentColor; // Defaults to 0,0,0
|
||||
PTR pClipper; // A void pointer encapsolated as a clipper Surface
|
||||
std::vector<VSURFACE_REGION> RegionList; // A List of regions within the video Surface
|
||||
|
||||
} SGPVSurface, *HVSURFACE;
|
||||
|
||||
//
|
||||
// This structure describes the creation parameters for a Video Surface
|
||||
//
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT32 fCreateFlags; // Specifies creation flags like from file or not
|
||||
SGPFILENAME ImageFile; // Filename of image data to use
|
||||
UINT32 usWidth; // Width, ignored if given from file
|
||||
UINT32 usHeight; // Height, ignored if given from file
|
||||
UINT8 ubBitDepth; // BPP, ignored if given from file
|
||||
|
||||
} VSURFACE_DESC;
|
||||
|
||||
namespace SurfaceData
|
||||
{
|
||||
typedef unsigned long tID;
|
||||
BYTE* SetApplicationData(BYTE* data);
|
||||
void ReleaseApplicationData(BYTE* data);
|
||||
|
||||
tID GetSurfaceID(BYTE* data);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Video Surface Manager Functions
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
*/
|
||||
extern INT32 giMemUsedInSurfaces;
|
||||
|
||||
// Creates a list to contain video Surfaces
|
||||
BOOLEAN InitializeVideoSurfaceManager( );
|
||||
|
||||
// Deletes any video Surface placed into list
|
||||
BOOLEAN ShutdownVideoSurfaceManager( );
|
||||
|
||||
// Restores all video Surfaces in list
|
||||
BOOLEAN RestoreVideoSurfaces( );
|
||||
|
||||
// Creates and adds a video Surface to list
|
||||
#ifdef SGP_VIDEO_DEBUGGING
|
||||
void DumpVSurfaceInfoIntoFile( const STR8 filename, BOOLEAN fAppend );
|
||||
extern BOOLEAN _AddAndRecordVSurface( VSURFACE_DESC *VSurfaceDesc, UINT32 *uiIndex, UINT32 uiLineNum, const STR8 pSourceFile );
|
||||
#define AddVideoSurface( a, b ) _AddAndRecordVSurface( a, b, __LINE__, __FILE__ )
|
||||
#else
|
||||
#define AddVideoSurface( a, b ) AddStandardVideoSurface( a, b )
|
||||
#endif
|
||||
|
||||
BOOLEAN AddStandardVideoSurface( VSURFACE_DESC *VSurfaceDesc, UINT32 *uiIndex );
|
||||
|
||||
// Returns a HVSurface for the specified index
|
||||
BOOLEAN GetVideoSurface( HVSURFACE *hVSurface, UINT32 uiIndex );
|
||||
|
||||
BYTE *LockVideoSurface( UINT32 uiVSurface, UINT32 *uiPitch );
|
||||
void UnLockVideoSurface( UINT32 uiVSurface );
|
||||
|
||||
// Blits a video Surface to another video Surface
|
||||
BOOLEAN BltVideoSurface(UINT32 uiDestVSurface, UINT32 uiSrcVSurface, UINT16 usRegionIndex, INT32 iDestX, INT32 iDestY, UINT32 fBltFlags, blt_vs_fx *pBltFx );
|
||||
|
||||
BOOLEAN ColorFillVideoSurfaceArea(UINT32 uiDestVSurface, INT32 iDestX1, INT32 iDestY1, INT32 iDestX2, INT32 iDestY2, UINT16 Color16BPP);
|
||||
|
||||
BOOLEAN ImageFillVideoSurfaceArea(UINT32 uiDestVSurface, INT32 iDestX1, INT32 iDestY1, INT32 iDestX2, INT32 iDestY2, HVOBJECT BkgrndImg, UINT16 Index, INT16 Ox, INT16 Oy);
|
||||
|
||||
// This function sets the global video Surfaces for primary and backbuffer
|
||||
BOOLEAN SetPrimaryVideoSurfaces( );
|
||||
|
||||
// Sets transparency
|
||||
BOOLEAN SetVideoSurfaceTransparency( UINT32 uiIndex, COLORVAL TransColor );
|
||||
|
||||
// Adds a video Surface region
|
||||
BOOLEAN AddVideoSurfaceRegion( UINT32 uiIndex, VSURFACE_REGION *pNewRegion );
|
||||
|
||||
// Gets width, hight, bpp information
|
||||
BOOLEAN GetVideoSurfaceDescription( UINT32 uiIndex, UINT16 *usWidth, UINT16 *usHeight, UINT8 *ubBitDepth );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Video Surface manipulation functions
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Darkens a rectangular area on a surface for menus etc.
|
||||
BOOLEAN PixelateVideoSurfaceRect( UINT32 uiDestVSurface, INT32 X1, INT32 Y1, INT32 X2, INT32 Y2);
|
||||
|
||||
// Created from a VSurface_DESC structure. Can be from a file via HIMAGE or empty.
|
||||
HVSURFACE CreateVideoSurface( VSURFACE_DESC *VSurfaceDesc );
|
||||
|
||||
// Gets the RGB palette entry values
|
||||
BOOLEAN GetVSurfacePaletteEntries( HVSURFACE hVSurface, SGPPaletteEntry *pPalette );
|
||||
|
||||
BOOLEAN RestoreVideoSurface( HVSURFACE hVSurface );
|
||||
|
||||
// Returns a flat pointer for direct manipulation of data
|
||||
BYTE *LockVideoSurfaceBuffer( HVSURFACE hVSurface, UINT32 *pPitch );
|
||||
|
||||
// Must be called after Locking buffer call above
|
||||
void UnLockVideoSurfaceBuffer( HVSURFACE hVSurface );
|
||||
|
||||
// Set data from HIMAGE.
|
||||
BOOLEAN SetVideoSurfaceDataFromHImage( HVSURFACE hVSurface, HIMAGE hImage, UINT16 usX, UINT16 usY, SGPRect *pSrcRect );
|
||||
|
||||
// Sets Transparency color into HVSurface and the underlying DD surface
|
||||
BOOLEAN SetVideoSurfaceTransparencyColor( HVSURFACE hVSurface, COLORVAL TransColor );
|
||||
|
||||
// Sets HVSurface palette, creates if nessessary. Also sets 16BPP palette
|
||||
BOOLEAN SetVideoSurfacePalette( HVSURFACE hVSurface, SGPPaletteEntry *pSrcPalette );
|
||||
|
||||
// Used if it's in video memory, will re-load backup copy
|
||||
//BOOLEAN RestoreVideoSurface( HVSurface hVSurface );
|
||||
|
||||
// Deletes all data, including palettes, regions, DD Surfaces
|
||||
BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface );
|
||||
BOOLEAN DeleteVideoSurfaceFromIndex( UINT32 uiIndex );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Region manipulation functions
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Regions will allow creation of sections within the Surface to manipulate quickly and cleanly
|
||||
// An example would be a cursor tileset
|
||||
BOOLEAN AddVSurfaceRegion( HVSURFACE hVSurface, VSURFACE_REGION *pNewRegion );
|
||||
BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *pNewRegion );
|
||||
BOOLEAN AddVSurfaceRegions( HVSURFACE hVSurface, VSURFACE_REGION **ppNewRegions, UINT16 uiNumRegions );
|
||||
BOOLEAN ClearAllVSurfaceRegions( HVSURFACE hVSurface );
|
||||
BOOLEAN GetVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *aRegion );
|
||||
BOOLEAN GetNumRegions( HVSURFACE hVSurface , UINT32 *puiNumRegions );
|
||||
BOOLEAN ReplaceVSurfaceRegion( HVSURFACE hVSurface , UINT16 usIndex, VSURFACE_REGION *aRegion );
|
||||
BOOLEAN DeleteVideoSurfaceFromIndex( UINT32 uiIndex );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Clipper manipulation functions
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOLEAN SetClipList( HVSURFACE hVSurface, SGPRect *RegionData, UINT16 usNumRegions );
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Blt Functions
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// These blitting functions more-or less encapsolate all of the functionality of DirectDraw
|
||||
// Blitting, giving an API layer for portability.
|
||||
|
||||
BOOLEAN BltVideoSurfaceToVideoSurface( HVSURFACE hDestVSurface, HVSURFACE hSrcVSurface, UINT16 usIndex, INT32 iDestX, INT32 iDestY, INT32 fBltFlags, blt_vs_fx *pBltFx );
|
||||
|
||||
HVSURFACE GetPrimaryVideoSurface( );
|
||||
HVSURFACE GetBackBufferVideoSurface( );
|
||||
|
||||
BOOLEAN ShadowVideoSurfaceRect( UINT32 uiDestVSurface, INT32 X1, INT32 Y1, INT32 X2, INT32 Y2);
|
||||
BOOLEAN ShadowVideoSurfaceImage( UINT32 uiDestVSurface, HVOBJECT hImageHandle, INT32 iPosX, INT32 iPosY);
|
||||
|
||||
// If the Dest Rect and the source rect are not the same size, the source surface will be either
|
||||
//enlraged or shunk.
|
||||
BOOLEAN BltStretchVideoSurface(UINT32 uiDestVSurface, UINT32 uiSrcVSurface, INT32 iDestX, INT32 iDestY, UINT32 fBltFlags, SGPRect *SrcRect, SGPRect *DestRect );
|
||||
|
||||
BOOLEAN MakeVSurfaceFromVObject(UINT32 uiVObject, UINT16 usSubIndex, UINT32 *puiVSurface);
|
||||
|
||||
BOOLEAN ShadowVideoSurfaceRectUsingLowPercentTable( UINT32 uiDestVSurface, INT32 X1, INT32 Y1, INT32 X2, INT32 Y2);
|
||||
|
||||
/*
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef __VSURFACE_PRIVATE_
|
||||
#define __VSURFACE_PRIVATE_
|
||||
|
||||
// ***********************************************************************
|
||||
//
|
||||
// PRIVATE, INTERNAL Header used by other SGP Internal modules
|
||||
//
|
||||
// Allows direct access to underlying Direct Draw Implementation
|
||||
//
|
||||
// ***********************************************************************
|
||||
|
||||
LPDIRECTDRAWSURFACE2 GetVideoSurfaceDDSurface( HVSURFACE hVSurface );
|
||||
LPDIRECTDRAWSURFACE GetVideoSurfaceDDSurfaceOne( HVSURFACE hVSurface );
|
||||
LPDIRECTDRAWPALETTE GetVideoSurfaceDDPalette( HVSURFACE hVSurface );
|
||||
|
||||
HVSURFACE CreateVideoSurfaceFromDDSurface( LPDIRECTDRAWSURFACE2 lpDDSurface );
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user