From b623f5953691b2a0614e6f1f4def86bdbb9a4113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 8 Aug 2020 11:53:00 +0200 Subject: New upstream version 5.2.0Beta2.1 --- app/bin/ctrain.c | 139 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 101 insertions(+), 38 deletions(-) (limited to 'app/bin/ctrain.c') diff --git a/app/bin/ctrain.c b/app/bin/ctrain.c index fe41a39..b15cb91 100644 --- a/app/bin/ctrain.c +++ b/app/bin/ctrain.c @@ -58,6 +58,7 @@ struct extraData { long state; carItem_p item; double speed; + BOOL_T pencils; BOOL_T direction; BOOL_T autoReverse; trainStatus_e status; @@ -92,7 +93,7 @@ static wButton_p newcarB; static void ControllerDialogSyncAll(void); static STATUS_T CmdTrain(wAction_t, coOrd); static wMenu_p trainPopupM; -static wMenuPush_p trainPopupMI[8]; +static wMenuPush_p trainPopupMI[10]; static track_p followTrain; static coOrd followCenter; static BOOL_T trainsTimeoutPending; @@ -311,6 +312,24 @@ BOOL_T TraverseTrack2( return TRUE; } +/*************** + * When a track is deleted, cross check that the Traverse Track reference is removed. + */ +EXPORT void CheckCarTraverse(track_p track) { + + track_p car; + for (car=NULL; TrackIterate(&car);) { + if (GetTrkType(car) == T_CAR) { + struct extraData * xx = GetTrkExtraData(car); + if (xx->trvTrk.trk == track) { + xx->trvTrk.trk=NULL; + xx->status = ST_NotOnTrack; + } + } + } + +} + static BOOL_T drawCarEnable = TRUE; @@ -358,7 +377,9 @@ static void DrawCar( } } - CarItemDraw(d, xx->item, color, xx->direction, IsLocoMaster(xx), coupler); + + + CarItemDraw(d, xx->item, color, xx->direction, IsLocoMaster(xx), coupler, xx->pencils, xx->trvTrk.trk); } @@ -467,10 +488,10 @@ static void DeleteCar( } -static void ReadCar( +static BOOL_T ReadCar( char * line) { - CarItemRead(line); + return CarItemRead(line); } @@ -521,6 +542,29 @@ static BOOL_T QueryCar(track_p trk, int query) } } +static BOOL_T StoreCar( + track_p car, + void **data, + long * len) { + + struct extraData *xx = GetTrkExtraData(car); + return StoreCarItem(xx->item,data,len); + +} + +static BOOL_T ReplayCar (track_p car, void *data,long len) { + + struct extraData *xx = GetTrkExtraData(car); + return ReplayCarItem(xx->item,data,len); + +} + + +static wBool_t CompareCar( track_cp trk1, track_cp trk2 ) +{ + return TRUE; +} + static trackCmd_t carCmds = { "CAR ", @@ -548,6 +592,16 @@ static trackCmd_t carCmds = { QueryCar, /* query */ NULL, /* ungroup */ NULL, /* flip */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + ReplayCar, + StoreCar, + NULL, /*activate*/ + CompareCar }; /* @@ -699,13 +753,13 @@ static void SpeedRedraw( pts[2][1] = pts[3][1] = y+SLIDER_THICKNESS/2; pts[0][0] = pts[3][0] = 0; pts[1][0] = pts[2][0] = SLIDER_WIDTH; - wDrawFilledPolygon(d, pts, 4, drawColor, 0); + wDrawPolygon(d, pts, NULL, 4, drawColor, 0, 0, 0, 1, 0); drawColor = wDrawFindColor(wRGB(220, 220, 220)); pts[0][1] = pts[1][1] = y+SLIDER_THICKNESS/2; pts[2][1] = pts[3][1] = y; pts[0][0] = pts[3][0] = 0; pts[1][0] = pts[2][0] = SLIDER_WIDTH; - wDrawFilledPolygon(d, pts, 4, drawColor, 0); + wDrawPolygon(d, pts, NULL, 4, drawColor, 0, 0, 0, 1, 0); wDrawLine(d, 0, y, SLIDER_WIDTH, y, 1, wDrawLineSolid, drawColorRed, 0); wDrawLine(d, 0, y+SLIDER_THICKNESS/2, SLIDER_WIDTH, y+SLIDER_THICKNESS/2, 1, wDrawLineSolid, drawColorBlack, 0); @@ -1068,13 +1122,11 @@ static void MoveMainWindow( dist *= factor; Translate(&pos, pos, angle, dist); - //DrawMapBoundingBox(FALSE); - mainCenter = pos; mainD.orig.x = pos.x-mainD.size.x/2;; mainD.orig.y = pos.y-mainD.size.y/2;; - MainRedraw(); - MapRedraw(); - //DrawMapBoundingBox(TRUE); + panCenter = pos; + LOG( log_pan, 2, ( "PanCenter:%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) ); + MainLayout( TRUE, TRUE ); // MoveTrainWindow } @@ -1197,7 +1249,7 @@ static void ControllerDialogUpdate( wButtonSetLabel((wButton_p)pg->paramPtr[I_DIR].control, (dlg->direction?_("Reverse"):_("Forward"))); SetTrainDirection(dlg->train); - DrawAllCars(); + TempRedraw(); // ctrain: change direction break; case I_STOP: @@ -1277,7 +1329,6 @@ static void DrawAllCars(void) drawCarEnable = TRUE; wDrawDelayUpdate(mainD.d, TRUE); wDrawRestoreImage(mainD.d); - DrawMarkers(); DrawPositionIndicators(); for (car=NULL; TrackIterate(&car);) { @@ -1291,7 +1342,7 @@ static void DrawAllCars(void) hi.y = lo.y + size.x; if (!OFF_MAIND(lo, hi)) { - DrawCar(car, &mainD, wDrawColorBlack); + DrawCar(car, &tempD, wDrawColorBlack); } } } @@ -1334,12 +1385,9 @@ static void PlaceCar( { struct extraData *xx = GetTrkExtraData(car); DIST_T dists[2]; - int dir; CarItemPlace(xx->item, &xx->trvTrk, dists); - for (dir=0; dir<2; dir++) { - xx->couplerPos[dir] = CarItemFindCouplerMountPoint(xx->item, xx->trvTrk, dir); - } + CarItemFindCouplerMountPoint(xx->item, xx->trvTrk, xx->couplerPos); car->endPt[0].angle = xx->trvTrk.angle; Translate(&car->endPt[0].pos, xx->trvTrk.pos, car->endPt[0].angle, dists[0]); @@ -1787,6 +1835,9 @@ static BOOL_T CheckCoupling( /* Move second train back along track half a car length */ TraverseTrack2(&trvTrk1, distc/2.0-dist); + if ( trvTrk0.trk == NULL || trvTrk1.trk == NULL ) + // fell off the end of track + return FALSE; /* If tracks are not the same - dont couple */ if (trvTrk1.trk != trvTrk0.trk) { @@ -2076,7 +2127,7 @@ static BOOL_T MoveTrains(long timeD) } ControllerDialogSyncAll(); - DrawAllCars(); + TempRedraw(); // MoveTrains return trains_moved; } @@ -2427,6 +2478,8 @@ static BOOL_T TrainOnMovableTrack( #define DO_MUMASTER (5) #define DO_CHANGEDIR (6) #define DO_STOP (7) +#define DO_PENCILS_ON (8) +#define DO_PENCILS_OFF (9) static track_p trainFuncCar; static coOrd trainFuncPos; static wButton_p trainPauseB; @@ -2470,12 +2523,11 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) Dtrain.state = 0; trk0 = NULL; tempSegs_da.cnt = 0; - DYNARR_SET(trkSeg_t, tempSegs_da, 8); + DYNARR_SET(trkSeg_t, tempSegs_da, 8); RestartTrains(); wButtonSetLabel(trainPauseB, (char*)goI); trainTime0 = 0; AttachTrains(); - DrawAllCars(); curTrainDlg->train = NULL; curTrainDlg->speed = -1; wDrawClear((wDraw_p)curTrainDlg->trainPGp->paramPtr[I_SLIDER].control); @@ -2484,6 +2536,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) wShow(curTrainDlg->win); wControlShow((wControl_p)newcarB, (toolbarSet&(1<pencils = FALSE; dist = CarItemCoupledLength(xx->item)/2.0; Translate(&pos, xx->trvTrk.pos, xx->trvTrk.angle, dist); SetTrkEndPoint(currCar, 0, pos, xx->trvTrk.angle); @@ -2578,7 +2632,6 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) SetCurTrain(trk0); } - DrawAllCars(); return C_CONTINUE; case C_MOVE: @@ -2589,7 +2642,6 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) pos.x += delta.x; pos.y += delta.y; pos0 = pos; - /*DrawCars( &tempD, currCar, FALSE );*/ xx = GetTrkExtraData(currCar); trk0 = OnTrack(&pos0, FALSE, TRUE); @@ -2613,7 +2665,6 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) PlaceTrainInit(currCar, trk0, pos0, xx->trvTrk.angle, (MyGetKeyState()&WKEY_SHIFT) == 0); ControllerDialogSync(curTrainDlg); - DrawAllCars(); return C_CONTINUE; case C_UP: @@ -2629,11 +2680,9 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) } Dtrain.state = 1; - /*MainRedraw();*/ ControllerDialogSync(curTrainDlg); } - DrawAllCars(); InfoSubstituteControls(NULL, NULL); currCar = trk0 = NULL; currCarItemPtr = NULL; @@ -2668,14 +2717,12 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) xx->trvTrk.pos = pos1; xx->trvTrk.angle = angle1; PlaceTrain(trk1, FALSE, TRUE); - DrawAllCars(); } } programMode = MODE_TRAIN; trk0 = NULL; - MainRedraw(); //Make sure track is redrawn after switch thrown - MapRedraw(); + MainRedraw(); //CmdTrain: Make sure track is redrawn after switch thrown } else { trk0 = FindCar(&pos); @@ -2704,6 +2751,14 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) } xx = GetTrkExtraData(trainFuncCar); + if (xx->pencils) { + wMenuPushEnable(trainPopupMI[DO_PENCILS_OFF], TRUE); + wMenuPushEnable(trainPopupMI[DO_PENCILS_ON], FALSE); + } else { + wMenuPushEnable(trainPopupMI[DO_PENCILS_OFF], FALSE); + wMenuPushEnable(trainPopupMI[DO_PENCILS_ON], TRUE); + } + trk0 = FindMasterLoco(trainFuncCar,NULL); dir = IsAligned(xx->trvTrk.angle, FindAngle(xx->trvTrk.pos, trainFuncPos)) ? 0 : 1; @@ -2761,8 +2816,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) wHide(curTrainDlg->win); } - MainRedraw(); - MapRedraw(); + MainRedraw(); // CmdTrain: Exit curTrainDlg->train = NULL; return C_CONTINUE; @@ -2844,8 +2898,6 @@ static void CmdTrainExit(void * junk) { Reset(); InfoSubstituteControls(NULL, NULL); - MainRedraw(); - MapRedraw(); } @@ -2879,6 +2931,14 @@ static void TrainFunc( break; + case DO_PENCILS_ON: + xx->pencils = TRUE; + break; + + case DO_PENCILS_OFF: + xx->pencils = FALSE; + break; + case DO_FLIPCAR: temp0 = GetTrkEndTrk(trainFuncCar,0); pos0 = GetTrkEndPos(trainFuncCar,0); @@ -3019,16 +3079,15 @@ static void TrainFunc( break; } - MainRedraw(); //Redraw if Train altered - MapRedraw(); + MainRedraw(); //TrainFunc: Redraw if Train altered if (trainsState == TRAINS_PAUSE) { RestartTrains(); } else { - DrawAllCars(); } } +EXPORT wIndex_t trainCmdInx; void InitCmdTrain(wMenu_p menu) { @@ -3036,8 +3095,8 @@ void InitCmdTrain(wMenu_p menu) log_trainPlayback = LogFindIndex("trainPlayback"); trainPLs[I_ZERO].winLabel = (char*)wIconCreatePixMap(zero_xpm); ParamRegister(&trainPG); - AddMenuButton(menu, CmdTrain, "cmdTrain", _("Train"), - wIconCreatePixMap(train_xpm), LEVEL0_50, IC_POPUP2|IC_LCLICK|IC_RCLICK, 0, + trainCmdInx = AddMenuButton(menu, CmdTrain, "cmdTrain", _("Train"), + wIconCreatePixMap(train_xpm), LEVEL0_50, IC_POPUP3|IC_LCLICK|IC_RCLICK, 0, NULL); stopI = wIconCreatePixMap(ballred); goI = wIconCreatePixMap(ballgreen); @@ -3053,6 +3112,10 @@ void InitCmdTrain(wMenu_p menu) TrainFunc, (void*)DO_UNCOUPLE); trainPopupMI[DO_FLIPCAR] = wMenuPushCreate(trainPopupM, "", _("Flip Car"), 0, TrainFunc, (void*)DO_FLIPCAR); + trainPopupMI[DO_PENCILS_ON] = wMenuPushCreate(trainPopupM, "", _("Clearance Lines On"), 0, + TrainFunc, (void*)DO_PENCILS_ON); + trainPopupMI[DO_PENCILS_OFF] = wMenuPushCreate(trainPopupM, "", _("Clearance Lines Off"), 0, + TrainFunc, (void*)DO_PENCILS_OFF); trainPopupMI[DO_FLIPTRAIN] = wMenuPushCreate(trainPopupM, "", _("Flip Train"), 0, TrainFunc, (void*)DO_FLIPTRAIN); trainPopupMI[DO_MUMASTER] = wMenuPushCreate(trainPopupM, "", _("MU Master"), -- cgit v1.2.3