Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kumir2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kumir
kumir2
Commits
3b097906
Commit
3b097906
authored
Dec 11, 2020
by
Alexander A. Maly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added --output option to actor Robot
to dump the resulting field after the program execution.
parent
4402d37c
Pipeline
#2829
passed with stages
in 3 minutes and 49 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
140 additions
and
9 deletions
+140
-9
src/actors/robot/cfield.cpp
src/actors/robot/cfield.cpp
+102
-2
src/actors/robot/cfield.h
src/actors/robot/cfield.h
+5
-0
src/actors/robot/robotmodule.cpp
src/actors/robot/robotmodule.cpp
+25
-3
src/actors/robot/robotmodule.h
src/actors/robot/robotmodule.h
+1
-0
src/app/kumir2-launcher.cpp
src/app/kumir2-launcher.cpp
+1
-0
src/plugins/kumircoderun/runplugin.cpp
src/plugins/kumircoderun/runplugin.cpp
+6
-4
No files found.
src/actors/robot/cfield.cpp
View file @
3b097906
...
...
@@ -22,10 +22,36 @@ CFieldItem::CFieldItem()
void
CFieldItem
::
setWalls
(
int
wallByte
)
{
upWall
=
(
wallByte
&
UP_WALL
)
?
true
:
false
;
downWall
=
(
wallByte
&
DOWN_WALL
)
?
true
:
false
;
leftWall
=
(
wallByte
&
LEFT_WALL
)
?
true
:
false
;
rightWall
=
(
wallByte
&
RIGHT_WALL
)
?
true
:
false
;
downWall
=
(
wallByte
&
DOWN_WALL
)
?
true
:
false
;
upWall
=
(
wallByte
&
UP_WALL
)
?
true
:
false
;
}
int
CFieldItem
::
getWalls
()
const
{
int
res
=
0
;
if
(
leftWall
)
res
|=
LEFT_WALL
;
if
(
rightWall
)
res
|=
RIGHT_WALL
;
if
(
downWall
)
res
|=
DOWN_WALL
;
if
(
upWall
)
res
|=
UP_WALL
;
return
res
;
}
bool
CFieldItem
::
isEmpty
(
int
wMask
)
const
{
return
(
getWalls
()
&
~
wMask
)
==
0
&&
!
isColored
&&
!
mark
&&
upChar
==
' '
&&
downChar
==
' '
&&
radiation
==
0
&&
temperature
==
0
;
}
...
...
@@ -163,6 +189,80 @@ bool ConsoleField::goRight()
return
true
;
}
int
ConsoleField
::
saveToFile
(
const
QString
&
filename
)
const
{
QFile
f
(
filename
);
bool
ok
=
f
.
open
(
QIODevice
::
WriteOnly
);
if
(
!
ok
)
{
qDebug
()
<<
QString
::
fromUtf8
(
"Ошибка сохранения обстановки "
)
<<
filename
;
return
1
;
}
int
res
=
saveToDataStream
(
f
);
f
.
close
();
return
res
;
}
int
ConsoleField
::
createWallMask
(
uint32_t
x
,
uint32_t
y
,
uint32_t
mx
,
uint32_t
my
)
{
int
res
=
0
;
if
(
x
==
0
)
res
|=
LEFT_WALL
;
if
(
y
==
0
)
res
|=
UP_WALL
;
if
(
x
+
1
==
mx
)
res
|=
RIGHT_WALL
;
if
(
y
+
1
==
my
)
res
|=
DOWN_WALL
;
return
res
;
}
int
ConsoleField
::
saveToDataStream
(
QIODevice
&
stream
)
const
{
char
ctmp
[
64
];
uint32_t
mx
=
roboCols
,
my
=
roboRows
;
uint32_t
rx
=
roboCol
,
ry
=
roboRow
;
stream
.
write
(
"; Field Size: x, y
\n
"
);
sprintf
(
ctmp
,
"%u %u
\n
"
,
mx
,
my
);
stream
.
write
(
ctmp
);
stream
.
write
(
"; Robot position: x, y
\n
"
);
sprintf
(
ctmp
,
"%u %u
\n
"
,
rx
,
ry
);
stream
.
write
(
ctmp
);
stream
.
write
(
"; A set of special Fields: x, y, Walls, Color, Radiation, Temperature, USymbol, DSymbol, Point
\n
"
);
for
(
uint32_t
y
=
0
;
y
<
my
;
y
++
)
{
for
(
uint32_t
x
=
0
;
x
<
mx
;
x
++
)
{
int
wMask
=
createWallMask
(
x
,
y
,
mx
,
my
);
CFieldItem
item
=
items
[
y
][
x
];
if
(
item
.
isEmpty
(
wMask
))
{
continue
;
}
char
uChar
=
item
.
upChar
.
cell
();
if
(
uChar
==
' '
)
uChar
=
'$'
;
char
dChar
=
item
.
downChar
.
cell
();
if
(
dChar
==
' '
)
dChar
=
'$'
;
char
mark
=
item
.
mark
?
'1'
:
'0'
;
char
color
=
item
.
isColored
?
'1'
:
'0'
;
sprintf
(
ctmp
,
"%d %d %d %c %f %f %c %c %c
\n
"
,
x
,
y
,
item
.
getWalls
()
&
~
wMask
,
color
,
item
.
radiation
,
item
.
temperature
,
uChar
,
dChar
,
mark
);
stream
.
write
(
ctmp
);
}
}
stream
.
write
(
"; End Of File
\n
"
);
return
0
;
}
int
ConsoleField
::
loadFromFile
(
const
QString
&
filename
)
{
QFile
f
(
filename
);
...
...
src/actors/robot/cfield.h
View file @
3b097906
...
...
@@ -21,6 +21,8 @@ struct CFieldItem
{
CFieldItem
();
void
setWalls
(
int
wallByte
);
int
getWalls
()
const
;
bool
isEmpty
(
int
wMask
=
0
)
const
;
bool
isColored
;
bool
mark
;
...
...
@@ -43,6 +45,7 @@ public:
const
CFieldItem
*
getItem
(
uint32_t
row
,
uint32_t
col
)
const
;
CFieldItem
*
getItem
(
uint32_t
row
,
uint32_t
col
);
CFieldItem
*
getCurItem
();
static
int
createWallMask
(
uint32_t
x
,
uint32_t
y
,
uint32_t
mx
,
uint32_t
my
);
bool
goLeft
();
bool
goRight
();
...
...
@@ -59,6 +62,8 @@ public:
uint32_t
Cols
()
const
{
return
roboCols
;
}
uint32_t
Rows
()
const
{
return
roboRows
;
}
int
saveToFile
(
const
QString
&
filename
)
const
;
int
saveToDataStream
(
QIODevice
&
stream
)
const
;
int
loadFromFile
(
const
QString
&
filename
);
int
loadFromDataStream
(
QIODevice
*
stream
);
...
...
src/actors/robot/robotmodule.cpp
View file @
3b097906
...
...
@@ -138,10 +138,11 @@ void RobotModule::reset()
This method is called when actor resets its state before program starts.
*/
//delete field;
qDebug
()
<<
"Reset!!"
;
if
(
!
DISPLAY
)
{
//console mode
qDebug
()
<<
"Reset::console mode"
;
qDebug
()
<<
"R
obot::R
eset::console mode"
;
return
;
}
else
{
qDebug
()
<<
"Robot::Reset::gui mode"
;
}
field
->
destroyRobot
();
...
...
@@ -168,7 +169,17 @@ void RobotModule::changeGlobalState(
)
{
Q_UNUSED
(
old
);
using
namespace
Shared
;
qDebug
()
<<
"RobotModuleBase::changeGlobalState"
;
qDebug
()
<<
"RobotModuleBase::changeGlobalState from "
<<
(
int
)
old
<<
" to "
<<
(
int
)
current
;
if
(
!
DISPLAY
)
{
if
(
current
==
PluginInterface
::
GS_Observe
&&
!
oName
.
isEmpty
())
{
int
res
=
curConsoleField
->
saveToFile
(
oName
);
qDebug
()
<<
"Dumped state to"
<<
oName
<<
", res = "
<<
res
;
}
return
;
}
view
->
setViewportUpdateMode
(
QGraphicsView
::
SmartViewportUpdate
);
if
(
current
==
PluginInterface
::
GS_Running
)
{
view
->
setViewportUpdateMode
(
QGraphicsView
::
NoViewportUpdate
);
...
...
@@ -266,6 +277,12 @@ RobotModule::acceptableCommandLineParameters()
QVariant
::
String
,
false
)
);
params
.
append
(
ExtensionSystem
::
CommandLineParameter
(
true
,
'o'
,
"output"
,
tr
(
"Robot field output file name"
),
QVariant
::
String
,
false
)
);
return
params
;
}
...
...
@@ -279,6 +296,11 @@ QString RobotModule::initialize(
qDebug
()
<<
"FIELD: |"
<<
fName
<<
"| "
;
}
if
(
runtimeParameters
.
value
(
'o'
).
isValid
())
{
oName
=
runtimeParameters
.
value
(
'o'
).
toString
();
qDebug
()
<<
"OUTPUT: |"
<<
oName
<<
"| "
;
}
DISPLAY
=
(
qobject_cast
<
QApplication
*>
(
qApp
)
!=
0
);
#ifdef Q_OS_LINUX
...
...
src/actors/robot/robotmodule.h
View file @
3b097906
...
...
@@ -121,6 +121,7 @@ private:
void
prepareNewWindow
();
int
CurCellSize
;
bool
DISPLAY
;
QString
oName
;
ExtensionSystem
::
SettingsPtr
curSettings
;
ConsoleField
*
curConsoleField
;
QMutex
mutex
;
...
...
src/app/kumir2-launcher.cpp
View file @
3b097906
...
...
@@ -283,6 +283,7 @@ public:
_qApp
->
exit
(
_qApp
->
property
(
"returnCode"
).
isValid
()
?
_qApp
->
property
(
"returnCode"
).
toInt
()
:
1
);
}
if
(
!
manager
->
isGuiRequired
())
{
_qApp
->
quit
();
}
...
...
src/plugins/kumircoderun/runplugin.cpp
View file @
3b097906
...
...
@@ -712,11 +712,12 @@ KumirRunPlugin::acceptableCommandLineParameters() const
return
result
;
}
QString
KumirRunPlugin
::
initialize
(
const
QStringList
&
configurationArguments
,
const
ExtensionSystem
::
CommandLine
&
runtimeArguments
)
{
QString
KumirRunPlugin
::
initialize
(
const
QStringList
&
configurationArguments
,
const
ExtensionSystem
::
CommandLine
&
runtimeArguments
)
{
pRun_
->
programLoaded
=
false
;
const
bool
noBreakpoints
=
configurationArguments
.
contains
(
"nobreakpoints"
);
bool
noBreakpoints
=
configurationArguments
.
contains
(
"nobreakpoints"
);
pRun_
->
setSupportBreakpoints
(
!
noBreakpoints
);
qRegisterMetaType
<
QVariant
::
Type
>
(
"QVariant::Type"
);
qRegisterMetaType
<
QList
<
QVariant
::
Type
>
>
(
"QList<QVariant::Type>"
);
...
...
@@ -833,6 +834,7 @@ void KumirRunPlugin::start()
pRun_
->
wait
();
checkForErrorInConsole
();
stop
();
ExtensionSystem
::
PluginManager
::
instance
()
->
switchGlobalState
(
Shared
::
PluginInterface
::
GS_Observe
);
}
else
{
startTimer
(
0
);
// start thread after event loop started
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment