Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vanilla Éclair (working title)
#68
Important notice: carnat = tech stuff.

Din cauza bug-ului cu enum-ul si din cauza ca a aparut nevoia unor comportamente custom ale item-urilor, aveam nevoie de o solutie mai buna decat cea de dinainte.
Two hours and a beer later, gasit-am si solutie Smile Am postat aici multi carnati (mai interesanti sau mai putin interesanti), iar dupa mine asta e cel mai interesant de pana acum.

Prima data aveam in plan mosteniri, si cate o clasa per item, avand in vedere ca ar fi fain un comportament flexibil si complet custom, pentru item-uri.
But then... daca ar fi fost 900 de items, am fi avut 900 de clase? That sucks. Prea stangaci si !elegant. Am ajuns la, dupa parerea mea, cea mai buna solutie avand in vedere structura existenta. Si de ce nu, o solutie excelenta din mai toate punctele de vedere. Solutia se bazeaza pe delegates (think pointeri catre functii (C++)).

Puncte forte:
- Structura solutiei este curata, si permite dezvoltarea cu usurinta a comportamentelor custom.
- Nu a fost nevoie sa modific decat o linie de cod din ce aveam deja; solutia s-a "instalat" ca un addon, iar la final am scos ce nu mai trebuia din lucrurile vechi.
- Cand vrem comportament custom, codul nou se rezuma doar la o functie extra implementata.
- Avem libertatea dorita cand vine vorba de comportament custom.
- Aceeasi solutie poate fi folosita la ORICE alt element din joc care utilizeaza comportamente custom. Spre exemplu, putem folosi acelasi sistem pentru a defini: rutine custom pentru fiecare personaj in parte, reactii custom a obiectelor interactive si-asa mai departe. Totul cu 1 singura clasa de baza + 1 metoda.
- Volumul de cod este suficient de scazut, DAR...
- poate fi scazut si mai mult folosind metode comune pentru obiectele deloc diferite. Spre exemplu, 5 mancaruri banale care influenteaza atribute si nimic mai mult, ar putea sa aibe ca si comportament o functie comuna DEFAULT_CONSUME.

Screeny details:
Delegate & base item class:
Se pot adauga usor alte functii delegate, pentru un alt tip de comportament. De exemplu, pentru un eveniment cu totul nou: ridicarea unui obiect.
Vrem sa avem un inel blestemat in ceva cripta uitata, iar in momentul in care jucatorul il ridica de jos, sa primeasca un curse de toata frumusetea care sa-l faca sa uite toate magiile? Ba chiar mai mult, sa inceapa imediat un summon undeads, ca sa se invete minte (jucatorul, nu inelul)? Nimic mai simplu; un delegate special pentru noul eveniment, de exemplu PickUpEvent, si un camp nou in BaseItem, precum OnPickUp.
Mai ramane doar sa implementam functia custom, dupa structura delegate-ului, si sa o atribuim item-ului.
[Image: 2yphnqx.png]

Sample events (consume):
Functiile custom; in imagine doar consume-uri.
[Image: 2ljs3o8.png]

Items:
Se observa usurinta cu care se atribuie o functie custom unui item. E basically doar un assign.
[Image: 350w42f.png]
replyReply


Messages In This Thread
Vanilla Éclair (working title) - by Patrunjelu' - 09-17-2012, 01:21 AM
RE: Vanilla Éclair (working title) - by Hegan - 09-24-2012, 02:05 PM
RE: Vanilla Éclair (working title) - by Szekemri - 09-24-2012, 08:10 PM
RE: Vanilla Éclair (working title) - by Bogdan - 09-24-2012, 08:35 PM
RE: Vanilla Éclair (working title) - by Szekemri - 09-28-2012, 04:57 PM
RE: Vanilla Éclair (working title) - by Szekemri - 09-29-2012, 10:31 AM
RE: Vanilla Éclair (working title) - by Warhell - 09-30-2012, 09:14 AM
RE: Vanilla Éclair (working title) - by BeoWulf - 09-30-2012, 11:25 AM
RE: Vanilla Éclair (working title) - by Szekemri - 09-30-2012, 03:41 PM
RE: Vanilla Éclair (working title) - by Hegan - 09-30-2012, 07:59 PM
RE: Vanilla Éclair (working title) - by Carnage - 10-04-2012, 09:47 PM
RE: Vanilla Éclair (working title) - by Warhell - 10-19-2012, 03:08 PM
RE: Vanilla Éclair (working title) - by cedry2k - 10-20-2012, 12:42 PM
RE: Vanilla Éclair (working title) - by Carnage - 10-20-2012, 01:45 PM
RE: Vanilla Éclair (working title) - by Carnage - 10-24-2012, 05:51 PM
RE: Vanilla Éclair (working title) - by Szekemri - 10-21-2012, 06:06 PM
RE: Vanilla Éclair (working title) - by Hegan - 10-27-2012, 11:39 AM
RE: Vanilla Éclair (working title) - by Carnage - 10-29-2012, 03:48 PM
RE: Vanilla Éclair (working title) - by Robi - 11-01-2012, 12:23 AM
RE: Vanilla Éclair (working title) - by Robi - 11-01-2012, 12:40 AM
RE: Vanilla Éclair (working title) - by BeoWulf - 11-01-2012, 09:32 PM
RE: Vanilla Éclair (working title) - by BeoWulf - 11-01-2012, 09:38 PM
RE: Vanilla Éclair (working title) - by old nick - 11-08-2012, 05:53 PM
RE: Vanilla Éclair (working title) - by old nick - 11-08-2012, 08:21 PM
RE: Vanilla Éclair (working title) - by old nick - 11-08-2012, 08:35 PM
RE: Vanilla Éclair (working title) - by Szekemri - 11-08-2012, 10:14 PM
RE: Vanilla Éclair (working title) - by Cristian - 11-08-2012, 10:18 PM
RE: Vanilla Éclair (working title) - by Szekemri - 11-08-2012, 10:23 PM
RE: Vanilla Éclair (working title) - by old nick - 11-08-2012, 10:32 PM
RE: Vanilla Éclair (working title) - by Patrunjelu' - 11-12-2012, 03:37 PM
RE: Vanilla Éclair (working title) - by Carnage - 11-13-2012, 09:24 PM
RE: Vanilla Éclair (working title) - by Carnage - 11-23-2012, 11:25 PM
RE: Vanilla Éclair (working title) - by Cristian - 12-02-2012, 09:01 PM
RE: Vanilla Éclair (working title) - by old nick - 12-02-2012, 09:30 PM
RE: Vanilla Éclair (working title) - by meph144 - 12-10-2012, 11:52 PM
RE: Vanilla Éclair (working title) - by meph144 - 12-14-2012, 08:24 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)