360 likes | 472 Views
#1 Refactoring. Methods of Development. Wat is refactoring?. Refactoring. Refactoring. Refactoren : waarom ?. Xtreme Programming. Wensen van designers veranderen vaak. Wensen van designers veranderen vaak. Wensen van designers veranderen vaak.
E N D
#1 Refactoring Methods of Development
X • Schone code vs later refactoren
Minder code is betere code • Vermijdtdubbele code Welke code lijktveel op elkaar?
D3DXHANDLE refractionTechnique, skyTechnique, glowTechnique; • g_refractionEffect->FindNextValidTechnique(0, &refractionTechnique); • g_refractionEffect->SetTechnique(refractionTechnique); • g_skyEffect->FindNextValidTechnique(0, &skyTechnique); • g_skyEffect->SetTechnique(skyTechnique); • g_glowEffect->FindNextValidTechnique(0, &glowTechnique); • g_glowEffect->SetTechnique(glowTechnique);
D3DXHANDLE refractionTechnique, skyTechnique, glowTechnique; • g_refractionEffect->FindNextValidTechnique(0, &refractionTechnique); • g_refractionEffect->SetTechnique(refractionTechnique); • g_skyEffect->FindNextValidTechnique(0, &skyTechnique); • g_skyEffect->SetTechnique(skyTechnique); • g_glowEffect->FindNextValidTechnique(0, &glowTechnique); • g_glowEffect->SetTechnique(glowTechnique); void InitalizeEffect(D3DXEFFECT *effect, D3DXHANDLE &technique) { effect->FindNextValidTechnique(0, &technique); effect->SetTechnique(technique); }
Code emigreren • Nieuwefunctie / member maken • Verhuizennaar (super)object • Verhuizennaar ‘free function’
Nieuwefunctie/ member • voidUpdateKaleidoscope(int kaleidoSides, float time) • { • … • tc[0] = center + zoom * D3DXVECTOR2(cosf(angle - 2.0f * 3.141592654f / 3.0f), sinf(angle - 2.0f * 3.141592654f / 3.0f)); • tc[1] = center + zoom * D3DXVECTOR2(cosf(angle), sin(angle)); • tc[2] = center + zoom * D3DXVECTOR2(cosf(angle + 2.0f * 3.141592654f / 3.0f), sinf(angle + 2.0f * 3.141592654f / 3.0f)); • … • floattriangleVertices[] = • { • p0.x, p0.y, 0.0f, tc[0].x, tc[0].y, • p1.x, p1.y, 0.0f, tx1.x, tx1.y, • p2.x, p2.y, 0.0f, tx2.x, tx2.y • }; • g_d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, triangleVertices, 5 * sizeof(float)); • } • }
Nieuwefunctie/ member • voidUpdateKaleidoscope(int kaleidoSides, float time) • { • tc[0] = center + zoom * D3DXVECTOR2(cosf(angle - 2.0f * 3.141592654f / 3.0f), sinf(angle - 2.0f * 3.141592654f / 3.0f)); • tc[1] = center + zoom * D3DXVECTOR2(cosf(angle), sin(angle)); • tc[2] = center + zoom * D3DXVECTOR2(cosf(angle + 2.0f * 3.141592654f / 3.0f), sinf(angle + 2.0f * 3.141592654f / 3.0f)); • } • void RenderKaleidoscope() • { • floattriangleVertices[] = • { • p0.x, p0.y, 0.0f, tc[0].x, tc[0].y, • p1.x, p1.y, 0.0f, tx1.x, tx1.y, • p2.x, p2.y, 0.0f, tx2.x, tx2.y • }; • g_d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, triangleVertices, 5 * sizeof(float)); • }
Verhuizennaar (super)object OBJECTKaleidoscope METHODS Update Render ATTRIBUTES vector0, vector1, vector2 center zoom
Verhuizennaar (super)object OBJECT Effect METHODSUpdate Render OBJECTKaleidoscope EXTENDS Effect ATTRIBUTES vector0, vector1, vector2 center zoom OBJECT Bloom EXTENDS Effect ATTRIBUTES …
Verhuizennaar ‘free function’ • stringToLower(string s) • { • transform(s.begin(), s.end(), s.begin(), ::tolower); • return s; • }
Maak code leesbaar • Repeat • Input->update(); • Physics()->update(); • World->Update(); • World->Render(); • Until…
Eindopdracht • Inleveren in week 12