void Application::initQML() { /** A QML-Cpp kommunikációhoz használt QMLData obejktumokat létre kell * hozni a QML felület számára.*/ QMap<QString,QMLData>::iterator iter; for(iter = qmlDataMap.begin(); iter != qmlDataMap.end(); ++iter) { engine.rootContext()->setContextProperty(iter.key(), &iter.value()); } engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); auto rootObjects = engine.rootObjects(); if (rootObjects.size() == 0) { qWarning() << "HIBA: Nem sikerült létrehozni a QML környezetet."; } rootObject = rootObjects.first(); customPlotPtr = (QCustomPlot*)rootObject->findChild<QObject*>("customPlot"); auto mainWindowPtr = rootObject->findChild<QObject*>("MainWindow"); eventhandler.setMainWindowPtr(mainWindowPtr); QObject::connect(rootObject, SIGNAL(connectCommandCpp()), &eventhandler, SLOT(connectCommand())); QObject::connect(rootObject, SIGNAL(connectCommandCpp()), this, SLOT(connectToServer())); QObject::connect(rootObject, SIGNAL(hvEnableCommandCpp()), &eventhandler, SLOT(hvEnableCommand())); QObject::connect(rootObject, SIGNAL(hvEnableCommandCpp()), this, SLOT(hvenCommand())); QObject::connect(rootObject, SIGNAL(driveEnableCommandCpp()), &eventhandler, SLOT(driveEnableCommand())); QObject::connect(rootObject, SIGNAL(driveEnableCommandCpp()), this, SLOT(drenCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), &eventhandler, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), this, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(testCommandCpp()), this, SLOT(testCommand())); QObject::connect(rootObject, SIGNAL(vdemandSliderChanged(QVariant )), this, SLOT(vdemandChanged(QVariant ))); }
UltraHeatDriver::UltraHeatDriver() { Command initCommand( INIT_CMD ); initCommand.AddParameter( new CommandParameter( COMPORT_NUM, NULL, "int" ) ); Command setValueCommand( SETVAL_CMD ); setValueCommand.AddParameter( new CommandParameter( VALUE_KEY, NULL, "int" ) ); setValueCommand.AddParameter( new CommandParameter( PWR_PARAM, NULL, "int" ) ); this->commands->push_back( initCommand ); this->commands->push_back( setValueCommand ); this->supportedComands->push_back( initCommand ); this->supportedComands->push_back( setValueCommand ); Command stopCommand( STOP_CMD ); this->supportedComands->push_back( stopCommand ); this->comPortFD = -1; this->comPortNumber = 0; char temp[50]; sprintf(temp, "%s%d", SERIAL_PORT, this->comPortNumber); this->comPortName = temp; this->shouldStopReadDataThread = false; this->shouldWaitForResponse = false; this->readResponseTries = 0; this->responseWaitTime = 0.05; // = 10ms in seconds }
int main(void){ struct token token = {0}; struct command command = {0}; boolean end = false; pid_t shell_pgid; int terminal; void *handle; terminal = STDIN_FILENO; while(tcgetpgrp(terminal) != (shell_pgid = getpgrp())){ kill(- shell_pgid,SIGTTIN); } shell_pgid = getpid(); if(setpgid(shell_pgid,shell_pgid) < 0){ printf("Erro"); exit(1); } tcsetpgrp(terminal,shell_pgid); terminateCommand ( & command ); signal( SIGCHLD , terminateHandler ); stopCommand( & command ); signal ( SIGTSTP , stopHandler ); handle = dlopen("./libparser.so", RTLD_LAZY); do{ ((void(*)(struct token*))(dlsym(handle,"getTokens")))(&token); ((void(*)(struct token*))(dlsym(handle,"identifyTokens")))(&token); if(!((boolean(*)(struct token*))(dlsym(handle,"checkSyntax")))(&token)) continue; if(ECHO_TOKENS) ((void(*)(struct token*))(dlsym(handle,"echoTokens")))(&token); if(ECHO_INPUT) ((void(*)(struct token*))(dlsym(handle,"echoInput")))(&token); while(((boolean(*)(struct token*,struct command*))(dlsym(handle,"getCommand")))(&token, &command)){ if(ECHO_COMMAND) ((void(*)(struct command))(dlsym(handle,"echoCommand")))(*(command.next)); end = executeCommand(command.next); } } while(!end); ((void(*)(struct command*))(dlsym(handle,"clearCommand")))(&command); ((void(*)(struct token*))(dlsym(handle,"clearToken")))(&token); dlclose(handle); return 0; }
MainApplication::MainApplication(int argc, char *argv[]) : QApplication(argc, argv), simulator(12345), engine(), history(), communication(), robot(history, communication), handler(robot, *engine.rootContext(), history) { // Szimulátor indítása simulator.start(0.3F); // Csatlakozás a szimulátorhoz. communication.connect(QStringLiteral("localhost"),12345); // Szimulálunk egy history változást, mert attól kezdve léteznek a QML oldalon // a C++ oldalról származó változók. (Különben referencia hibákat kapnánk a QML oldalon // egészen addig, amíg az első üzenet meg nem jönne a szimulátortól. //handler.historyChanged(); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); // A QML gyökérelemre szükségünk van ahhoz, hogy tudjunk hivatkozni a QML-es elemekre. auto rootObjects = engine.rootObjects(); if (rootObjects.size() == 0) { qDebug() << "HIBA: Nem sikerült létrehozni a QML környezetet."; return; } // A QML környezet is felállt, bekötjük a signalokat a QML és C++ oldal között. QObject *rootObject = rootObjects[0]; // A handler beköti a saját signaljait. handler.ConnectQmlSignals(rootObject); // Bekötjük a nyomógombok signaljait. QObject::connect(rootObject, SIGNAL(resetCommandCpp()), &handler, SLOT(resetCommand())); QObject::connect(rootObject, SIGNAL(accelerateXCommandCpp()), &handler, SLOT(accelerateXCommand())); QObject::connect(rootObject, SIGNAL(accelerateYCommandCpp()), &handler, SLOT(accelerateYCommand())); QObject::connect(rootObject, SIGNAL(slowDownXCommandCpp()), &handler, SLOT(slowDownXCommand())); QObject::connect(rootObject, SIGNAL(slowDownYCommandCpp()), &handler, SLOT(slowDownYCommand())); QObject::connect(rootObject, SIGNAL(stopCommandCpp()), &handler, SLOT(stopCommand())); QObject::connect(rootObject, SIGNAL(testCommandCpp()), &handler, SLOT(testCommand())); QObject::connect(rootObject, SIGNAL(defaultCommandCpp()), &handler, SLOT(defaultCommand())); }
void CCommandAI::GiveAllowedCommand(const Command& c, bool fromSynced) { if (ExecuteStateCommand(c)) { return; } switch (c.GetID()) { case CMD_SELFD: { if (owner->unitDef->canSelfD) { if (!(c.options & SHIFT_KEY) || commandQue.empty()) { if (owner->selfDCountdown != 0) { owner->selfDCountdown = 0; } else { owner->selfDCountdown = owner->unitDef->selfDCountdown*2+1; } } else if (commandQue.back().GetID() == CMD_SELFD) { commandQue.pop_back(); } else { commandQue.push_back(c); } } return; } case CMD_SET_WANTED_MAX_SPEED: { if (CanSetMaxSpeed() && (commandQue.empty() || (commandQue.back().GetID() != CMD_SET_WANTED_MAX_SPEED))) { // bail early, do not check for overlaps or queue cancelling commandQue.push_back(c); if (commandQue.size()==1 && !owner->beingBuilt) { SlowUpdate(); } } return; } case CMD_WAIT: { GiveWaitCommand(c); return; } case CMD_INSERT: { ExecuteInsert(c, fromSynced); return; } case CMD_REMOVE: { ExecuteRemove(c); return; } } // flush the queue for immediate commands if (!(c.options & SHIFT_KEY)) { if (!commandQue.empty()) { const int& cmd_id = commandQue.front().GetID(); if ((cmd_id == CMD_MANUALFIRE) || (cmd_id == CMD_ATTACK) || (cmd_id == CMD_AREA_ATTACK)) { owner->AttackUnit(0,true); } waitCommandsAI.ClearUnitQueue(owner, commandQue); ClearCommandDependencies(); commandQue.clear(); } inCommand=false; SetOrderTarget(NULL); } AddCommandDependency(c); if (c.GetID() == CMD_PATROL) { CCommandQueue::iterator ci = commandQue.begin(); for (; ci != commandQue.end() && ci->GetID() != CMD_PATROL; ++ci) { // just increment } if (ci == commandQue.end()) { if (commandQue.empty()) { Command c2(CMD_PATROL, c.options); c2.params.push_back(owner->pos.x); c2.params.push_back(owner->pos.y); c2.params.push_back(owner->pos.z); commandQue.push_back(c2); } else { do { --ci; if (ci->params.size() >= 3) { Command c2(CMD_PATROL, c.options); c2.params = ci->params; commandQue.push_back(c2); break; } else if (ci == commandQue.begin()) { Command c2(CMD_PATROL, c.options); c2.params.push_back(owner->pos.x); c2.params.push_back(owner->pos.y); c2.params.push_back(owner->pos.z); commandQue.push_back(c2); break; } } while (ci != commandQue.begin()); } } } // cancel duplicated commands bool first; if (CancelCommands(c, commandQue, first) > 0) { if (first) { Command stopCommand(CMD_STOP); commandQue.push_front(stopCommand); SlowUpdate(); } return; } // do not allow overlapping commands if (!GetOverlapQueued(c).empty()) { return; } if (c.GetID() == CMD_ATTACK) { // avoid weaponless units moving to 0 distance when given attack order if (owner->weapons.empty() && (owner->unitDef->canKamikaze == false)) { Command c2(CMD_STOP); commandQue.push_back(c2); return; } } commandQue.push_back(c); if (commandQue.size() == 1 && !owner->beingBuilt && !owner->stunned) { SlowUpdate(); } }
/** * @brief Main execution loop. Checks if there is an active target * @return void */ void SpecificWorker::compute() { static QTime reloj = QTime::currentTime(); // Check for connection failure if (updateInnerModel(innerModel, tState) == false) { controller->stopTheRobot(omnirobot_proxy); stopCommand(currentTarget, road, tState); tState.setState("DISCONNECTED"); currentTarget.state = CurrentTarget::State::DISCONNECTED; } switch (currentTarget.state) { case CurrentTarget::State::STOP: stopCommand(currentTarget, road, tState); break; case CurrentTarget::State::CHANGETARGET: currentTarget.setState(CurrentTarget::State::GOTO); break; case CurrentTarget::State::GOTO: timer.setInterval(Period); //qDebug() << __FUNCTION__ << "GOTO:" << "Robot at:" << innerModel->transform6D("world", "robot") << "Target:" << currentTarget.getFullPose(); gotoCommand(innerModel, currentTarget, tState, road, laserData); break; case CurrentTarget::State::SETHEADING: setHeadingCommand(innerModel, currentTarget.getRotation().y(), currentTarget, tState, road); break; case CurrentTarget::State::BLOCKED: road.update(); elasticband.update(innerModel, road, laserData, currentTarget); if( road.isBlocked() == false) currentTarget.setState(CurrentTarget::State::GOTO); else qDebug() << __FUNCTION__ << "Blocked"; break; case CurrentTarget::State::GOBACKWARDS: goBackwardsCommand(innerModel, currentTargetBack, currentTarget, tState, road); break; case CurrentTarget::State::DISCONNECTED: timer.setInterval(2000); break; case CurrentTarget::State::ROBOT_COLLISION: // Check if robot is inside limits and not in collision. if (std::get<bool>(sampler.checkRobotValidStateAtTarget(innerModel->transform6D("world", "robot")))) { tState.setState("IDLE"); tState.setDescription(""); currentTarget.setState(CurrentTarget::State::IDLE); } break; case CurrentTarget::State::TARGET_COLLISION: // Check if robot is inside limits and not in collision. timer.setInterval(300); if (std::get<bool>(sampler.checkRobotValidStateAtTarget(currentTarget.getFullPose()))) { tState.setState("IDLE"); tState.setDescription(""); currentTarget.setState(CurrentTarget::State::IDLE); } break; case CurrentTarget::State::LEARNING: if(plannerPRM.learnForAWhile(150, false)) //150, Max number of nodes in the graph. { #ifdef USE_QTGUI //plannerPRM.drawGraph(viewer->innerViewer); #endif } currentTarget.setState(CurrentTarget::State::IDLE); break; case CurrentTarget::State::IDLE: timer.setInterval(700); qDebug() << __FUNCTION__ << "Computed period" << reloj.restart() << "ms. State. Robot at:" << innerModel->transform6D("world", "robot"); //currentTarget.setState(CurrentTarget::State::LEARNING); break; } }
int ONScripter::loadSaveFile2( int file_version ) { deleteNestInfo(); int i, j; readInt(); // 1 if ( readInt() == 1 ) sentence_font.is_bold = true; else sentence_font.is_bold = false; if ( readInt() == 1 ) sentence_font.is_shadow = true; else sentence_font.is_shadow = false; readInt(); // 0 rmode_flag = (readInt()==1)?true:false; sentence_font.color[0] = readInt(); sentence_font.color[1] = readInt(); sentence_font.color[2] = readInt(); cursor_info[0].remove(); char *tmp_name = NULL; readStr( &tmp_name ); loadCursor(0, tmp_name, 0, 0); readStr( &tmp_name ); loadCursor(1, tmp_name, 0, 0); if (tmp_name) delete[] tmp_name; window_effect.effect = readInt(); window_effect.duration = readInt(); readStr( &window_effect.anim.image_name ); // probably sentence_font.clear(); sentence_font.ttf_font = NULL; sentence_font.top_xy[0] = readInt(); sentence_font.top_xy[1] = readInt(); sentence_font.num_xy[0] = readInt(); sentence_font.num_xy[1] = readInt(); sentence_font.font_size_xy[0] = readInt(); sentence_font.font_size_xy[1] = readInt(); sentence_font.pitch_xy[0] = readInt(); sentence_font.pitch_xy[1] = readInt(); for ( i=0 ; i<3 ; i++ ) sentence_font.window_color[2-i] = readChar(); if ( readChar() == 0x00 ) sentence_font.is_transparent = true; else sentence_font.is_transparent = false; sentence_font.wait_time = readInt(); AnimationInfo *ai = &sentence_font_info; ai->orig_pos.x = readInt(); ai->orig_pos.y = readInt(); ai->orig_pos.w = readInt() + 1 - ai->orig_pos.x; ai->orig_pos.h = readInt() + 1 - ai->orig_pos.y; ai->scalePosXY( screen_ratio1, screen_ratio2 ); ai->scalePosWH( screen_ratio1, screen_ratio2 ); readStr( &ai->image_name ); if ( !sentence_font.is_transparent && ai->image_name ){ parseTaggedString( ai ); setupAnimationInfo( ai ); } if ( readInt() == 1 ) cursor_info[0].abs_flag = false; else cursor_info[0].abs_flag = true; if ( readInt() == 1 ) cursor_info[1].abs_flag = false; else cursor_info[1].abs_flag = true; cursor_info[0].orig_pos.x = readInt(); cursor_info[1].orig_pos.x = readInt(); cursor_info[0].orig_pos.y = readInt(); cursor_info[1].orig_pos.y = readInt(); cursor_info[0].scalePosXY( screen_ratio1, screen_ratio2 ); cursor_info[1].scalePosXY( screen_ratio1, screen_ratio2 ); // load background surface bg_info.remove(); readStr( &bg_info.file_name ); createBackground(); for ( i=0 ; i<3 ; i++ ){ tachi_info[i].remove(); readStr( &tachi_info[i].image_name ); if ( tachi_info[i].image_name ){ parseTaggedString( &tachi_info[i] ); setupAnimationInfo( &tachi_info[i] ); } } for ( i=0 ; i<3 ; i++ ) tachi_info[i].orig_pos.x = readInt(); for ( i=0 ; i<3 ; i++ ) tachi_info[i].orig_pos.y = readInt(); for ( i=0 ; i<3 ; i++ ) tachi_info[i].scalePosXY( screen_ratio1, screen_ratio2 ); readInt(); // 0 readInt(); // 0 readInt(); // 0 if (file_version >= 203){ readInt(); // -1 readInt(); // -1 readInt(); // -1 } for ( i=0 ; i<MAX_SPRITE_NUM ; i++ ){ AnimationInfo *ai = &sprite_info[i]; ai->remove(); readStr( &ai->image_name ); if ( ai->image_name ){ parseTaggedString( ai ); setupAnimationInfo( ai ); } ai->orig_pos.x = readInt(); ai->orig_pos.y = readInt(); ai->scalePosXY( screen_ratio1, screen_ratio2 ); if ( readInt() == 1 ) ai->visible = true; else ai->visible = false; ai->current_cell = readInt(); if (file_version >= 203){ j = readInt(); if (j == -1) ai->trans = 256; else ai->trans = j; } } readVariables( 0, script_h.global_variable_border ); // nested info int num_nest =readInt(); last_nest_info = &root_nest_info; if (num_nest > 0){ file_io_buf_ptr += (num_nest-1)*4; while( num_nest > 0 ){ NestInfo *info = new NestInfo(); if (last_nest_info == &root_nest_info) last_nest_info = info; i = readInt(); if (i > 0){ info->nest_mode = NestInfo::LABEL; info->next_script = script_h.getAddress( i ); file_io_buf_ptr -= 8; num_nest--; } else{ info->nest_mode = NestInfo::FOR; info->next_script = script_h.getAddress( -i ); file_io_buf_ptr -= 16; info->var_no = readInt(); info->to = readInt(); info->step = readInt(); file_io_buf_ptr -= 16; num_nest -= 4; } info->next = root_nest_info.next; if (root_nest_info.next) root_nest_info.next->previous = info; root_nest_info.next = info; info->previous = &root_nest_info; } num_nest = readInt(); file_io_buf_ptr += num_nest*4; } if (readInt() == 1) monocro_flag = true; else monocro_flag = false; for ( i=0 ; i<3 ; i++ ) monocro_color[2-i] = readInt(); for ( i=0 ; i<256 ; i++ ){ monocro_color_lut[i][0] = (monocro_color[0] * i) >> 8; monocro_color_lut[i][1] = (monocro_color[1] * i) >> 8; monocro_color_lut[i][2] = (monocro_color[2] * i) >> 8; } nega_mode = readInt(); // ---------------------------------------- // Sound stopCommand(); loopbgmstopCommand(); stopAllDWAVE(); readStr( &midi_file_name ); // MIDI file readStr( &wave_file_name ); // wave, waveloop i = readInt(); if ( i >= 0 ) current_cd_track = i; // play, playonce MIDI if ( readInt() == 1 ){ midi_play_loop_flag = true; current_cd_track = -2; playSound(midi_file_name, SOUND_MIDI, midi_play_loop_flag); } else midi_play_loop_flag = false; // wave, waveloop if ( readInt() == 1 ) wave_play_loop_flag = true; else wave_play_loop_flag = false; if ( wave_file_name && wave_play_loop_flag ) playSound(wave_file_name, SOUND_CHUNK, wave_play_loop_flag, MIX_WAVE_CHANNEL); // play, playonce if ( readInt() == 1 ) cd_play_loop_flag = true; else cd_play_loop_flag = false; if ( current_cd_track >= 0 ) playCDAudio(); // bgm, mp3, mp3loop if ( readInt() == 1 ) music_play_loop_flag = true; else music_play_loop_flag = false; if ( readInt() == 1 ) mp3save_flag = true; else mp3save_flag = false; readStr( &music_file_name ); if ( music_file_name ){ playSound(music_file_name, SOUND_MUSIC | SOUND_MIDI, music_play_loop_flag, MIX_BGM_CHANNEL); } erase_text_window_mode = readInt(); readInt(); // 1 barclearCommand(); for ( i=0 ; i<MAX_PARAM_NUM ; i++ ){ j = readInt(); if ( j != 0 ){ ai = bar_info[i] = new AnimationInfo(); ai->trans_mode = AnimationInfo::TRANS_COPY; ai->num_of_cells = 1; ai->param = j; ai->orig_pos.x = readInt(); ai->orig_pos.y = readInt(); ai->max_width = readInt(); ai->orig_pos.w = 0; ai->orig_pos.h = readInt(); ai->max_param = readInt(); ai->scalePosXY( screen_ratio1, screen_ratio2 ); for ( j=0 ; j<3 ; j++ ) ai->color[2-j] = readChar(); readChar(); // 0x00 int w = ai->max_width * ai->param / ai->max_param; if ( ai->max_width > 0 && w > 0 ) ai->orig_pos.w = w; ai->scalePosWH( screen_ratio1, screen_ratio2 ); ai->allocImage( ai->pos.w, ai->pos.h ); ai->fill( ai->color[0], ai->color[1], ai->color[2], 0xff ); } else{ readInt(); // -1 readInt(); // 0 readInt(); // 0 readInt(); // 0 readInt(); // 0 readInt(); // 0 } } prnumclearCommand(); for ( i=0 ; i<MAX_PARAM_NUM ; i++ ){ j = readInt(); if ( prnum_info[i] ){ ai = prnum_info[i] = new AnimationInfo(); ai->trans_mode = AnimationInfo::TRANS_STRING; ai->num_of_cells = 1; ai->color_list = new uchar3[1]; ai->param = j; ai->orig_pos.x = readInt(); ai->orig_pos.y = readInt(); ai->scalePosXY( screen_ratio1, screen_ratio2 ); ai->font_size_xy[0] = readInt(); ai->font_size_xy[1] = readInt(); for ( j=0 ; j<3 ; j++ ) ai->color_list[0][2-j] = readChar(); readChar(); // 0x00 char num_buf[7]; script_h.getStringFromInteger( num_buf, ai->param, 3 ); setStr( &ai->file_name, num_buf ); setupAnimationInfo( ai ); } else{ readInt(); // -1 readInt(); // 0 readInt(); // 0 readInt(); // 0 readInt(); // 0 } } readInt(); // 1 readInt(); // 0 readInt(); // 1 btndef_info.remove(); readStr( &btndef_info.image_name ); if ( btndef_info.image_name && btndef_info.image_name[0] != '\0' ){ parseTaggedString( &btndef_info ); setupAnimationInfo( &btndef_info ); SDL_SetAlpha( btndef_info.image_surface, DEFAULT_BLIT_FLAG, SDL_ALPHA_OPAQUE ); } if ( file_version >= 202 ) readArrayVariable(); readInt(); // 0 if ( readChar() == 1 ) erase_text_window_mode = 2; readChar(); // 0 readChar(); // 0 readChar(); // 0 readStr( &loop_bgm_name[0] ); readStr( &loop_bgm_name[1] ); if ( loop_bgm_name[0] ) { if ( loop_bgm_name[1] ) playSound(loop_bgm_name[1], SOUND_PRELOAD|SOUND_CHUNK, false, MIX_LOOPBGM_CHANNEL1); playSound(loop_bgm_name[0], SOUND_CHUNK, false, MIX_LOOPBGM_CHANNEL0); } if ( file_version >= 201 ){ if ( readInt() == 1 ) rubyon_flag = true; else rubyon_flag = false; sentence_font.rubyon_flag = rubyon_flag; ruby_struct.font_size_xy[0] = readInt(); ruby_struct.font_size_xy[1] = readInt(); readStr( &ruby_struct.font_name ); } if (file_version >= 204){ readInt(); for ( i=0 ; i<MAX_SPRITE2_NUM ; i++ ){ ai = &sprite2_info[i]; ai->remove(); readStr( &ai->image_name ); if ( ai->image_name ){ parseTaggedString( ai ); setupAnimationInfo( ai ); } ai->orig_pos.x = readInt(); ai->orig_pos.y = readInt(); ai->scalePosXY( screen_ratio1, screen_ratio2 ); ai->scale_x = readInt(); ai->scale_y = readInt(); ai->rot = readInt(); if ( readInt() == 1 ) ai->visible = true; else ai->visible = false; j = readInt(); if (j == -1) ai->trans = 256; else ai->trans = j; ai->blending_mode = readInt(); ai->calcAffineMatrix(); } readInt(); readInt(); if (file_version >= 205) readInt(); // 1 readInt(); readInt(); readInt(); readInt(); if (file_version >= 205) readChar(); // 0 } if (file_version >= 206){ readInt(); // 0 readInt(); // 160 readInt(); // 320 readInt(); // 480 if (file_version >= 207) underline_value = readInt(); else readInt(); // 480 } int text_num = readInt(); start_page = current_page; for ( i=0 ; i<text_num ; i++ ){ clearCurrentPage(); do{ current_page->text[current_page->text_count] = readChar(); } while( current_page->text[current_page->text_count++] ); if (file_version == 203) readChar(); // 0 current_page->text_count--; current_page = current_page->next; } clearCurrentPage(); if (file_version >= 205){ Page *page = start_page; j = readInt(); for (i=0 ; i<j ; i++){ readStr(&page->tag); page = page->next; } } else if (file_version >= 204){ readInt(); readInt(); } i = readInt(); current_label_info = script_h.getLabelByLine( i ); current_line = i - current_label_info.start_line; //printf("load %d:%d(%d-%d)\n", current_label_info.start_line, current_line, i, current_label_info.start_line); char *buf = script_h.getAddressByLine( i ); j = readInt(); for ( i=0 ; i<j ; i++ ){ while( *buf != ':' ) buf++; buf++; } script_h.setCurrent( buf ); display_mode = shelter_display_mode = DISPLAY_MODE_TEXT; clickstr_state = CLICK_NONE; draw_cursor_flag = false; return 0; }
int ONScripterLabel::loadSaveFile( int no, bool input_flag ) { char filename[16]; sprintf( filename, "save%d.dat", no ); if (loadFileIOBuf( filename )){ //fprintf( stderr, "can't open save file %s\n", filename ); return -1; } char *str = NULL; int i, j, k, address; int file_version; /* ---------------------------------------- */ /* Load magic number */ for ( i=0 ; i<(int)strlen( SAVEFILE_MAGIC_NUMBER ) ; i++ ) if ( readChar() != SAVEFILE_MAGIC_NUMBER[i] ) break; if ( i != (int)strlen( SAVEFILE_MAGIC_NUMBER ) ){ // if not ONS save file file_io_buf_ptr = 0; // check for ONS version 0 bool ons_ver0_flag = false; if ( readInt() != 1 ) ons_ver0_flag = true; for (i=0 ; i<4 ; i++) { j = readInt(); if ( (j != 1) && (j != 0) ) ons_ver0_flag = true; } for (i=0 ; i<3 ; i++) { j = readInt(); if ( (j < 0) || (j > 0xFF) ) ons_ver0_flag = true; } file_io_buf_ptr = 0; if ( !ons_ver0_flag ){ printf("Save file version is unknown\n" ); return loadSaveFile2( fileversion, input_flag ); } file_version = 0; } else{ file_version = readChar() * 100; file_version += readChar(); } //printf("Save file version is %d.%d\n", file_version/100, file_version%100 ); if ( file_version > SAVEFILE_VERSION_MAJOR*100 + SAVEFILE_VERSION_MINOR ){ fprintf( stderr, "Save file is newer than %d.%d, please use the latest ONScripter.\n", SAVEFILE_VERSION_MAJOR, SAVEFILE_VERSION_MINOR ); return -1; } if ( file_version >= 200 ) return loadSaveFile2( file_version, input_flag ); //The input_flag is only relevant for file_version 260+, //so no need to check beyond this point deleteNestInfo(); /* ---------------------------------------- */ /* Load text history */ if ( file_version >= 107 ) i = readInt(); else i = 0; sentence_font.setTateyokoMode( i ); int num_page = readInt(); for ( i=0 ; i<num_page ; i++ ){ int num_xy[2]; num_xy[0] = readInt(); num_xy[1] = readInt(); current_page->max_text = (num_xy[0]*2+1)*num_xy[1]; if (sentence_font.getTateyokoMode() == Fontinfo::TATE_MODE) current_page->max_text = (num_xy[1]*2+1)*num_xy[0]; int xy[2]; xy[0] = readInt(); xy[1] = readInt(); if ( current_page->text ) delete[] current_page->text; current_page->text = new char[ current_page->max_text ]; current_page->text_count = 0; char ch1, ch2; for ( j=0, k=0 ; j<num_xy[0] * num_xy[1] ; j++ ){ ch1 = readChar(); ch2 = readChar(); if ( (unsigned char) ch1 == 0x80 && (unsigned char) ch2 == 0x40 ){ k += 2; } else{ if ( ch1 ){ current_page->add( ch1 ); k++; } if ( ch1 & 0x80 || ch2 ){ current_page->add( ch2 ); k++; } } if ( k >= num_xy[0] * 2 ){ current_page->add( 0x0a ); k = 0; } } current_page = current_page->next; if ( i==0 ){ for ( j=0 ; j<max_page_list - num_page ; j++ ) current_page = current_page->next; start_page = current_page; } } /* ---------------------------------------- */ /* Load sentence font */ j = readInt(); //sentence_font.is_valid = (j==1)?true:false; sentence_font.font_size_xy[0] = readInt(); if ( file_version >= 100 ){ sentence_font.font_size_xy[1] = readInt(); } else{ sentence_font.font_size_xy[1] = sentence_font.font_size_xy[0]; } sentence_font.top_xy[0] = readInt(); sentence_font.top_xy[1] = readInt(); sentence_font.num_xy[0] = readInt(); sentence_font.num_xy[1] = readInt(); sentence_font.xy[0] = readInt()*2; sentence_font.xy[1] = readInt()*2; sentence_font.pitch_xy[0] = readInt(); sentence_font.pitch_xy[1] = readInt(); sentence_font.wait_time = readInt(); sentence_font.is_bold = (readInt()==1)?true:false; sentence_font.is_shadow = (readInt()==1)?true:false; sentence_font.is_transparent = (readInt()==1)?true:false; for (j=0, k=0, i=0 ; i<current_page->text_count ; i++){ if (j == sentence_font.xy[1] && (k > sentence_font.xy[0] || current_page->text[i] == 0x0a)) break; if (current_page->text[i] == 0x0a){ j+=2; k=0; } else k++; } current_page->text_count = i; /* Dummy, must be removed later !! */ for ( i=0 ; i<8 ; i++ ){ j = readInt(); //sentence_font.window_color[i] = j; } /* Should be char, not integer !! */ for ( i=0 ; i<3 ; i++ ) sentence_font.window_color[i] = readInt(); readStr( &sentence_font_info.image_name ); sentence_font_info.orig_pos.x = readInt(); sentence_font_info.orig_pos.y = readInt(); sentence_font_info.orig_pos.w = readInt(); sentence_font_info.orig_pos.h = readInt(); UpdateAnimPosXY(&sentence_font_info); UpdateAnimPosWH(&sentence_font_info); if ( !sentence_font.is_transparent ){ parseTaggedString( &sentence_font_info ); setupAnimationInfo( &sentence_font_info ); } sentence_font.ttf_font = NULL; clickstr_state = readInt(); new_line_skip_flag = (readInt()==1)?true:false; if ( file_version >= 103 ){ erase_text_window_mode = readInt(); } /* ---------------------------------------- */ /* Load link label info */ int offset = 0; while( 1 ){ readStr( &str ); current_label_info = script_h.lookupLabel( str ); current_line = readInt() + 2; char *buf = current_label_info.label_header; while( buf < current_label_info.start_address ){ if ( *buf == 0x0a ) current_line--; buf++; } offset = readInt(); script_h.setCurrent( current_label_info.label_header ); script_h.skipLine( current_line ); if ( file_version <= 104 ) { if ( file_version >= 102 ) readInt(); address = readInt(); } else{ offset += readInt(); } if ( readChar() == 0 ) break; last_nest_info->next = new NestInfo(); last_nest_info->next->previous = last_nest_info; last_nest_info = last_nest_info->next; last_nest_info->next_script = script_h.getCurrent() + offset; } script_h.setCurrent( script_h.getCurrent() + offset ); int tmp_event_mode = readChar(); /* ---------------------------------------- */ /* Load variables */ readVariables( 0, 200 ); /* ---------------------------------------- */ /* Load monocro flag */ monocro_flag = (readChar()==1)?true:false; if ( file_version >= 101 ){ monocro_flag = (readChar()==1)?true:false; } for ( i=0 ; i<3 ; i++ ) monocro_color[i] = readChar(); if ( file_version >= 101 ){ for ( i=0 ; i<3 ; i++ ) monocro_color[i] = readChar(); readChar(); // obsolete, need_refresh_flag } for ( i=0 ; i<256 ; i++ ){ monocro_color_lut[i][0] = (monocro_color[0] * i) >> 8; monocro_color_lut[i][1] = (monocro_color[1] * i) >> 8; monocro_color_lut[i][2] = (monocro_color[2] * i) >> 8; } /* Load nega flag */ if ( file_version >= 104 ){ nega_mode = (unsigned char)readChar(); } /* ---------------------------------------- */ /* Load current images */ bg_info.remove(); bg_info.color[0] = (unsigned char)readChar(); bg_info.color[1] = (unsigned char)readChar(); bg_info.color[2] = (unsigned char)readChar(); bg_info.num_of_cells = 1; readStr( &bg_info.file_name ); setupAnimationInfo( &bg_info ); int bg_effect_image = readChar(); if (bg_effect_image == 0){ // COLOR_EFFECT_IMAGE bg_info.allocImage( screen_width, screen_height ); bg_info.fill( bg_info.color[0], bg_info.color[1], bg_info.color[2], 0xff ); bg_info.pos.x = 0; bg_info.pos.y = 0; } bg_info.trans_mode = AnimationInfo::TRANS_COPY; for ( i=0 ; i<3 ; i++ ) tachi_info[i].remove(); for ( i=0 ; i<MAX_SPRITE_NUM ; i++ ) sprite_info[i].remove(); /* ---------------------------------------- */ /* Load Tachi image and Sprite */ for ( i=0 ; i<3 ; i++ ){ readStr( &tachi_info[i].image_name ); if ( tachi_info[i].image_name ){ parseTaggedString( &tachi_info[i] ); setupAnimationInfo( &tachi_info[ i ] ); tachi_info[ i ].pos.x = screen_width * (i+1) / 4 - tachi_info[ i ].pos.w / 2; tachi_info[ i ].orig_pos.x = ContractPos(tachi_info[ i ].pos.x); tachi_info[ i ].pos.y = ExpandPos(underline_value) - tachi_info[ i ].image_surface->h + 1; tachi_info[ i ].orig_pos.y = ContractPos(tachi_info[ i ].pos.y); } } /* ---------------------------------------- */ /* Load current sprites */ for ( i=0 ; i<256 ; i++ ){ sprite_info[i].visible = (readInt()==1)?true:false; sprite_info[i].orig_pos.x = readInt(); sprite_info[i].orig_pos.y = readInt(); UpdateAnimPosXY(&sprite_info[i]); sprite_info[i].trans = readInt(); readStr( &sprite_info[i].image_name ); if ( sprite_info[i].image_name ){ parseTaggedString( &sprite_info[i] ); setupAnimationInfo( &sprite_info[i] ); } } /* ---------------------------------------- */ /* Load current playing CD track */ stopCommand(); loopbgmstopCommand(); stopAllDWAVE(); current_cd_track = (Sint8)readChar(); bool play_once_flag = (readChar()==1)?true:false; if ( current_cd_track == -2 ){ readStr( &seqmusic_file_name ); seqmusic_play_loop_flag = !play_once_flag; setStr( &music_file_name, NULL ); music_play_loop_flag = false; } else{ readStr( &music_file_name ); if ( music_file_name ){ music_play_loop_flag = !play_once_flag; cd_play_loop_flag = false; } else{ music_play_loop_flag = false; cd_play_loop_flag = !play_once_flag; } setStr( &seqmusic_file_name, NULL ); seqmusic_play_loop_flag = false; } if ( current_cd_track >= 0 ){ playCDAudio(); } else if ( seqmusic_file_name && seqmusic_play_loop_flag ){ playSound(seqmusic_file_name, SOUND_SEQMUSIC, seqmusic_play_loop_flag); } else if ( music_file_name && music_play_loop_flag ){ playSound(music_file_name, SOUND_WAVE | SOUND_OGG_STREAMING | SOUND_MP3, music_play_loop_flag, MIX_BGM_CHANNEL); } /* ---------------------------------------- */ /* Load rmode flag */ rmode_flag = (readChar()==1)?true:false; /* ---------------------------------------- */ /* Load text on flag */ text_on_flag = (readChar()==1)?true:false; restoreTextBuffer(); num_chars_in_sentence = 0; cached_page = current_page; display_mode = shelter_display_mode = DISPLAY_MODE_TEXT; event_mode = tmp_event_mode; if ( event_mode & WAIT_BUTTON_MODE ) event_mode = WAIT_SLEEP_MODE; // Re-execute the selectCommand, etc. if ( event_mode & WAIT_SLEEP_MODE ) event_mode &= ~WAIT_SLEEP_MODE; else event_mode |= WAIT_TIMER_MODE; if (event_mode & WAIT_INPUT_MODE) event_mode |= WAIT_TEXT_MODE; draw_cursor_flag = (clickstr_state == CLICK_NONE)?false:true; return 0; }
int ONScripterLabel::loadSaveFile2( int file_version ) { deleteNestInfo(); int i, j; readInt(); // 1 if ( readInt() == 1 ) sentence_font.is_bold = true; else sentence_font.is_bold = false; if ( readInt() == 1 ) sentence_font.is_shadow = true; else sentence_font.is_shadow = false; readInt(); // 0 rmode_flag = (readInt()==1)?true:false; sentence_font.color[0] = readInt(); sentence_font.color[1] = readInt(); sentence_font.color[2] = readInt(); cursor_info[0].remove(); readStr( &cursor_info[0].image_name ); if ( cursor_info[0].image_name ){ parseTaggedString( &cursor_info[0] ); setupAnimationInfo( &cursor_info[0] ); if ( cursor_info[0].image_surface ) cursor_info[0 ].visible = true; } cursor_info[1].remove(); readStr( &cursor_info[1].image_name ); if ( cursor_info[1].image_name ){ parseTaggedString( &cursor_info[1] ); setupAnimationInfo( &cursor_info[1] ); if ( cursor_info[1].image_surface ) cursor_info[1 ].visible = true; } window_effect.effect = readInt(); window_effect.duration = readInt(); readStr( &window_effect.anim.image_name ); // probably sentence_font.clear(); sentence_font.ttf_font = NULL; sentence_font.top_xy[0] = readInt(); sentence_font.top_xy[1] = readInt(); #ifndef RCA_SCALE sentence_font.num_xy[0] = readInt(); sentence_font.num_xy[1] = readInt(); #else sentence_font.num_xy[0] = readInt() * scr_stretch_x; sentence_font.num_xy[1] = readInt() * scr_stretch_y; #endif sentence_font.font_size_xy[0] = readInt(); sentence_font.font_size_xy[1] = readInt(); sentence_font.pitch_xy[0] = readInt(); sentence_font.pitch_xy[1] = readInt(); for ( i=0 ; i<3 ; i++ ) sentence_font.window_color[2-i] = readChar(); if ( readChar() == 0x00 ) sentence_font.is_transparent = true; else sentence_font.is_transparent = false; sentence_font.wait_time = readInt(); sentence_font_info.pos.x = readInt() * screen_ratio1 / screen_ratio2; sentence_font_info.pos.y = readInt() * screen_ratio1 / screen_ratio2; #ifndef RCA_SCALE sentence_font_info.pos.w = (readInt() + 1 - sentence_font_info.pos.x * screen_ratio1 / screen_ratio2) * screen_ratio1 / screen_ratio2; sentence_font_info.pos.h = (readInt() + 1 - sentence_font_info.pos.y * screen_ratio1 / screen_ratio2) * screen_ratio1 / screen_ratio2; #else sentence_font_info.pos.w = (readInt() + 1 - sentence_font_info.pos.x * screen_ratio1 / screen_ratio2) * screen_ratio1 * scr_stretch_x / screen_ratio2; sentence_font_info.pos.h = (readInt() + 1 - sentence_font_info.pos.y * screen_ratio1 / screen_ratio2) * screen_ratio1 * scr_stretch_y / screen_ratio2; #endif readStr( &sentence_font_info.image_name ); if ( !sentence_font.is_transparent && sentence_font_info.image_name ){ parseTaggedString( &sentence_font_info ); setupAnimationInfo( &sentence_font_info ); } if ( readInt() == 1 ) cursor_info[0].abs_flag = false; else cursor_info[0].abs_flag = true; if ( readInt() == 1 ) cursor_info[1].abs_flag = false; else cursor_info[1].abs_flag = true; cursor_info[0].pos.x = readInt() * screen_ratio1 / screen_ratio2; cursor_info[1].pos.x = readInt() * screen_ratio1 / screen_ratio2; cursor_info[0].pos.y = readInt() * screen_ratio1 / screen_ratio2; cursor_info[1].pos.y = readInt() * screen_ratio1 / screen_ratio2; // load background surface bg_info.remove(); readStr( &bg_info.file_name ); createBackground(); for ( i=0 ; i<3 ; i++ ){ tachi_info[i].remove(); readStr( &tachi_info[i].image_name ); if ( tachi_info[i].image_name ){ parseTaggedString( &tachi_info[i] ); setupAnimationInfo( &tachi_info[i] ); #ifdef RCA_SCALE if (scr_stretch_y > 1.0) { // RCA: Stretch characters to screen size. // Note all stretches are with Y-scale, so they don't get distorted (FIXME assumes widescreen) SDL_Surface* src = tachi_info[i].image_surface; SDL_PixelFormat *fmt = src->format; SDL_Surface* dst = SDL_CreateRGBSurface( SDL_SWSURFACE, scr_stretch_y*src->w, scr_stretch_y*src->h, fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask ); resizeSurface( src, dst ); tachi_info[i].image_surface = dst; tachi_info[i].pos.w = src->w*scr_stretch_y; tachi_info[i].pos.h = src->h*scr_stretch_y; SDL_FreeSurface( src ); } #endif } } #ifndef RCA_SCALE for ( i=0 ; i<3 ; i++ ) tachi_info[i].pos.x = readInt() * screen_ratio1 / screen_ratio2; #else for ( i=0 ; i<3 ; i++ ) { readInt(); tachi_info[i].pos.x = screen_width * (i+1) / 4 - tachi_info[i].pos.w / 2; // RCA Ignore saved value } #endif #ifndef RCA_SCALE for ( i=0 ; i<3 ; i++ ) tachi_info[i].pos.y = readInt() * screen_ratio1 / screen_ratio2; #else for ( i=0 ; i<3 ; i++ ) { readInt(); if (tachi_info[i].image_surface) tachi_info[i].pos.y = underline_value - tachi_info[i].image_surface->h + 1; // RCA Ignore saved value } #endif readInt(); // 0 readInt(); // 0 readInt(); // 0 if (file_version >= 203){ readInt(); // -1 readInt(); // -1 readInt(); // -1 } for ( i=0 ; i<MAX_SPRITE_NUM ; i++ ){ sprite_info[i].remove(); readStr( &sprite_info[i].image_name ); if ( sprite_info[i].image_name ){ parseTaggedString( &sprite_info[i] ); setupAnimationInfo( &sprite_info[i] ); } sprite_info[i].pos.x = readInt() * screen_ratio1 / screen_ratio2; sprite_info[i].pos.y = readInt() * screen_ratio1 / screen_ratio2; if ( readInt() == 1 ) sprite_info[i].visible = true; else sprite_info[i].visible = false; sprite_info[i].current_cell = readInt(); if (file_version >= 203) { int trans = readInt(); if (trans == -1) trans = 256; sprite_info[i].trans = trans; } } readVariables( 0, script_h.global_variable_border ); // nested info int num_nest =readInt(); last_nest_info = &root_nest_info; if (num_nest > 0){ file_io_buf_ptr += (num_nest-1)*4; while( num_nest > 0 ){ NestInfo *info = new NestInfo(); if (last_nest_info == &root_nest_info) last_nest_info = info; i = readInt(); if (i > 0){ info->nest_mode = NestInfo::LABEL; info->next_script = script_h.getAddress( i ); file_io_buf_ptr -= 8; num_nest--; } else{ info->nest_mode = NestInfo::FOR; info->next_script = script_h.getAddress( -i ); file_io_buf_ptr -= 16; info->var_no = readInt(); info->to = readInt(); info->step = readInt(); file_io_buf_ptr -= 16; num_nest -= 4; } info->next = root_nest_info.next; if (root_nest_info.next) root_nest_info.next->previous = info; root_nest_info.next = info; info->previous = &root_nest_info; } num_nest = readInt(); file_io_buf_ptr += num_nest*4; } if (readInt() == 1) monocro_flag = true; else monocro_flag = false; for ( i=0 ; i<3 ; i++ ) monocro_color[2-i] = readInt(); for ( i=0 ; i<256 ; i++ ){ monocro_color_lut[i][0] = (monocro_color[0] * i) >> 8; monocro_color_lut[i][1] = (monocro_color[1] * i) >> 8; monocro_color_lut[i][2] = (monocro_color[2] * i) >> 8; } nega_mode = readInt(); // ---------------------------------------- // Sound stopCommand(); loopbgmstopCommand(); stopAllDWAVE(); readStr( &midi_file_name ); // MIDI file readStr( &wave_file_name ); // wave, waveloop i = readInt(); if ( i >= 0 ) current_cd_track = i; // play, playonce MIDI if ( readInt() == 1 ){ midi_play_loop_flag = true; current_cd_track = -2; playSound(midi_file_name, SOUND_MIDI, midi_play_loop_flag); } else midi_play_loop_flag = false; // wave, waveloop if ( readInt() == 1 ) wave_play_loop_flag = true; else wave_play_loop_flag = false; if ( wave_file_name && wave_play_loop_flag ) playSound(wave_file_name, SOUND_WAVE|SOUND_OGG, wave_play_loop_flag, MIX_WAVE_CHANNEL); // play, playonce if ( readInt() == 1 ) cd_play_loop_flag = true; else cd_play_loop_flag = false; if ( current_cd_track >= 0 ) playCDAudio(); // bgm, mp3, mp3loop if ( readInt() == 1 ) music_play_loop_flag = true; else music_play_loop_flag = false; if ( readInt() == 1 ) mp3save_flag = true; else mp3save_flag = false; readStr( &music_file_name ); if ( music_file_name ){ playSound(music_file_name, SOUND_WAVE | SOUND_OGG_STREAMING | SOUND_MP3 | SOUND_MIDI, music_play_loop_flag, MIX_BGM_CHANNEL); } erase_text_window_mode = readInt(); readInt(); // 1 barclearCommand(); for ( i=0 ; i<MAX_PARAM_NUM ; i++ ){ j = readInt(); if ( j != 0 ){ bar_info[i] = new AnimationInfo(); bar_info[i]->trans_mode = AnimationInfo::TRANS_COPY; bar_info[i]->num_of_cells = 1; bar_info[i]->param = j; bar_info[i]->pos.x = readInt() * screen_ratio1 / screen_ratio2; bar_info[i]->pos.y = readInt() * screen_ratio1 / screen_ratio2; bar_info[i]->max_width = readInt() * screen_ratio1 / screen_ratio2; bar_info[i]->pos.h = readInt() * screen_ratio1 / screen_ratio2; bar_info[i]->max_param = readInt(); for ( j=0 ; j<3 ; j++ ) bar_info[i]->color[2-j] = readChar(); readChar(); // 0x00 int w = bar_info[i]->max_width * bar_info[i]->param / bar_info[i]->max_param; if ( bar_info[i]->max_width > 0 && w > 0 ){ bar_info[i]->pos.w = w; bar_info[i]->allocImage( bar_info[i]->pos.w, bar_info[i]->pos.h ); bar_info[i]->fill( bar_info[i]->color[0], bar_info[i]->color[1], bar_info[i]->color[2], 0xff ); } } else{ readInt(); // -1 readInt(); // 0 readInt(); // 0 readInt(); // 0 readInt(); // 0 readInt(); // 0 } } prnumclearCommand(); for ( i=0 ; i<MAX_PARAM_NUM ; i++ ){ j = readInt(); if ( prnum_info[i] ){ prnum_info[i] = new AnimationInfo(); prnum_info[i]->trans_mode = AnimationInfo::TRANS_STRING; prnum_info[i]->num_of_cells = 1; prnum_info[i]->color_list = new uchar3[1]; prnum_info[i]->param = j; prnum_info[i]->pos.x = readInt() * screen_ratio1 / screen_ratio2; prnum_info[i]->pos.y = readInt() * screen_ratio1 / screen_ratio2; prnum_info[i]->font_size_xy[0] = readInt(); prnum_info[i]->font_size_xy[1] = readInt(); for ( j=0 ; j<3 ; j++ ) prnum_info[i]->color_list[0][2-j] = readChar(); readChar(); // 0x00 char num_buf[7]; script_h.getStringFromInteger( num_buf, prnum_info[i]->param, 3 ); setStr( &prnum_info[i]->file_name, num_buf ); setupAnimationInfo( prnum_info[i] ); } else{ readInt(); // -1 readInt(); // 0 readInt(); // 0 readInt(); // 0 readInt(); // 0 } } readInt(); // 1 readInt(); // 0 readInt(); // 1 btndef_info.remove(); readStr( &btndef_info.image_name ); if ( btndef_info.image_name && btndef_info.image_name[0] != '\0' ){ parseTaggedString( &btndef_info ); setupAnimationInfo( &btndef_info ); SDL_SetAlpha( btndef_info.image_surface, DEFAULT_BLIT_FLAG, SDL_ALPHA_OPAQUE ); } if ( file_version >= 202 ) readArrayVariable(); readInt(); // 0 if ( readChar() == 1 ) erase_text_window_mode = 2; readChar(); // 0 readChar(); // 0 readChar(); // 0 readStr( &loop_bgm_name[0] ); readStr( &loop_bgm_name[1] ); if ( loop_bgm_name[0] ) { if ( loop_bgm_name[1] ) playSound(loop_bgm_name[1], SOUND_PRELOAD|SOUND_WAVE|SOUND_OGG, false, MIX_LOOPBGM_CHANNEL1); playSound(loop_bgm_name[0], SOUND_WAVE|SOUND_OGG, false, MIX_LOOPBGM_CHANNEL0); } if ( file_version >= 201 ){ if ( readInt() == 1 ) rubyon_flag = true; else rubyon_flag = false; ruby_struct.font_size_xy[0] = readInt(); ruby_struct.font_size_xy[1] = readInt(); readStr( &ruby_struct.font_name ); sentence_font.setRubyOnFlag(rubyon_flag); } if (file_version >= 204){ readInt(); for ( i=0 ; i<MAX_SPRITE2_NUM ; i++ ){ sprite2_info[i].remove(); readStr( &sprite2_info[i].image_name ); if ( sprite2_info[i].image_name ){ parseTaggedString( &sprite2_info[i] ); setupAnimationInfo( &sprite2_info[i] ); } sprite2_info[i].pos.x = readInt() * screen_ratio1 / screen_ratio2; sprite2_info[i].pos.y = readInt() * screen_ratio1 / screen_ratio2; sprite2_info[i].scale_x = readInt(); sprite2_info[i].scale_y = readInt(); sprite2_info[i].rot = readInt(); if ( readInt() == 1 ) sprite2_info[i].visible = true; else sprite2_info[i].visible = false; j = readInt(); if (j == -1) sprite2_info[i].trans = 256; else sprite2_info[i].trans = j; sprite2_info[i].blending_mode = readInt(); sprite2_info[i].calcAffineMatrix(); } readInt(); readInt(); if (file_version >= 205) readInt(); // 1 readInt(); readInt(); readInt(); readInt(); if (file_version >= 205) readChar(); // 0 } if (file_version >= 206){ readInt(); // 0 readInt(); // 160 readInt(); // 320 readInt(); // 480 readInt(); // 480 } int text_num = readInt(); //Mion: clearing page then moving to next eliminates buffer error start_page = current_page->next; clearCurrentPage(); current_page = start_page; for ( i=0 ; i<text_num ; i++ ){ clearCurrentPage(); do{ current_page->text[current_page->text_count] = readChar(); } while( current_page->text[current_page->text_count++] ); if (file_version == 203) readChar(); // 0 current_page->text_count--; current_page = current_page->next; } clearCurrentPage(); if (file_version >= 205){ Page *page = start_page; j = readInt(); for (i=0 ; i<j ; i++){ readStr(&page->tag); page = page->next; } } else if (file_version >= 204){ readInt(); readInt(); } i = readInt(); current_label_info = script_h.getLabelByLine( i ); current_line = i - current_label_info.start_line; //printf("load %d:%d(%d-%d)\n", current_label_info.start_line, current_line, i, current_label_info.start_line); char *buf = script_h.getAddressByLine( i ); j = readInt(); for ( i=0 ; i<j ; i++ ){ while( *buf != ':' ) buf++; buf++; } script_h.setCurrent( buf ); display_mode = shelter_display_mode = DISPLAY_MODE_NORMAL; clickstr_state = CLICK_NONE; event_mode = 0;//WAIT_SLEEP_MODE; draw_cursor_flag = false; return 0; }
void stopHandler(int signalNumber){ stopCommand(NULL); }
int main (int argc, char* argv[]) { printf("DeckControl Test Application\n\n"); IDeckLinkIterator* deckLinkIterator; IDeckLink* deckLink; int numDevices = 0; HRESULT result; fdSerial = -1; // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system deckLinkIterator = CreateDeckLinkIteratorInstance(); if (deckLinkIterator == NULL) { fprintf(stderr, "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.\n"); return 1; } // Enumerate all cards in this system while (deckLinkIterator->Next(&deckLink) == S_OK) { CFStringRef deviceNameCFString = NULL; // Increment the total number of DeckLink cards found numDevices++; if (numDevices > 1) printf("\n\n"); // *** Print the model name of the DeckLink card result = deckLink->GetModelName(&deviceNameCFString); if (result == S_OK) { IDeckLinkAttributes* deckLinkAttributes; char deviceName[64]; HRESULT attributeResult; CFStringRef serialName; bool serialSupported; CFStringGetCString(deviceNameCFString, deviceName, sizeof(deviceName), kCFStringEncodingMacRoman); printf("Found Blackmagic device: %s\n", deviceName); attributeResult = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (attributeResult != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface"); } else { attributeResult = deckLinkAttributes->GetFlag(BMDDeckLinkHasSerialPort, &serialSupported); // are serial ports supported on device? if (attributeResult == S_OK && serialSupported) { attributeResult = deckLinkAttributes->GetString(BMDDeckLinkSerialPortDeviceName, &serialName); // get serial port name if (attributeResult == S_OK) { char portName[64]; CFStringGetCString(serialName, portName, sizeof(portName), kCFStringEncodingMacRoman); printf("Serial port name: %s\n",portName); if (openSerialDevice((char*)&portName)== true) // open serial port { printf("Device opened\n"); playCommand(); // Play deck, printf("Delay 3 seconds\n"); sleep(3); timeCodeCommand(); // DisplayTC printf("Delay 3 seconds\n"); sleep(3); stopCommand(); // Stop deck closeSerialDevice(); // close serial port } else printf("Device open fail\n"); CFRelease(serialName); } else printf("Unable to get serial port device name\n"); } else printf("Serial port not supported\n"); } CFRelease(deviceNameCFString); // Release the IDeckLink instance when we've finished with it to prevent leaks } deckLink->Release(); } if (deckLinkIterator) deckLinkIterator->Release(); // If no DeckLink cards were found in the system, inform the user if (numDevices == 0) printf("No Blackmagic Design devices were found.\n"); printf("\n"); return 0; }