Merge remote-tracking branch 'upstream/master' into nev6502_branch

This commit is contained in:
nev6502
2020-06-20 15:48:25 -06:00
17 changed files with 211 additions and 84 deletions
+27 -15
View File
@@ -46,7 +46,7 @@
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
#include "image.h"
static TemplateTypeClass const Empty(
TEMPLATE_CLEAR1,
@@ -3137,7 +3137,16 @@ void TemplateTypeClass::Init(TheaterType theater)
((unsigned char &)tplate.Width) = Get_IconSet_MapWidth(ptr);
((unsigned char &)tplate.Height) = Get_IconSet_MapHeight(ptr);
// Try and load HD assets first.
Image_t *hdImage = Load_StampHD(Theaters[theater].Name, fullname, tplate.ImageData);
if (hdImage)
{
Get_Stamp_Size(tplate.ImageData, hdImage->renderwidth, hdImage->renderheight);
((void const*&)tplate.HDImageData) = hdImage;
}
else
{
// If no HD assets, load the legacy assets into a texture.
char tmp[512];
sprintf(tmp, "icon_%s", fullname);
((void const*&)tplate.HDImageData) = Load_Stamp(fullname, tplate.ImageData);
@@ -3189,20 +3198,23 @@ void TemplateTypeClass::Display(int x, int y, WindowNumberType window, HousesTyp
for (index = 0; index < w*h; index++) {
if (map[index] != 0xFF) {
HidPage.Draw_Stamp(iconset, index, 0, 0, NULL, WINDOW_MAIN);
Buffer_Enable_HD_Texture(true); // At this point, Draw_Stamp creates a 32bit image.
if (scale) {
HidPage.Scale((*LogicPage), 0, 0,
x + ((index % w)*(ICON_PIXEL_W/2)),
y + ((index / w)*(ICON_PIXEL_H/2)),
ICON_PIXEL_W, ICON_PIXEL_H,
ICON_PIXEL_W/2, ICON_PIXEL_H/2, (char *)NULL);
} else {
HidPage.Blit((*LogicPage), 0, 0, x + ((index % w)*(ICON_PIXEL_W)),
y + ((index / w)*(ICON_PIXEL_H)), ICON_PIXEL_W, ICON_PIXEL_H);
}
Buffer_Enable_HD_Texture(false);
// jmarshall - even if using legacy data, always use hdimage.
HidPage.Draw_Stamp(Get_HDImage_Data(), index, 0, 0, NULL, WINDOW_MAIN);
// Disabled legacy blit code.
//Buffer_Enable_HD_Texture(true); // At this point, Draw_Stamp creates a 32bit image.
//if (scale) {
// HidPage.Scale((*LogicPage), 0, 0,
// x + ((index % w)*(ICON_PIXEL_W/2)),
// y + ((index / w)*(ICON_PIXEL_H/2)),
// ICON_PIXEL_W, ICON_PIXEL_H,
// ICON_PIXEL_W/2, ICON_PIXEL_H/2, (char *)NULL);
//
//} else {
// HidPage.Blit((*LogicPage), 0, 0, x + ((index % w)*(ICON_PIXEL_W)),
// y + ((index / w)*(ICON_PIXEL_H)), ICON_PIXEL_W, ICON_PIXEL_H);
//}
//Buffer_Enable_HD_Texture(false);
// jmarshall end
}
}
}
+1 -1
View File
@@ -1638,7 +1638,7 @@ void Color_Cycle(void)
*=============================================================================================*/
void Call_Back(void)
{
WWSDL_ProcessEvents(g_globalKeyNumType, g_globalKeyFlags);
Device_Present();
/*
** Music and speech maintenance
+3 -3
View File
@@ -859,9 +859,9 @@ void Show_Who_Was_Responsible (void)
** If user hits escape then break.
*/
KeyNumType _key = KN_NONE;
int _flags;
WWSDL_ProcessEvents(_key, _flags);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
key = Keyboard->Check();
+2
View File
@@ -501,6 +501,8 @@ KeyNumType GadgetClass::Input(void)
*/
// jmarshall
int flags = g_globalKeyFlags;
UserInput.Process_Input( g_globalKeyNumType, flags );
// jmarshall end
/*
+3 -1
View File
@@ -21,6 +21,7 @@ struct Image_t {
__forceinline Image_t::Image_t() {
IconMapPtr = NULL;
numAnimFrames = 0;
memset(image, 0, sizeof(image));
}
__forceinline Image_t::~Image_t() {
@@ -29,4 +30,5 @@ __forceinline Image_t::~Image_t() {
Image_t* Image_LoadImage(const char* name, bool loadAnims = false, bool loadHouseColor = false);
Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, unsigned char* data, unsigned char *remap = NULL);
Image_t* Find_Image(const char* name);
void Image_Add8BitImage(Image_t* image, int HouseId, int ShapeID, int Width, int Height, unsigned char* data, unsigned char* remap);
void Image_Add8BitImage(Image_t* image, int HouseId, int ShapeID, int Width, int Height, unsigned char* data, unsigned char* remap);
bool Image_Add32BitImage(const char* name, Image_t* image, int HouseId, int ShapeID);
+13 -12
View File
@@ -652,9 +652,9 @@ int MapEditClass::Pick_Scenario(char const * caption, int & scen_nump, ScenarioP
*/
bool display = true;
while (pickscenerio_process) {
KeyNumType _key;
int _flags;
WWSDL_ProcessEvents(_key, _flags);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
}
Imgui_Dialog_Function = nullptr;
@@ -1117,9 +1117,10 @@ int MapEditClass::Size_Map(int x, int y, int w, int h)
// }
//
// Show_Mouse();
KeyNumType _key;
int _types;
WWSDL_ProcessEvents(_key, _types);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
// display = REDRAW_NONE;
@@ -1957,9 +1958,9 @@ int MapEditClass::Scenario_Dialog(void)
*/
KeyNumType input = KN_NONE; //commands->Input();
KeyNumType _key;
int _flags;
WWSDL_ProcessEvents(_key, _flags);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
/*
** Process input
@@ -2549,9 +2550,9 @@ int MapEditClass::Select_Trigger(void)
//// LogicPage->Unlock();
// }
KeyNumType _key;
int _flags;
WWSDL_ProcessEvents(_key, _flags);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
/*
** Get user input
+16 -5
View File
@@ -1584,11 +1584,16 @@ void MapEditClass::Main_Menu(void)
*/
Hide_Mouse(); // Do_Menu assumes the mouse is already hidden
selection = mainmenu_selection;
KeyNumType _key;
int _flags;
WWSDL_ProcessEvents(_key, _flags);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
Call_Back();
Show_Mouse();
if (UnknownKey==KN_ESC || _key == KN_RMOUSE) {
if (UnknownKey==KN_ESC || g_globalKeyNumType == KN_RMOUSE) {
break;
}
@@ -1702,7 +1707,9 @@ void MapEditClass::Main_Menu(void)
case 7:
if (Changed) {
Imgui_Dialog_Function = nullptr;
WWSDL_ProcessEvents(_key, _flags);
UserInput.Process_Input();
rc = WWMessageBox().Process("Save Changes?", TXT_YES, TXT_NO, TXT_CANCEL);
HidPage.Clear();
Flag_To_Redraw(true);
@@ -1779,12 +1786,16 @@ void MapEditClass::AI_Menu(void)
*/
Call_Back();
UserInput.Process_Input();
/*
** Invoke menu
*/
Hide_Mouse(); // Do_Menu assumes the mouse is already hidden
selection = Do_Menu(&_menus[0], true);
Show_Mouse();
if (UnknownKey==KN_ESC || UnknownKey==KN_LMOUSE || UnknownKey==KN_RMOUSE) {
break;
}
+17 -15
View File
@@ -228,9 +228,12 @@ char const * Map_Selection(void)
bool done = 0;
MouseType shape = MOUSE_NORMAL;
while (!done) {
KeyNumType _key;
int _flags = 0;
WWSDL_ProcessEvents(_key, _flags);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
Call_Back();
#ifdef WIN32
/*
@@ -259,24 +262,23 @@ char const * Map_Selection(void)
timer = delay;
Set_Mouse_Cursor(xspot, yspot, start + frame);
}
if (_flags == KN_LMOUSE) {
{
choice = 0;
if (choice != -1) {
done = 1;
selection = choice;
if (g_globalKeyFlags == KN_LMOUSE)
{
choice = 0;
if (choice != -1) {
done = 1;
selection = choice;
#ifdef WIN32
Play_Sample(country1, 255, Options.Normalize_Volume(170));
Play_Sample(country1, 255, Options.Normalize_Volume(170));
#else
Play_Sample(country1, 255, Options.Normalize_Volume(50));
Play_Sample(country1, 255, Options.Normalize_Volume(50));
#endif
} else {
} else {
#ifdef WIN32
Play_Sample(scold1, 255, Options.Normalize_Volume(170));
Play_Sample(scold1, 255, Options.Normalize_Volume(170));
#else
Play_Sample(scold1, 255, Options.Normalize_Volume(50));
Play_Sample(scold1, 255, Options.Normalize_Volume(50));
#endif
}
}
}
}
+7 -6
View File
@@ -443,13 +443,14 @@ int Do_Menu(char const ** strings, bool )
UnknownKey = 0;
while (selection == -1) {
// jmarshall
KeyNumType _key = KN_NONE;
int _flags;
WWSDL_ProcessEvents(_key, _flags);
Show_Mouse(true);
// jmarshall end
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
Call_Back();
selection = Check_Menu(0, strings, NULL, 0xFFL, 0, _key);
Show_Mouse(true);
selection = Check_Menu(0, strings, NULL, 0xFFL, 0, (KeyNumType)g_globalKeyFlags);
if (UnknownKey != 0 || UnknownKey == KN_ESC || UnknownKey==KN_LMOUSE || UnknownKey==KN_RMOUSE) break;
}
Keyboard->Clear();
+3 -3
View File
@@ -1427,9 +1427,9 @@ void ScoreClass::Input_Name(char str[], int xpos, int ypos, char const pal[])
// jmarshall - temp disable high school writing.
// do {
//// jmarshall
// KeyNumType _key;
// int flags;
// WWSDL_ProcessEvents(_key, flags);
// g_globalKeyNumType = KN_NONE;
// g_globalKeyFlags = 0;
// UserInput.Process_Input();
//// jmarshall end
// Call_Back();
// Animate_Score_Objs();
+8 -7
View File
@@ -684,9 +684,10 @@ int PASCAL WinMain ( HINSTANCE instance , HINSTANCE , char * command_line , int
{
Keyboard->Check();
KeyNumType _key = KN_NONE;
int _flags;
WWSDL_ProcessEvents(_key, _flags);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
} while (ReadyToQuit == 1);
return (EXIT_SUCCESS);
@@ -866,10 +867,10 @@ void Emergency_Exit ( int code )
{
Keyboard->Check();
KeyNumType _key = KN_NONE;
int _flags;
WWSDL_ProcessEvents(_key, _flags);
}while (ReadyToQuit == 3);
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
} while (ReadyToQuit == 3);
#else //WIN32
+8
View File
@@ -690,6 +690,14 @@ void TerrainTypeClass::Init(TheaterType theater)
_makepath(fullname, NULL, NULL, terrain.IniName, Theaters[theater].Suffix);
((void const *&)terrain.ImageData) = MFCD::Retrieve(fullname);
// Try and load HD assets first.
Image_t* hdImage = Load_StampHD(Theaters[theater].Name, fullname, terrain.ImageData);
if (hdImage)
{
Get_Stamp_Size(terrain.ImageData, hdImage->renderwidth, hdImage->renderheight);
((void const*&)terrain.HDImageData) = hdImage;
}
else
{
char tmp[512];
sprintf(tmp, "icon_%s", fullname);
+80 -3
View File
@@ -190,7 +190,81 @@ void __cdecl Buffer_Draw_Stamp2(GraphicViewPortClass& viewport, IconControlType*
}
}
struct Image_t *__cdecl Load_Stamp(const char *name, const void* icondata)
Image_t* Load_StampHD(const char* theaterName, const char* iconName, const void* icondata) {
char filename[2048];
Image_t* image = NULL;
IconControlType* tileset = (IconControlType*)icondata;
if (!tileset) {
return NULL;
}
if (LastIconset != tileset) {
Init_Stamps(tileset);
}
// This is because were trying to avoid parsing the XML's and the filenames aren't consistant.
char* baseFileNameTemplate = "DATA/ART/TEXTURES/SRGB/RED_ALERT/TERRAIN/%s/%s/%s-%04d.DDS";
char* fileNameTemplate = baseFileNameTemplate;
for (int i = 0; i < IconCount; i++)
{
sprintf(filename, fileNameTemplate, theaterName, iconName, iconName, i);
if (image == NULL) {
image = Image_LoadImage(filename);
if (image == NULL) {
fileNameTemplate = "DATA/ART/TEXTURES/SRGB/RED_ALERT/TERRAIN/%s/%s/%s-%04d-0000.DDS";
sprintf(filename, fileNameTemplate, theaterName, iconName, iconName, i);
image = Image_LoadImage(filename);
if (image == NULL) {
fileNameTemplate = "DATA/ART/TEXTURES/SRGB/RED_ALERT/TERRAIN/%s/%s/%s-%04d-00.DDS";
sprintf(filename, fileNameTemplate, theaterName, iconName, iconName, i);
image = Image_LoadImage(filename);
if (image == NULL) {
fileNameTemplate = baseFileNameTemplate; // Restore back to the original template.
continue;
}
}
}
//if (i != 0) {
// image->image[0][i] = image->image[0][0];
// image->image[0][0] = 0;
//}
}
else {
if (!Image_Add32BitImage(filename, image, -1, i)) {
continue;
}
}
}
//if (image) {
// image->IconMapPtr = MapPtr;
//}
return image;
}
void Get_Stamp_Size(const void* icondata, int& width, int& height) {
IconControlType* tileset = (IconControlType*)icondata;
if (!tileset) {
width = -1;
height = -1;
return;
}
if (LastIconset != tileset) {
Init_Stamps(tileset);
}
width = IconWidth;
height = IconHeight;
}
Image_t * Load_Stamp(const char *name, const void* icondata)
{
IconControlType* tileset = (IconControlType*)icondata;
@@ -239,8 +313,8 @@ void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, const void
uint8_t* MapPtr = (uint8_t * )iconImage->IconMapPtr;
int icon_index = MapPtr != nullptr ? MapPtr[icon] : icon;
{
int blit_height = IconHeight;
int blit_width = IconWidth;
int blit_height = iconImage->renderheight;
int blit_width = iconImage->renderwidth;
int width = left + right;
int xstart = left + x;
@@ -320,6 +394,9 @@ void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, const void
// src += IconWidth;
//}
if (iconImage->image[0][icon_index] == 0)
return;
GL_SetClipRect(xstart, ystart, blit_width, blit_height);
GL_RenderImage(iconImage, xstart, ystart, blit_width, blit_height, 0, icon_index);
GL_ResetClipRect();
+5 -1
View File
@@ -61,7 +61,11 @@ extern "C" {
void * __cdecl Get_Font_Palette_Ptr ( void );
}
struct Image_t* __cdecl Load_Stamp(const char* name, const void* icondata);
struct Image_t;
Image_t* Load_Stamp(const char* name, const void* icondata);
void Get_Stamp_Size(const void* icondata, int &width, int &height);
Image_t* Load_StampHD(const char* theaterName, const char* iconName, const void *icondata);
extern GraphicViewPortClass *LogicPage;
extern BOOL AllowHardwareBlitFills;
+4 -2
View File
@@ -433,7 +433,9 @@ void Image_Add8BitImage(Image_t *image, int HouseId, int ShapeID, int Width, int
delete buffer;
}
bool Image_Add32BitImage(const char *name, Image_t* image, int HouseId, int ShapeID) {
return Image_loadHDImage(image, name, HouseId, ShapeID, image->namehash, false);
}
BOOL Set_Video_Mode(HWND hwnd, int w, int h, int bits_per_pixel) {
// Todo implement resoluton scaling.
@@ -960,7 +962,7 @@ void __cdecl SetPalette(unsigned char *palette, long, unsigned long)
void WWSDL_ProcessEvents(KeyNumType& key, int& flags, bool presentBuffer) {
UserInput.Process_Input(key, flags, presentBuffer);
//UserInput.Process_Input(key, flags);
}
#ifndef NDEBUG
+10 -9
View File
@@ -3,7 +3,7 @@
extern KeyboardClass * Keyboard;
void UserInputClass::Process_Input(KeyNumType& key, int& flags, bool presentBuffer)
void UserInputClass::Process_Input(KeyNumType& key, int& flags)
{
bool leftMouseProcessed = false;
SDL_GetMouseState(&Mouse.X, &Mouse.Y);
@@ -50,17 +50,23 @@ void UserInputClass::Process_Input(KeyNumType& key, int& flags, bool presentBuff
if (event.button.button == SDL_BUTTON_LEFT) {
Mouse.Button_Left == MouseButtonState::MOUSE_BUTTON_DOWN;
key = KN_LMOUSE;
flags = GadgetClass::LEFTPRESS;
Keyboard->Put_Element(KN_LMOUSE);
leftMouseProcessed = true;
numFramesLMouse++;
key = KN_LMOUSE;
}
else if (event.button.button == SDL_BUTTON_RIGHT) {
Mouse.Button_Right == MouseButtonState::MOUSE_BUTTON_DOWN;
numFramesLMouse = 0;
flags = GadgetClass::RIGHTPRESS;
Keyboard->Put_Element(KN_RMOUSE);
key = KN_RMOUSE;
flags = GadgetClass::RIGHTPRESS;
numFramesLMouse = 0;
}
break;
@@ -138,9 +144,4 @@ void UserInputClass::Process_Input(KeyNumType& key, int& flags, bool presentBuff
Mouse.Button_Left == MouseButtonState::MOUSE_BUTTON_HOLD;
flags = GadgetClass::LEFTHELD;
}
if (presentBuffer)
{
Device_Present();
}
}
+4 -1
View File
@@ -7,6 +7,9 @@
#include "examples/imgui_impl_sdl.h"
extern KeyNumType g_globalKeyNumType;
extern int g_globalKeyFlags;
// Mapping of SDL KeyCode values to internal KeyNumType
std::map<SDL_KeyCode, KeyNumType> const sdl_keyMapping = {
{ SDLK_a, KN_A },
@@ -101,7 +104,7 @@ class UserInputClass
INPUT_ACTION_MOUSE,
} InputAction;
void UserInputClass::Process_Input(KeyNumType& key, int& flags, bool presentBuffer = true);
void UserInputClass::Process_Input(KeyNumType& key = g_globalKeyNumType, int& flags = g_globalKeyFlags);
InputAction LastAction;