Skip to content

Commit

Permalink
Sync with 20160327
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Yan <leochenlinux@gmail.com>
  • Loading branch information
MagicLeo21 committed Mar 29, 2016
1 parent 1ffa948 commit 9725555
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 81 deletions.
58 changes: 29 additions & 29 deletions LUAHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* LUAHandler.cpp - LUA handler for ONScripter
*
* Copyright (c) 2001-2015 Ogapee. All rights reserved.
* Copyright (c) 2001-2016 Ogapee. All rights reserved.
*
* ogapee@aqua.dti2.ne.jp
*
Expand Down Expand Up @@ -219,8 +219,8 @@ int NSSetIntValue(lua_State *state)
lua_getglobal( state, ONS_LUA_HANDLER_PTR );
LUAHandler *lh = (LUAHandler*)lua_topointer( state, -1 );

int no = luaL_checkint( state, 1 );
int val = luaL_checkint( state, 2 );
int no = luaL_checkinteger( state, 1 );
int val = luaL_checkinteger( state, 2 );

lh->sh->setNumVariable( no, val );

Expand All @@ -232,7 +232,7 @@ int NSSetStrValue(lua_State *state)
lua_getglobal( state, ONS_LUA_HANDLER_PTR );
LUAHandler *lh = (LUAHandler*)lua_topointer( state, -1 );

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );
const char *str = luaL_checkstring( state, 2 );

if (lh->sh->getVariableData(no).str)
Expand All @@ -252,7 +252,7 @@ int NSGetIntValue(lua_State *state)
lua_getglobal( state, ONS_LUA_HANDLER_PTR );
LUAHandler *lh = (LUAHandler*)lua_topointer( state, -1 );

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );

lua_pushnumber( state, lh->sh->getVariableData(no).num );

Expand All @@ -264,7 +264,7 @@ int NSGetStrValue(lua_State *state)
lua_getglobal( state, ONS_LUA_HANDLER_PTR );
LUAHandler *lh = (LUAHandler*)lua_topointer( state, -1 );

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );

lua_pushstring( state, lh->sh->getVariableData(no).str );

Expand Down Expand Up @@ -469,7 +469,7 @@ int NSSleep(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int val = luaL_checkint( state, 1 );
int val = luaL_checkinteger( state, 1 );

sprintf(cmd_buf, "wait %d", val);
lh->sh->enterExternalScript(cmd_buf);
Expand Down Expand Up @@ -497,8 +497,8 @@ int NSSpCell(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int cell = luaL_checkint( state, 2 );
int no = luaL_checkinteger( state, 1 );
int cell = luaL_checkinteger( state, 2 );

sprintf(cmd_buf, "cell %d, %d", no, cell);
lh->sh->enterExternalScript(cmd_buf);
Expand All @@ -513,7 +513,7 @@ int NSSpClear(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );

sprintf(cmd_buf, "csp %d", no);
lh->sh->enterExternalScript(cmd_buf);
Expand All @@ -528,7 +528,7 @@ int NSSpGetInfo(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );

AnimationInfo *ai = lh->ons->getSpriteInfo(no);

Expand All @@ -544,7 +544,7 @@ int NSSpGetPos(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );

AnimationInfo *ai = lh->ons->getSpriteInfo(no);

Expand All @@ -560,7 +560,7 @@ int NSSpLoad(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );
const char *str = luaL_checkstring( state, 2 );

sprintf(cmd_buf, "lsp %d, \"%s\", %d, 0", no, str, lh->ons->getWidth()+1);
Expand All @@ -576,10 +576,10 @@ int NSSpMove(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int x = luaL_checkint( state, 2 );
int y = luaL_checkint( state, 3 );
int alpha = luaL_checkint( state, 4 );
int no = luaL_checkinteger( state, 1 );
int x = luaL_checkinteger( state, 2 );
int y = luaL_checkinteger( state, 3 );
int alpha = luaL_checkinteger( state, 4 );

sprintf(cmd_buf, "amsp %d, %d, %d, %d", no, x, y, alpha);
lh->sh->enterExternalScript(cmd_buf);
Expand All @@ -594,7 +594,7 @@ int NSSpVisible(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );
int v = lua_toboolean( state, 2 );

sprintf(cmd_buf, "vsp %d, %d", no, v);
Expand All @@ -610,7 +610,7 @@ int NSSp2GetInfo(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );

AnimationInfo *ai = lh->ons->getSprite2Info(no);

Expand All @@ -626,7 +626,7 @@ int NSSp2GetPos(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );

AnimationInfo *ai = lh->ons->getSprite2Info(no);

Expand All @@ -646,7 +646,7 @@ int NSSp2Load(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int no = luaL_checkinteger( state, 1 );
const char *str = luaL_checkstring( state, 2 );

sprintf(cmd_buf, "lsp2 %d, \"%s\", %d, 0, 100, 100, 0", no, str, lh->ons->getWidth()*2);
Expand All @@ -662,14 +662,14 @@ int NSSp2Move(lua_State *state)
lua_getglobal(state, ONS_LUA_HANDLER_PTR);
LUAHandler *lh = (LUAHandler*)lua_topointer(state, -1);

int no = luaL_checkint( state, 1 );
int x = luaL_checkint( state, 2 );
int y = luaL_checkint( state, 3 );
int sx = luaL_checkint( state, 4 );
int sy = luaL_checkint( state, 5 );
int r = luaL_checkint( state, 6 );
int alpha = luaL_checkint( state, 7 );
int opt = luaL_checkint( state, 8 ); // opt is not handled properly yet
int no = luaL_checkinteger( state, 1 );
int x = luaL_checkinteger( state, 2 );
int y = luaL_checkinteger( state, 3 );
int sx = luaL_checkinteger( state, 4 );
int sy = luaL_checkinteger( state, 5 );
int r = luaL_checkinteger( state, 6 );
int alpha = luaL_checkinteger( state, 7 );
int opt = luaL_checkinteger( state, 8 ); // opt is not handled properly yet

sprintf(cmd_buf, "amsp2 %d, %d, %d, %d, %d, %d, %d", no, x, y, sx, sy, r, alpha);
lh->sh->enterExternalScript(cmd_buf);
Expand Down
5 changes: 3 additions & 2 deletions ONScripter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* ONScripter.h - Execution block parser of ONScripter
*
* Copyright (c) 2001-2015 Ogapee. All rights reserved.
* Copyright (c) 2001-2016 Ogapee. All rights reserved.
*
* ogapee@aqua.dti2.ne.jp
*
Expand Down Expand Up @@ -505,7 +505,8 @@ class ONScripter : public ScriptParser
char *readSaveStrFromFile( int no );
int loadSaveFile( int no );
void saveMagicNumber( bool output_flag );
int saveSaveFile( bool write_to_disk, int no=0, const char *savestr=NULL );
void storeSaveFile();
int writeSaveFile( int no=0, const char *savestr=NULL );

int loadSaveFile2( int file_version );
void saveSaveFile2( bool output_flag );
Expand Down
18 changes: 12 additions & 6 deletions ONScripter_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* ONScripter_command.cpp - Command executer of ONScripter
*
* Copyright (c) 2001-2015 Ogapee. All rights reserved.
* Copyright (c) 2001-2016 Ogapee. All rights reserved.
* ogapee@aqua.dti2.ne.jp
*
* Copyright (c) 2016 Chen Yan. All rights reserved.
Expand Down Expand Up @@ -290,6 +290,8 @@ int ONScripter::texecCommand()
processEOT();
page_enter_status = 0;
}

saveonCommand();

return RET_CONTINUE;
}
Expand Down Expand Up @@ -980,7 +982,7 @@ int ONScripter::saveonCommand()

int ONScripter::saveoffCommand()
{
if (saveon_flag && internal_saveon_flag) saveSaveFile(false);
if (saveon_flag && internal_saveon_flag) storeSaveFile();

saveon_flag = false;

Expand All @@ -999,8 +1001,8 @@ int ONScripter::savegameCommand()
if (savegame2_flag)
savestr = script_h.readStr();

if (saveon_flag && internal_saveon_flag) saveSaveFile(false);
saveSaveFile( true, no, savestr );
if (saveon_flag && internal_saveon_flag) storeSaveFile();
writeSaveFile( no, savestr );

return RET_CONTINUE;
}
Expand Down Expand Up @@ -1074,7 +1076,7 @@ int ONScripter::resetCommand()
script_h.getVariableData(i).reset(false);

setCurrentLabel( "start" );
saveSaveFile(false);
storeSaveFile();

return RET_CONTINUE;
}
Expand Down Expand Up @@ -3455,8 +3457,12 @@ int ONScripter::bspCommand()
{
int no = script_h.readInt();
if (no < 0 || no >= MAX_SPRITE_NUM ||
sprite_info[no].image_surface == NULL)
sprite_info[no].image_surface == NULL){
for (int i=0 ; i<3 ; i++)
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
script_h.readStr();
return RET_CONTINUE;
}

ButtonLink *bl = new ButtonLink();
root_button_link.insert( bl );
Expand Down
56 changes: 27 additions & 29 deletions ONScripter_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* ONScripter_file.cpp - FILE I/O of ONScripter
*
* Copyright (c) 2001-2014 Ogapee. All rights reserved.
* Copyright (c) 2001-2016 Ogapee. All rights reserved.
*
* ogapee@aqua.dti2.ne.jp
*
Expand Down Expand Up @@ -223,38 +223,36 @@ void ONScripter::saveMagicNumber( bool output_flag )
writeChar( SAVEFILE_VERSION_MINOR, output_flag );
}

int ONScripter::saveSaveFile( bool write_to_disk, int no, const char *savestr )
void ONScripter::storeSaveFile()
{
// make save data structure on memory
if (!write_to_disk || (saveon_flag && internal_saveon_flag)){
file_io_buf_ptr = 0;
saveMagicNumber( false );
saveSaveFile2( false );
allocFileIOBuf();
saveMagicNumber( true );
saveSaveFile2( true );
save_data_len = file_io_buf_ptr;
memcpy(save_data_buf, file_io_buf, save_data_len);
}

if (write_to_disk){
saveAll();
file_io_buf_ptr = 0;
saveMagicNumber( false );
saveSaveFile2( false );
allocFileIOBuf();
saveMagicNumber( true );
saveSaveFile2( true );
save_data_len = file_io_buf_ptr;
memcpy(save_data_buf, file_io_buf, save_data_len);
}

char filename[32];
sprintf( filename, "save%d.dat", no );

memcpy(file_io_buf, save_data_buf, save_data_len);
file_io_buf_ptr = save_data_len;
if (saveFileIOBuf( filename, 0, savestr )){
fprintf( stderr, "can't open save file %s for writing\n", filename );
return -1;
}
int ONScripter::writeSaveFile( int no, const char *savestr )
{
saveAll();

size_t magic_len = strlen(SAVEFILE_MAGIC_NUMBER)+2;
sprintf( filename, RELATIVEPATH "sav%csave%d.dat", DELIMITER, no );
if (saveFileIOBuf( filename, magic_len, savestr ))
fprintf( stderr, "can't open save file %s for writing (not an error)\n", filename );
char filename[32];
sprintf( filename, "save%d.dat", no );

memcpy(file_io_buf, save_data_buf, save_data_len);
file_io_buf_ptr = save_data_len;
if (saveFileIOBuf( filename, 0, savestr )){
fprintf( stderr, "can't open save file %s for writing\n", filename );
return -1;
}

size_t magic_len = strlen(SAVEFILE_MAGIC_NUMBER)+2;
sprintf( filename, RELATIVEPATH "sav%csave%d.dat", DELIMITER, no );
if (saveFileIOBuf( filename, magic_len, savestr ))
fprintf( stderr, "can't open save file %s for writing (not an error)\n", filename );

return 0;
}
6 changes: 3 additions & 3 deletions ONScripter_rmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* ONScripter_rmenu.cpp - Right click menu handler of ONScripter
*
* Copyright (c) 2001-2015 Ogapee. All rights reserved.
* Copyright (c) 2001-2016 Ogapee. All rights reserved.
* ogapee@aqua.dti2.ne.jp
*
* Copyright (c) 2016 Chen Yan. All rights reserved.
Expand Down Expand Up @@ -462,8 +462,8 @@ void ONScripter::executeSystemSave()
if ( current_button_state.button > 0 ){
int file_no = current_button_state.button;
if (executeSystemYesNo( SYSTEM_SAVE, file_no )){
if (saveon_flag && internal_saveon_flag) saveSaveFile(false);
saveSaveFile( true, file_no );
if (saveon_flag && internal_saveon_flag) storeSaveFile();
writeSaveFile( file_no );
leaveSystemCall();
}
return;
Expand Down
6 changes: 3 additions & 3 deletions ONScripter_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* ONScripter_text.cpp - Text parser of ONScripter
*
* Copyright (c) 2001-2015 Ogapee. All rights reserved.
* Copyright (c) 2001-2016 Ogapee. All rights reserved.
* ogapee@aqua.dti2.ne.jp
*
* Copyright (c) 2016 Chen Yan. All rights reserved.
Expand Down Expand Up @@ -463,7 +463,7 @@ void ONScripter::restoreTextBuffer(SDL_Surface *surface)
void ONScripter::enterTextDisplayMode(bool text_flag)
{
if (line_enter_status <= 1 && (!pretextgosub_label || saveon_flag) && internal_saveon_flag && text_flag){
saveSaveFile(false);
storeSaveFile();
internal_saveon_flag = false;
}

Expand Down Expand Up @@ -693,7 +693,7 @@ void ONScripter::endRuby(bool flush_flag, bool lookback_flag, SDL_Surface *surfa
int ONScripter::textCommand()
{
if (line_enter_status <= 1 && (!pretextgosub_label || saveon_flag) && internal_saveon_flag){
saveSaveFile(false);
storeSaveFile();
internal_saveon_flag = false;
}

Expand Down
2 changes: 1 addition & 1 deletion ScriptHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const char *ScriptHandler::readToken()
addStringBuffer( ch );
buf++;
if (ch == '_') ignore_clickstr_flag = true;
if (!wait_script && ch == '@') wait_script = buf;
if (!wait_script && (ch == '@' || ch == '\\')) wait_script = buf;
}
}
ch = *buf;
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define ONS_VERSION "20150820"
#define ONS_VERSION "20160327"
#define NSC_VERSION 296

0 comments on commit 9725555

Please sign in to comment.