Improved the error handling for previous commit.

Reverted the change in Tiles.cpp from commit 4bc1a422c3.
This commit is contained in:
NovaRain
2019-05-10 10:38:51 +08:00
parent 02c2df50ac
commit 4b221b5367
7 changed files with 29 additions and 23 deletions
+1 -1
View File
@@ -249,7 +249,7 @@
#define dialog_message(text) sfall_func1("dialog_message", text)
#define dialog_obj sfall_func0("dialog_obj")
#define display_stats sfall_func0("display_stats")
#define draw_image(frmFile, frame, x, y, transparent) sfall_func5("draw_image", frmFile, frame, x, y, transparent)
#define draw_image(frmFile, frame, x, y, noTransparent) sfall_func5("draw_image", frmFile, frame, x, y, noTransparent)
#define draw_image_scaled(frmFile, frame, x, y, w, h) sfall_func6("draw_image_scaled", frmFile, frame, x, y, w, h)
#define exec_map_update_scripts sfall_func0("exec_map_update_scripts")
#define floor2(value) sfall_func1("floor2", value)
+4 -3
View File
@@ -587,7 +587,7 @@ Some utility/math functions are available:
- there is also a unique ID number range for the player and party members from 18000 to 83535
- to assign a new ID number generated by the engine to the object (i.e. unassign a unique ID), call the function with two arguments and pass -1 for the flag argument
> void sfall_func5("draw_image", string/int pathFile/artId, int frame, int x, int y, bool transparent)
> void sfall_func5("draw_image", string/int pathFile/artId, int frame, int x, int y, bool noTransparent)
> void sfall_func6("draw_image_scaled", string/int pathFile/artId, int frame, int x, int y, int width, int height)
- displays the specified FRM image in the active window created by vanilla CreateWin or sfall's create_win script function
- pathFile/artId: path to the FRM file (e.g. "art\\inven\\5mmap.frm"), or its FRM ID number (e.g. 117440550, see specification of the FID format)
@@ -595,8 +595,9 @@ Optional arguments:
- frame: frame number, the first frame starts from zero
- x/y: offset relative to the top-left corner of the window
- width/height: image size, used to scale the image when displaying it
- transparent: pass true to display an image with transparent background
- NOTE: calling the functions without creating a window first will crash the game
- noTransparent: pass true to display an image without transparent background
- NOTE: to omit optional arguments, call the functions with different sfall_funcX (e.g. sfall_func4("draw_image", pathFile, frame, x, y))
- if draw_image_scaled is called without x/y/width/height arguments, the image will be scaled to fit the window without transparent background
------------------------
------ MORE INFO -------
+7 -7
View File
@@ -417,16 +417,16 @@ void __fastcall DrawWinLine(int winRef, DWORD startXPos, DWORD endXPos, DWORD st
}
}
// draws an image to the buffer without scaling and with possible transparency
void __fastcall windowDisplayBuf(long x, long width, long y, long height, void* data, long isTrans) {
// draws an image to the buffer without scaling and with transparency display toggle
void __fastcall windowDisplayBuf(long x, long width, long y, long height, void* data, long noTrans) {
__asm {
push height;
push edx; // from_width
push y;
mov eax, data; // from
mov ebx, fo::funcoffs::windowDisplayBuf_;
cmp isTrans, 0;
cmovnz ebx, fo::funcoffs::windowDisplayTransBuf_;
mov ebx, fo::funcoffs::windowDisplayTransBuf_;
cmp noTrans, 0;
cmovnz ebx, fo::funcoffs::windowDisplayBuf_;
call ebx; // *data<eax>, from_width<edx>, unused<ebx>, X<ecx>, Y, width, height
}
}
@@ -449,9 +449,9 @@ void __fastcall trans_cscale(long i_width, long i_height, long s_width, long s_h
mov edx, ecx; // i_width
call fo::funcoffs::windowGetBuffer_;
add eax, xy_shift;
push eax; // w_buff
push eax; // to_buff
mov eax, data;
call fo::funcoffs::trans_cscale_; // *i_data@<eax>, i_width@<edx>, i_height@<ebx>, i_width2@<ecx>, w_buff, width, height, from_width
call fo::funcoffs::trans_cscale_; // *from_buff<eax>, i_width<edx>, i_height<ebx>, i_width2<ecx>, to_buff, width, height, to_width
}
}
+2 -2
View File
@@ -198,8 +198,8 @@ long __stdcall win_register_button(DWORD winRef, long xPos, long yPos, long widt
void __stdcall DialogOut(const char* text);
// draws an image to the buffer without scaling and with possible transparency
void __fastcall windowDisplayBuf(long x, long width, long y, long height, void* data, long isTrans);
// draws an image to the buffer without scaling and with transparency display toggle
void __fastcall windowDisplayBuf(long x, long width, long y, long height, void* data, long noTrans);
// draws an image in the window and scales it to fit the window
void __fastcall displayInWindow(long w_here, long width, long height, void* data);
+1
View File
@@ -43,6 +43,7 @@
#define FO_VAR_curr_font_num 0x51E3B0
#define FO_VAR_curr_pc_stat 0x6681AC
#define FO_VAR_curr_stack 0x59E96C
#define FO_VAR_currentWindow 0x51DCB8
#define FO_VAR_cursor_line 0x664514
#define FO_VAR_dialogue_head 0x518850
#define FO_VAR_dialogue_state 0x518714
+13 -9
View File
@@ -399,7 +399,11 @@ void sf_create_win(OpcodeContext& ctx) {
}
static void DrawImage(OpcodeContext& ctx, bool isScaled) {
long rotation = 0;
if (*(DWORD*)FO_VAR_currentWindow == -1) {
ctx.printOpcodeError("%s() - no created/selected window for the image.", ctx.getMetaruleName());
return;
}
long direction = 0;
const char* file = nullptr;
if (ctx.arg(0).isInt()) { // art id
long fid = ctx.arg(0).rawValue();
@@ -407,9 +411,9 @@ static void DrawImage(OpcodeContext& ctx, bool isScaled) {
long _fid = fid & 0xFFFFFFF;
file = fo::func::art_get_name(_fid); // .frm
if (_fid >> 24 == fo::OBJ_TYPE_CRITTER) {
rotation = (fid >> 28);
direction = (fid >> 28);
DWORD sz;
if (rotation && fo::func::db_file_exist(file, &sz)) {
if (direction && fo::func::db_file_exist(file, &sz)) {
file = fo::func::art_get_name(fid); // .fr#
}
}
@@ -418,13 +422,13 @@ static void DrawImage(OpcodeContext& ctx, bool isScaled) {
}
fo::FrmFile* frmPtr = nullptr;
if (fo::func::load_frame(file, &frmPtr)) {
ctx.printOpcodeError("%s() - can't open the file '%s'.", ctx.getMetaruleName(), file);
ctx.printOpcodeError("%s() - can't open the file: %s", ctx.getMetaruleName(), file);
return;
}
fo::FrmFrameData* framePtr = (fo::FrmFrameData*)&frmPtr->width;
if (rotation > 0 && rotation < 6) {
if (direction > 0 && direction < 6) {
BYTE* offsOriFrame = (BYTE*)framePtr;
offsOriFrame += frmPtr->oriFrameOffset[rotation];
offsOriFrame += frmPtr->oriFrameOffset[direction];
framePtr = (fo::FrmFrameData*)offsOriFrame;
}
int frameno = ctx.arg(1).rawValue();
@@ -438,7 +442,7 @@ static void DrawImage(OpcodeContext& ctx, bool isScaled) {
}
}
if (isScaled && ctx.numArgs() < 3) {
fo::func::displayInWindow(framePtr->width, framePtr->width, framePtr->height, framePtr->data); // scaled to window size
fo::func::displayInWindow(framePtr->width, framePtr->width, framePtr->height, framePtr->data); // scaled to window size (w/o transparent)
} else {
int x = ctx.arg(2).rawValue(), y = ctx.arg(3).rawValue();
if (isScaled) { // draw to scale
@@ -447,8 +451,8 @@ static void DrawImage(OpcodeContext& ctx, bool isScaled) {
long w_width = fo::func::windowWidth();
long xy_pos = (x * w_width) + y;
fo::func::trans_cscale(framePtr->width, framePtr->height, s_width, s_height, xy_pos, w_width, framePtr->data); // custom scaling
} else {
fo::func::windowDisplayBuf(x + frmPtr->xshift[rotation], framePtr->width, y + frmPtr->yshift[rotation], framePtr->height, framePtr->data, ctx.arg(4).rawValue());
} else { // with x/y frame offsets
fo::func::windowDisplayBuf(x + frmPtr->xshift[direction], framePtr->width, y + frmPtr->yshift[direction], framePtr->height, framePtr->data, ctx.arg(4).rawValue());
}
}
__asm {
+1 -1
View File
@@ -119,7 +119,7 @@ static int ProcessTile(fo::Art* tiles, int tile, int listpos) {
frame.height = ByteSwapW(36);
frame.width = ByteSwapW(80);
frame.frameSize = ByteSwapD(80 * 36);
frame.frameAreaSize = frame.frameSize + 12;
frame.frameAreaSize = ByteSwapD(80 * 36 + 12);
int xoffset = x * 48 + (ysize - (y + 1)) * 32;
int yoffset = height - (36 + x * 12 + y * 24);
for (int y2 = 0; y2 < 36; y2++) {