Even if do-while was somehow inferior, it's a very tiny and irrelevant issue compared to all the other things we could say about that code. Ignoring what's already been said, there's still:
- His main loop renders stuff, then handles keyboard input, then actually displays the rendered stuff. This is a strange and confusing order in which to do those operations (and it's probably doing something bad like forcing all input to lag one frame).
- He's using real-time input when he probably wants events. The Escape to close behavior in particular is almost certainly better as an event.
- The "exit" sentinel variable appears to contain no special meaning or information. He could have just as easily used while(true) {} with break;, or the SFML convention while(window.isOpen()) {} with window.close();, depending on whether or not he wants a "quick exit" from the loop. Or the do-while equivalents of those. None of these requires declaring an additional variable at the top of main().
- He's not using any Vector2s or Vector3s in his drawable classes, forcing him to set each x,y,z coordinate individually rather than group them together.
- He's giving his classes Init() methods instead of proper constructors.
- His classes need to be explicitly "enabled" and made "visible". Is there a reason the classes aren't like this by default after construction?
We should be pointing out stuff like this instead of arguing about do-while.
You could, and I'm sure there would be something to learn from it, but it would be misdirected
and way out of proportion, when considering the purpose of the testbech code.
Anyway, I've now gone away from static instantiation of the Anim class to dynamic storing them in a vector.
and then the DrawAbleVector get a reference too that. To get that to work I had to use vector.reserve()
without it after the 2nd. push the vector resized and chanced memory location and the ref was invalid.
So now I have perfect drawing order control from the scene definition file,
and can move the blocks up and down the layer stack without altering any code.
And I've started making overloaded constructors for the basic stuff, and I have removed
a huge amount of boiler plate code - 'I think it's called', as a benefit from the effort of restructuring the code.
Old class Scene{
public:
AnimCLASS Anim_layer1
...
AnimCLASS Anim_layer8
New class Scene{
public:
std::vector<DrawableCLASS*> DrawVec;
std::vector<AnimCLASS> DrawAnimVec;
Scene.Define(int SN) {
if(SN==Scene_Intro) {
uint32_t index=0;
{ // Full screen Background single frame pos 0,0 scale 1,1
AnimCLASS Anim(true,true,"textures/Art01");
DrawAnimVec.push_back(Anim);
DrawVec.push_back(&DrawAnimVec[index]);
index++; }
// Fog -old C function/class on the todo list..
WX.FOG.SetEnable(true);
WX.FOG.SetVisible(true);
WX.FOG.SetBandsColor(205,205,205,30);
WX.FOG.NumOfBands = 50 ;// 50 optimal
WX.FOG.BandYmin = -300;
WX.FOG.BandYmax = 600;
WX.FOG.BandSize = 2;
WX.FOG.BandSpeed = 2;
DrawVec.push_back(&WX.FOG);
{// Actor sidding
AnimCLASS Anim(true,true,"textures/girl4");
Anim.SetPos(808,463);
Anim.SetScale(0.18,0.18);
Anim.SetClickPoint(true, true, "Dynamic", "Aixy", "ACTOR_NO" ,0 , "Cursor_Red", 808,463, 50, 88);
DrawAnimVec.push_back(Anim);
DrawVec.push_back(&DrawAnimVec[index]);
index++; }
{// Fire animation 24 frames
AnimCLASS Anim(true,true,"textures/Particles/Fireplace");
Anim.SetFrameCount(23);
Anim.SetCounterType(UP_Counter);
Anim.SetPos(484,394);
Anim.SetScale(0.26,0.26);
Anim.SetColor(255,255,245,115);
Anim.SetAnimationSpeed(0.6);
Anim.SetLayerName("Fire");
AnimVec.push_back(Anim);
DrawVec.push_back(&DrawAnimVec[index]);
index++; }