Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
YGOPRO-520DIY
ygopro
Commits
80187919
Commit
80187919
authored
Dec 15, 2024
by
Chen Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replay: add read/write template
parent
56247c6d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
21 deletions
+20
-21
gframe/replay.cpp
gframe/replay.cpp
+8
-17
gframe/replay.h
gframe/replay.h
+12
-4
No files found.
gframe/replay.cpp
View file @
80187919
...
...
@@ -44,10 +44,10 @@ void Replay::WriteHeader(ReplayHeader& header) {
fflush
(
fp
);
#endif
}
void
Replay
::
WriteData
(
const
void
*
data
,
in
t
length
,
bool
flush
)
{
void
Replay
::
WriteData
(
const
void
*
data
,
size_
t
length
,
bool
flush
)
{
if
(
!
is_recording
)
return
;
if
(
length
<
0
||
(
int
)
(
pwrite
-
replay_data
)
+
length
>
MAX_REPLAY_SIZE
)
if
((
pwrite
-
replay_data
)
+
length
>
MAX_REPLAY_SIZE
)
return
;
std
::
memcpy
(
pwrite
,
data
,
length
);
pwrite
+=
length
;
...
...
@@ -119,7 +119,7 @@ bool Replay::OpenReplay(const wchar_t* name) {
if
(
!
rfp
)
return
false
;
pdata
=
replay_data
;
data_position
=
0
;
is_recording
=
false
;
is_replaying
=
false
;
replay_size
=
0
;
...
...
@@ -209,26 +209,17 @@ bool Replay::ReadName(wchar_t* data) {
BufferIO
::
CopyWStr
(
buffer
,
data
,
20
);
return
true
;
}
bool
Replay
::
ReadData
(
void
*
data
,
in
t
length
)
{
bool
Replay
::
ReadData
(
void
*
data
,
size_
t
length
)
{
if
(
!
is_replaying
)
return
false
;
if
(
length
<
0
)
return
false
;
if
((
int
)(
pdata
-
replay_data
)
+
length
>
(
int
)
replay_size
)
{
if
(
data_position
+
length
>
replay_size
)
{
is_replaying
=
false
;
return
false
;
}
std
::
memcpy
(
data
,
pdata
,
length
);
pdata
+=
length
;
std
::
memcpy
(
data
,
&
replay_data
[
data_position
]
,
length
);
data_position
+=
length
;
return
true
;
}
template
<
typename
T
>
T
Replay
::
ReadValue
()
{
T
ret
{};
if
(
!
ReadData
(
&
ret
,
sizeof
ret
))
return
-
1
;
return
ret
;
}
int
Replay
::
ReadInt32
()
{
return
ReadValue
<
int32_t
>
();
}
...
...
@@ -239,7 +230,7 @@ char Replay::ReadInt8() {
return
ReadValue
<
char
>
();
}
void
Replay
::
Rewind
()
{
pdata
=
replay_data
;
data_position
=
0
;
}
}
gframe/replay.h
View file @
80187919
...
...
@@ -34,7 +34,11 @@ public:
// record
void
BeginRecord
();
void
WriteHeader
(
ReplayHeader
&
header
);
void
WriteData
(
const
void
*
data
,
int
length
,
bool
flush
=
true
);
void
WriteData
(
const
void
*
data
,
size_t
length
,
bool
flush
=
true
);
template
<
typename
T
>
void
Write
(
T
data
,
bool
flush
=
true
)
{
WriteData
(
&
data
,
sizeof
(
T
),
flush
);
}
void
WriteInt32
(
int
data
,
bool
flush
=
true
);
void
WriteInt16
(
short
data
,
bool
flush
=
true
);
void
WriteInt8
(
char
data
,
bool
flush
=
true
);
...
...
@@ -50,9 +54,13 @@ public:
bool
ReadNextResponse
(
unsigned
char
resp
[]);
bool
ReadName
(
wchar_t
*
data
);
//void ReadHeader(ReplayHeader& header);
bool
ReadData
(
void
*
data
,
in
t
length
);
bool
ReadData
(
void
*
data
,
size_
t
length
);
template
<
typename
T
>
T
ReadValue
();
T
Read
()
{
T
ret
{};
ReadData
(
&
ret
,
sizeof
(
T
));
return
ret
;
}
int
ReadInt32
();
short
ReadInt16
();
char
ReadInt8
();
...
...
@@ -71,7 +79,7 @@ private:
unsigned
char
*
replay_data
;
size_t
replay_size
{};
unsigned
char
*
pwrite
{};
unsigned
char
*
pdata
{};
size_t
data_position
{};
bool
is_recording
{};
bool
is_replaying
{};
};
...
...
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