📄 main.cpp
字号:
mouse = Vector(X,Y);
MyPaint();
}
*/
mouse = Vector(X, Y);
if (mouse_left_down) {
hMonitor.MouseMotion(X, Y);
MyPaint();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if (Button == mbLeft) {
mouse_left_down = false;
} else if (Button == mbRight) {
if (mouse_right_down) {
//if (mouse_right_down && mLiveMonitor) {
mouse.x = min(mouse.x,
Memo1->Left - MonitorCommandPanel->Width - 40);
mouse.y = min(mouse.y,
Form1->Height - MonitorCommandPanel->Height - 40);
MonitorCommandPanel->Left = mouse.x;
MonitorCommandPanel->Top = mouse.y;
MonitorCommandPanel->Visible = true;
MonitorCommandPanel->Enabled = true;
MonitorCommandEdit->Visible = true;
MonitorCommandEdit->Enabled = true;
MonitorCommandButton->Visible = true;
MonitorCommandButton->Enabled = true;
MonitorCommandCloseButton->Visible = true;
MonitorCommandCloseButton->Enabled = true;
}
mouse_right_down = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift,
int WheelDelta, TPoint &MousePos, bool &Handled)
{
Vector delta = center-Vector(Width/2,Height/2);
delta /= scale;
if(Shift.Contains(ssCtrl)){
scale += WheelDelta/100;
if(scale<5)
scale = 5;
center = Vector(Width/2,Height/2) + delta * scale;
MyPaint();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
mLiveMonitor = !mLiveMonitor;
if (!mMonitorOnly) {
for (int i = 0; i < 4; ++ i) {
swap(Monitor::sTeamColorLeft[i], Monitor::sTeamColorRight[i]);
}
}
static bool flag = false;
if (mLiveMonitor) {
ClientSocket1->Host = ServerIPEdit->Text;
ClientSocket1->Open();
mShowReal = false;
Button3->Caption = "Disconn";
Button1->Enabled = false;
Button2->Enabled = false;
Button4->Enabled = false;
flag = TrackBar1->Enabled;
TrackBar1->Enabled = false;
for (int i = 0; i < 11; ++ i) {
rbs[i]->Enabled = false;
}
} else {
SendMessage(string("D"));
ClientSocket1->Close();
Button3->Caption = "Connect";
Button1->Enabled = true;
Button2->Enabled = true;
Button4->Enabled = true;
if (flag) {
TrackBar1->Enabled = true;
for (int i = 0; i < 11; ++ i) {
rbs[i]->Enabled = true;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// create opengl view
PIXELFORMATDESCRIPTOR pfd= {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
32,
0, 0,
PFD_MAIN_PLANE,
0,
0, 0, 0,
};
hdc = GetDC(Handle);
int pixelFormat=ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, pixelFormat, &pfd);
if ((hrc=wglCreateContext(hdc)) == NULL) {
ShowMessage("Error! hrc == NULL");
}
glClearColor(192./256, 192./256, 192./256, 1);
// initilization for monitor
// initilization for monitor
string word = "--logfile monitor.log";
istringstream is(word);
vector <string> cmdPara;
while (is >> word) {
cmdPara.push_back(word);
}
int argc = cmdPara.size() + 1;
char **argv = new char*[argc];
argv[0] = "3DMonitor";
for (int i = 0; i < cmdPara.size(); ++ i) {
argv[i + 1] = (char*)cmdPara[i].c_str();
}
if (hMonitor.Init(argc, argv) == true) {
hMonitor.Run();
} else {
hMonitor.Usage(argc, argv);
}
hMonitor.mGLServer.Reshape(Splitter1->Left - 5, this->Height - TrackBar1->Top - TrackBar1->Height - 35);
// initilization for monitor
// initilization for monitor
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
SendMessage(string("D"));
// destroy opengl view
wglDeleteContext(hrc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
Vector3 pos;
switch (Key) {
case 'W':
case 'S':
case 'A':
case 'D':
case 'C':
case VK_ADD:
case VK_SUBTRACT:
case 'N':
case '2':
hMonitor.Keyboard(Key, 0, 0);
break;
/* case 'Q':
case VK_ESCAPE:
// quit
// mCommServer->SendDisconnectCmd();
SendMessage(string("D"));
exit(0);*/
case 'K' :
// kick off
SendWorldModel(string("(kickOff None)"));
// SendToWorldModel("(playMode KickOff_Left)");
// SendToWorldModel("(playMode KickOff_Right)");
// SendWorldModel(string("(playMode KickOff_Right)"));
// mCommServer->SendKickOffCmd(mKickOff);
break;
case 'B':
// drop ball
SendWorldModel(string("(dropBall)"));
// mCommServer->SendDropBallCmd();
break;
case 'P' :
// pause simulation
SendMessage(string("P"));
// cout <<"--- Pausing Simulation" << endl;
// mCommServer->SendPauseCmd();
break;
// case ' ':
// mKickOff = NextKickOffMode(mKickOff);
// break;
case 'R' :
// run simulation (after pause command)
SendMessage(string("R"));
// cout <<"--- Running Simulation" << endl;
// mCommServer->SendRunCmd();
break;
#if 0
case 'V':
case 'v':
SendWorldModel(string("(ball (pos 0 0 10) (vel 6.0 0.0 0.1))"));
break;
#endif
default:
return;
}
MyPaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButton1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
FormKeyDown(Sender, Key, Shift);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TrackBar1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
FormKeyDown(Sender, Key, Shift);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
FormKeyDown(Sender, Key, Shift);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
FormKeyDown(Sender, Key, Shift);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
FormKeyDown(Sender, Key, Shift);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Memo1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
FormKeyDown(Sender, Key, Shift);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
hMonitor.mGLServer.Reshape(Splitter1->Left - 5, this->Height - TrackBar1->Top - TrackBar1->Height - 35);
MyPaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Splitter1CanResize(TObject *Sender, int &NewSize,
bool &Accept)
{
FormResize(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
AnsiString s = Socket->ReceiveText();
Predicate predicate;
Parser::Parse(s.c_str(), predicate);
monitor.push_back(s.c_str());
hMonitor.mGameState.ProcessInput(predicate);
mFieldReverse = false;
if (predicate.name == "Info") {
MyPaint();
if (hMonitor.mGameState.GetTime() > 600. - 1e-7) {
Button3Click(Sender);
}
} else if (predicate.name == "Die") {
Button3Click(Sender);
}
}
//---------------------------------------------------------------------------
TForm1::SendMessage(const string& msg)
{
//TODO: Add your source code here
unsigned long len = htonl(msg.size());
string s((const char*)&len,sizeof(len));
s += msg;
ClientSocket1->Socket->SendBuf((void*)s.c_str(),s.size());
}
void TForm1::SendWorldModel(const string& ss)
{
string cmd;
cmd = "W";
cmd += ss;
string message = cmd;
unsigned long len = htonl(message.size());
string s((const char*)&len,sizeof(len));
s += message;
ClientSocket1->Socket->SendBuf((void*)s.c_str(),s.size());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
mShowReal = !mShowReal;
MyPaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
FormKeyDown(Sender, Key, Shift);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MonitorCommandButtonClick(TObject *Sender)
{
string command = MonitorCommandEdit->Text.c_str();
command = string("(playMode PlayOn)") + command;
SendWorldModel(command);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MonitorCommandCloseButtonClick(TObject *Sender)
{
MonitorCommandPanel->Visible = false;
MonitorCommandPanel->Enabled = false;
MonitorCommandEdit->Visible = false;
MonitorCommandEdit->Enabled = false;
MonitorCommandButton->Visible = false;
MonitorCommandButton->Enabled = false;
MonitorCommandCloseButton->Visible = false;
MonitorCommandCloseButton->Enabled = false;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -