Commit 1110ff16 authored by Chen Bill's avatar Chen Bill

use std::vector buffer

parent 0423cf88
......@@ -74,13 +74,14 @@ int ReplayMode::ReplayThread() {
mainGame->dInfo.isFinished = false;
mainGame->dInfo.isReplay = true;
mainGame->dInfo.isReplaySkiping = (skip_turn > 0);
char engineBuffer[0x1000];
std::vector<char> engineBuffer;
engineBuffer.resize(MESSAGE_BUFFER_SIZE);
is_continuing = true;
skip_step = 0;
if(mainGame->dInfo.isSingleMode) {
int len = get_message(pduel, (byte*)engineBuffer);
int len = get_message(pduel, (byte*)engineBuffer.data());
if (len > 0)
is_continuing = ReplayAnalyze(engineBuffer, len);
is_continuing = ReplayAnalyze(engineBuffer.data(), len);
} else {
ReplayRefreshDeck(0);
ReplayRefreshDeck(1);
......@@ -92,12 +93,13 @@ int ReplayMode::ReplayThread() {
if(mainGame->dInfo.isReplaySkiping)
mainGame->gMutex.lock();
while (is_continuing && !exit_pending) {
int result = process(pduel);
int len = result & 0xffff;
/*int flag = result >> 16;*/
unsigned int result = process(pduel);
int len = result & PROCESSOR_BUFFER_LEN;
if (len > 0) {
get_message(pduel, (byte*)engineBuffer);
is_continuing = ReplayAnalyze(engineBuffer, len);
if (len > (int)engineBuffer.size())
engineBuffer.resize(len);
get_message(pduel, (byte*)engineBuffer.data());
is_continuing = ReplayAnalyze(engineBuffer.data(), len);
if(is_restarting) {
mainGame->gMutex.lock();
is_restarting = false;
......@@ -109,9 +111,9 @@ int ReplayMode::ReplayThread() {
if(mainGame->dInfo.isSingleMode) {
is_continuing = true;
skip_step = 0;
int len = get_message(pduel, (byte*)engineBuffer);
int len = get_message(pduel, (byte*)engineBuffer.data());
if (len > 0) {
is_continuing = ReplayAnalyze(engineBuffer, len);
is_continuing = ReplayAnalyze(engineBuffer.data(), len);
}
} else {
ReplayRefreshDeck(0);
......
......@@ -492,18 +492,22 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
Process();
}
void SingleDuel::Process() {
char engineBuffer[0x1000];
unsigned int engFlag = 0, engLen = 0;
std::vector<char> engineBuffer;
engineBuffer.reserve(MESSAGE_BUFFER_SIZE);
unsigned int engFlag = 0;
int engLen = 0;
int stop = 0;
while (!stop) {
if (engFlag == 2)
if (engFlag == PROCESSOR_END)
break;
int result = process(pduel);
engLen = result & 0xffff;
engFlag = result >> 16;
unsigned int result = process(pduel);
engLen = result & PROCESSOR_BUFFER_LEN;
engFlag = result & PROCESSOR_FLAG;
if (engLen > 0) {
get_message(pduel, (byte*)&engineBuffer);
stop = Analyze(engineBuffer, engLen);
if (engLen > (int)engineBuffer.size())
engineBuffer.resize(engLen);
get_message(pduel, (byte*)engineBuffer.data());
stop = Analyze(engineBuffer.data(), engLen);
}
}
if(stop == 2)
......
......@@ -98,12 +98,13 @@ int SingleMode::SinglePlayThread() {
mainGame->dInfo.isSingleMode = true;
mainGame->device->setEventReceiver(&mainGame->dField);
mainGame->gMutex.unlock();
char engineBuffer[0x1000];
std::vector<char> engineBuffer;
engineBuffer.resize(MESSAGE_BUFFER_SIZE);
is_closing = false;
is_continuing = true;
int len = get_message(pduel, (byte*)engineBuffer);
int len = get_message(pduel, (byte*)engineBuffer.data());
if (len > 0)
is_continuing = SinglePlayAnalyze(engineBuffer, len);
is_continuing = SinglePlayAnalyze(engineBuffer.data(), len);
last_replay.BeginRecord();
last_replay.WriteHeader(rh);
unsigned short buffer[20];
......@@ -120,12 +121,13 @@ int SingleMode::SinglePlayThread() {
last_replay.Flush();
start_duel(pduel, opt);
while (is_continuing) {
int result = process(pduel);
len = result & 0xffff;
/* int flag = result >> 16; */
unsigned int result = process(pduel);
len = result & PROCESSOR_BUFFER_LEN;
if (len > 0) {
get_message(pduel, (byte*)engineBuffer);
is_continuing = SinglePlayAnalyze(engineBuffer, len);
if (len > (int)engineBuffer.size())
engineBuffer.resize(len);
get_message(pduel, (byte*)engineBuffer.data());
is_continuing = SinglePlayAnalyze(engineBuffer.data(), len);
}
}
last_replay.EndRecord();
......
......@@ -488,18 +488,22 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
Process();
}
void TagDuel::Process() {
char engineBuffer[0x1000];
unsigned int engFlag = 0, engLen = 0;
std::vector<char> engineBuffer;
engineBuffer.reserve(MESSAGE_BUFFER_SIZE);
unsigned int engFlag = 0;
int engLen = 0;
int stop = 0;
while (!stop) {
if (engFlag == 2)
if (engFlag == PROCESSOR_END)
break;
int result = process(pduel);
engLen = result & 0xffff;
engFlag = result >> 16;
unsigned int result = process(pduel);
engLen = result & PROCESSOR_BUFFER_LEN;
engFlag = result & PROCESSOR_FLAG;
if (engLen > 0) {
get_message(pduel, (byte*)&engineBuffer);
stop = Analyze(engineBuffer, engLen);
if (engLen > (int)engineBuffer.size())
engineBuffer.resize(engLen);
get_message(pduel, (byte*)engineBuffer.data());
stop = Analyze(engineBuffer.data(), engLen);
}
}
if(stop == 2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment