@vinterberg this is messageloop. tmr.tickprecise(4)will return true every 250ms(I've tested it in a separate project). but I only got 120fps.
while (message.message != WM_QUIT)
{
if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
if (tmr.timeprecise(4))
{
UpdateDXGame();
}
}
and this is the entity class
class entity
{
public:
entity();
~entity();
void make_transform(lpvector2 origin, float rotation);
void make_movement(lpvector2 velocity, float angularvelocity);
void make_graphics(lpvector2 topleft, RECT* SourceRect);
void make_input(int iflag);
void make_collision(vector2* vertice, int vercount);
void make_fire();
void messagepump(lptexture texture, entity** miss, int* iterator);
transform* _transform;
movement* _movement;
graphics* _graphics;
input* _input;
collision* _collision;
fire* _fire;
};
this is the funciton to be called every frame. implecolli calculate collisions and it works quite good.
void scene::update()
{
for (int i = 0; i < _iterator; i++)
{
_entities[i]->messagepump(texture, &_missilemanage[_iteratormiss], &_iteratormiss);
if (_entities[i]->_collision->detector == true)
{
for (int j = 0; j < _iterator; j++)
{
if (j == i)
continue;
vector2 mtd;
if (impleColli(_entities[i]->_collision->_vertrans, _entities[i]->_collision->_iterator,
&_entities[i]->_movement->_velc, &_entities[i]->_transform->_ori,
_entities[j]->_collision->_vertrans, _entities[j]->_collision->_iterator,
&_entities[j]->_movement->_velc, &_entities[j]->_transform->_ori,
&mtd))
{
if(mtd != NULL)
_entities[i]->_transform->_ori += mtd;
}
}
}
}
ostringstream os; string s;
os << _iteratormiss; s = os.str();
SetWindowText(GetActiveWindow(), s.c_str());
for (int i = 0; i < _iteratormiss; i++)
{
_missilemanage[i]->messagepump(texture, &_missilemanage[_iteratormiss], &_iteratormiss);
}
}
here is messagepump. it handles the communication between components
void entity::messagepump(lptexture texture, entity** miss, int* iterator)
{
//movement
if (_transform != NULL && _movement != NULL)
{
_transform->_ori += _movement->_velc;
_transform->_rot += _movement->_angvelc;
}
//input
if (_input != NULL && _movement != NULL && _transform != NULL)
{
int imove, irotate, addi;
_input->update(&imove, &irotate, &addi);
float tx = 0;
float ty = 0;
float rotR = 0;
vector2 Vtrans = D3DXVECTOR2(0, 0);
rotR = 3.14159265 * 2 * _transform->_rot / 360;
tx = _movement->max_vel * sin(rotR);
ty = -_movement->max_vel * cos(rotR);
Vtrans = vector2(tx, ty);
switch (imove)
{
case 1:
_movement->_velc = Vtrans;
break;
case 2:
_movement->_velc = -Vtrans;
break;
case 3:
_movement->_velc = vector2(0, 0);
break;
}
switch(irotate)
{
case 2:
_movement->_angvelc = _movement->max_angv;
break;
case 1:
_movement->_angvelc = -_movement->max_angv;
break;
case 3:
_movement->_angvelc = 0;
break;
}
if (addi == 1)
{
_fire->makefire(miss, &_collision->springarm, _transform->_rot);
*iterator += 1;
}
}
//graphics
if (_graphics != NULL)
{
float rotR = 3.14159265f * 2.f / 360.f * _transform->_rot;
D3DXMATRIX mat;
D3DXMatrixTransformation2D(&mat, NULL, 0, NULL, &(_graphics->_topleft*-1), rotR, &_transform->_ori);
spriteobj1->SetTransform(&mat);
spriteobj1->Draw(texture, &_graphics->_srcrect, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255));
}
//collision
if (_collision != NULL)
{
_collision->update(&_transform->_rot, &_transform->_ori);
}
}