summaryrefslogtreecommitdiffstats
path: root/src/CBot/tests/TestCBot/PerformDlg.cpp
blob: 8abbb4beb2123657bf3e2ec9f62dfeaa7d5a8177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see  http://www.gnu.org/licenses/.

// PerformDlg.cpp : implementation file
//

#include "stdafx.h"
#include "testcbot.h"
#include "PerformDlg.h"

//#include <stdio.h>
#include <sys/timeb.h>
//#include <time.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPerformDlg dialog


CPerformDlg::CPerformDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPerformDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPerformDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CPerformDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPerformDlg)
	DDX_Control(pDX, IDC_EDIT3, m_Edit3);
	DDX_Control(pDX, IDC_EDIT1, m_Edit1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPerformDlg, CDialog)
	//{{AFX_MSG_MAP(CPerformDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPerformDlg message handlers

/* Pauses for a specified number of milliseconds. */

/*void sleep( double waitseconds )
{
   clock_t wait = (clock_t)(waitseconds * CLOCKS_PER_SEC);
   clock_t goal;
   goal = wait + clock();
   while( goal > clock() )
      ;
}*/

void sleep( clock_t wait )
{
   clock_t goal;
   goal = wait + clock();
   while( goal > clock() )
      TRACE("%d \n", clock() );
}

void sleep2( clock_t wait )
{
   struct _timeb timebuffer;
   char *timeline;

   _ftime( &timebuffer );
   timeline = ctime( & ( timebuffer.time ) );
   long x = timebuffer.millitm;
   while( x == timebuffer.millitm ) _ftime( &timebuffer );
}

#define	NBLP	20

UINT ThreadProc2(ThreadInfo2 *info)
{
	int		lp = NBLP;
	int		i;
	clock_t start = clock();

	while ( !info->m_bStop )
	{
		for ( i = 0; i< info->m_nbscripts; i++ )
		{
			info->m_pProg[i]->Run();
		}

#ifdef	_DEBUG
		sleep2( 1 );
#else
		CString s ( "xx" );
		for ( long z = 0x5000; z>0; z-- ) s = s.Left(1);
#endif
		if ( --lp == 0 )
		{
			clock_t finish = clock();
			double n = (double)NBLP / (double)(finish-start) * CLOCKS_PER_SEC;
			char	b[30];
			sprintf( b, "%f", n);
			info->m_pEdit->SetWindowText(b);

			n = n * 1100 / 200;	// performances
			sprintf( b, "%f", n);
			info->m_pEdit3->SetWindowText(b);
			start = finish;
			lp = NBLP;
		}
	}

	return 0 ;
}

BOOL CPerformDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();


	CBotStringArray liste;
	// cr�e les scripts pour les tests
	for ( int i = 0; i < 100; i++ )
	{
		m_pProg[i] = new CBotProgram();
		m_pProg[i]->Compile(m_Script, liste);
		m_pProg[i]->Start(liste[0]);
	}

	// lance un processus paral�le pour l'ex�cution
//	m_threadinfo2.m_pWndMessage = this ;

	m_threadinfo2.m_pEdit  = &m_Edit1;
	m_threadinfo2.m_pEdit3 = &m_Edit3;
	m_threadinfo2.m_pProg  = m_pProg;
	m_threadinfo2.m_bStop  = FALSE;
	m_threadinfo2.m_nbscripts = 30;


	AfxBeginThread((AFX_THREADPROC)ThreadProc2, &m_threadinfo2) ;
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPerformDlg::OnCancel() 
{
	m_threadinfo2.m_bStop  = TRUE;
	sleep ( 2000 );

	CDialog::OnCancel();

	for ( int i = 0; i < 100; i++ )
	{
		delete m_pProg[i];
	}
}