| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194 |
- #include "FactoryClient.h"
- #include <Bild.h>
- #include <Datei.h>
- #include <DateiSystem.h>
- #include <M3Datei.h>
- #include <Textur.h>
- #include "Globals.h"
- #include "Load.h"
- using namespace Network;
- using namespace Framework;
- void createDefaultCube(Bildschirm* zScreen)
- {
- Model3DData* data = zScreen->zGraphicsApi()->createModel("cube");
- data->setAmbientFactor(0.f);
- data->setDiffusFactor(1.f);
- data->setSpecularFactor(0.f);
- float size = 1;
- float left, right, top, bottom;
- // Calculate the screen coordinates of the left side of the bitmap.
- right = (float)((-size / 2.0));
- // Calculate the screen coordinates of the right side of the bitmap.
- left = right + (float)size;
- // Calculate the screen coordinates of the top of the bitmap.
- top = (float)(size / 2.0);
- // Calculate the screen coordinates of the bottom of the bitmap.
- bottom = top - (float)size;
- float front = -size / 2;
- float back = front + size;
- Vertex3D* vertecies = new Vertex3D[24];
- for (int i = 0; i < 24; i++)
- vertecies[i].knochenId = 0;
- // front side
- vertecies[0].pos = Vec3<float>(left, front, top);
- vertecies[0].tPos = Vec2<float>(0.f, 0.f);
- vertecies[1].pos = Vec3<float>(right, front, top);
- vertecies[1].tPos = Vec2<float>(1.f, 0.f);
- vertecies[2].pos = Vec3<float>(left, front, bottom);
- vertecies[2].tPos = Vec2<float>(0.f, 1.f);
- vertecies[3].pos = Vec3<float>(right, front, bottom);
- vertecies[3].tPos = Vec2<float>(1.f, 1.f);
- // back side
- vertecies[4].pos = Vec3<float>(right, back, top);
- vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
- vertecies[5].pos = Vec3<float>(left, back, top);
- vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
- vertecies[6].pos = Vec3<float>(right, back, bottom);
- vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
- vertecies[7].pos = Vec3<float>(left, back, bottom);
- vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
- // left side
- vertecies[8].pos = Vec3<float>(left, back, top);
- vertecies[8].tPos = Vec2<float>(0.f, 0.f);
- vertecies[9].pos = Vec3<float>(left, front, top);
- vertecies[9].tPos = Vec2<float>(1.f, 0.f);
- vertecies[10].pos = Vec3<float>(left, back, bottom);
- vertecies[10].tPos = Vec2<float>(0.f, 1.f);
- vertecies[11].pos = Vec3<float>(left, front, bottom);
- vertecies[11].tPos = Vec2<float>(1.f, 1.f);
- // right side
- vertecies[12].pos = Vec3<float>(right, front, top);
- vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
- vertecies[13].pos = Vec3<float>(right, back, top);
- vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
- vertecies[14].pos = Vec3<float>(right, front, bottom);
- vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
- vertecies[15].pos = Vec3<float>(right, back, bottom);
- vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
- // top side
- vertecies[16].pos = Vec3<float>(left, back, top);
- vertecies[16].tPos = Vec2<float>(0.f, 0.f);
- vertecies[17].pos = Vec3<float>(right, back, top);
- vertecies[17].tPos = Vec2<float>(1.f, 0.f);
- vertecies[18].pos = Vec3<float>(left, front, top);
- vertecies[18].tPos = Vec2<float>(0.f, 1.f);
- vertecies[19].pos = Vec3<float>(right, front, top);
- vertecies[19].tPos = Vec2<float>(1.f, 1.f);
- // botom side
- vertecies[20].pos = Vec3<float>(left, front, bottom);
- vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
- vertecies[21].pos = Vec3<float>(right, front, bottom);
- vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
- vertecies[22].pos = Vec3<float>(left, back, bottom);
- vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
- vertecies[23].pos = Vec3<float>(right, back, bottom);
- vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
- data->setVertecies(vertecies, 24);
- // the order of the polygons has to be NORTH (front), EAST (left), SOUTH
- // (back), WEST (right), TOP, BOTTOM according to the Area definition
- // front side
- Polygon3D* p
- = new Polygon3D(); // looking from (0,0,0) to (1,0,0) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0;
- p->indexList[1] = 1;
- p->indexList[2] = 2;
- p->indexList[3] = 1;
- p->indexList[4] = 3;
- p->indexList[5] = 2;
- data->addPolygon(p);
- // left side
- p = new Polygon3D(); // looking from (0,0,0) to (0,1,0) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 8;
- p->indexList[1] = 1 + 8;
- p->indexList[2] = 2 + 8;
- p->indexList[3] = 1 + 8;
- p->indexList[4] = 3 + 8;
- p->indexList[5] = 2 + 8;
- data->addPolygon(p);
- // back side
- p = new Polygon3D(); // looking from (0,0,0) to (-1,0,0) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 4;
- p->indexList[1] = 1 + 4;
- p->indexList[2] = 2 + 4;
- p->indexList[3] = 1 + 4;
- p->indexList[4] = 3 + 4;
- p->indexList[5] = 2 + 4;
- data->addPolygon(p);
- // right side
- p = new Polygon3D(); // looking from (0,0,0) to (0,-1,0) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 12;
- p->indexList[1] = 1 + 12;
- p->indexList[2] = 2 + 12;
- p->indexList[3] = 1 + 12;
- p->indexList[4] = 3 + 12;
- p->indexList[5] = 2 + 12;
- data->addPolygon(p);
- // top side
- p = new Polygon3D(); // looking from (0,0,0) to (0,0,-1) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 16;
- p->indexList[1] = 1 + 16;
- p->indexList[2] = 2 + 16;
- p->indexList[3] = 1 + 16;
- p->indexList[4] = 3 + 16;
- p->indexList[5] = 2 + 16;
- data->addPolygon(p);
- // botom side
- p = new Polygon3D(); // looking from (0,0,0) to (0,0,1) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 20;
- p->indexList[1] = 1 + 20;
- p->indexList[2] = 2 + 20;
- p->indexList[3] = 1 + 20;
- p->indexList[4] = 3 + 20;
- p->indexList[5] = 2 + 20;
- data->addPolygon(p);
- data->calculateNormals();
- data->release();
- }
- void createGrass(Bildschirm* zScreen)
- {
- Model3DData* data = zScreen->zGraphicsApi()->createModel("grass");
- data->setAmbientFactor(0.f);
- data->setDiffusFactor(1.f);
- data->setSpecularFactor(0.f);
- float size = 1;
- float left, right, top, bottom;
- // Calculate the screen coordinates of the left side of the bitmap.
- right = (float)((-size / 2.0));
- // Calculate the screen coordinates of the right side of the bitmap.
- left = right + (float)size;
- // Calculate the screen coordinates of the top of the bitmap.
- top = (float)(size / 2.0);
- // Calculate the screen coordinates of the bottom of the bitmap.
- bottom = top - (float)size;
- float front = -size / 2;
- float back = front + size;
- Vertex3D* vertecies = new Vertex3D[32];
- for (int i = 0; i < 32; i++)
- vertecies[i].knochenId = 0;
- // first y plane
- vertecies[0].pos = Vec3<float>(left, front + 0.2f, top);
- vertecies[0].tPos = Vec2<float>(0.01f, 0.01f);
- vertecies[1].pos = Vec3<float>(right, front + 0.2f, top);
- vertecies[1].tPos = Vec2<float>(0.99f, 0.01f);
- vertecies[2].pos = Vec3<float>(left, front + 0.2f, bottom);
- vertecies[2].tPos = Vec2<float>(0.01f, 0.99f);
- vertecies[3].pos = Vec3<float>(right, front + 0.2f, bottom);
- vertecies[3].tPos = Vec2<float>(0.99f, 0.99f);
- // second y plane
- vertecies[4].pos = Vec3<float>(left, front + 0.4f, top);
- vertecies[4].tPos = Vec2<float>(0.01f, 0.01f);
- vertecies[5].pos = Vec3<float>(right, front + 0.4f, top);
- vertecies[5].tPos = Vec2<float>(0.99f, 0.01f);
- vertecies[6].pos = Vec3<float>(left, front + 0.4f, bottom);
- vertecies[6].tPos = Vec2<float>(0.01f, 0.99f);
- vertecies[7].pos = Vec3<float>(right, front + 0.4f, bottom);
- vertecies[7].tPos = Vec2<float>(0.99f, 0.99f);
- // third y plane
- vertecies[8].pos = Vec3<float>(left, front + 0.6f, top);
- vertecies[8].tPos = Vec2<float>(0.01f, 0.01f);
- vertecies[9].pos = Vec3<float>(right, front + 0.6f, top);
- vertecies[9].tPos = Vec2<float>(0.99f, 0.01f);
- vertecies[10].pos = Vec3<float>(left, front + 0.6f, bottom);
- vertecies[10].tPos = Vec2<float>(0.01f, 0.99f);
- vertecies[11].pos = Vec3<float>(right, front + 0.6f, bottom);
- vertecies[11].tPos = Vec2<float>(0.99f, 0.99f);
- // forth y plane
- vertecies[12].pos = Vec3<float>(left, front + 0.8f, top);
- vertecies[12].tPos = Vec2<float>(0.01f, 0.01f);
- vertecies[13].pos = Vec3<float>(right, front + 0.8f, top);
- vertecies[13].tPos = Vec2<float>(0.99f, 0.01f);
- vertecies[14].pos = Vec3<float>(left, front + 0.8f, bottom);
- vertecies[14].tPos = Vec2<float>(0.01f, 0.99f);
- vertecies[15].pos = Vec3<float>(right, front + 0.8f, bottom);
- vertecies[15].tPos = Vec2<float>(0.99f, 0.99f);
- // first x plane
- vertecies[16].pos = Vec3<float>(right + 0.2f, front, top);
- vertecies[16].tPos = Vec2<float>(0.01f, 0.01f);
- vertecies[17].pos = Vec3<float>(right + 0.2f, back, top);
- vertecies[17].tPos = Vec2<float>(0.99f, 0.01f);
- vertecies[18].pos = Vec3<float>(right + 0.2f, front, bottom);
- vertecies[18].tPos = Vec2<float>(0.01f, 0.99f);
- vertecies[19].pos = Vec3<float>(right + 0.2f, back, bottom);
- vertecies[19].tPos = Vec2<float>(0.99f, 0.99f);
- // second x plane
- vertecies[20].pos = Vec3<float>(right + 0.4f, front, top);
- vertecies[20].tPos = Vec2<float>(0.01f, 0.01f);
- vertecies[21].pos = Vec3<float>(right + 0.4f, back, top);
- vertecies[21].tPos = Vec2<float>(0.99f, 0.01f);
- vertecies[22].pos = Vec3<float>(right + 0.4f, front, bottom);
- vertecies[22].tPos = Vec2<float>(0.01f, 0.99f);
- vertecies[23].pos = Vec3<float>(right + 0.4f, back, bottom);
- vertecies[23].tPos = Vec2<float>(0.99f, 0.99f);
- // third x plane
- vertecies[24].pos = Vec3<float>(right + 0.6f, front, top);
- vertecies[24].tPos = Vec2<float>(0.01f, 0.01f);
- vertecies[25].pos = Vec3<float>(right + 0.6f, back, top);
- vertecies[25].tPos = Vec2<float>(0.99f, 0.01f);
- vertecies[26].pos = Vec3<float>(right + 0.6f, front, bottom);
- vertecies[26].tPos = Vec2<float>(0.01f, 0.99f);
- vertecies[27].pos = Vec3<float>(right + 0.6f, back, bottom);
- vertecies[27].tPos = Vec2<float>(0.99f, 0.99f);
- // forth x plane
- vertecies[28].pos = Vec3<float>(right + 0.8f, front, top);
- vertecies[28].tPos = Vec2<float>(0.01f, 0.01f);
- vertecies[29].pos = Vec3<float>(right + 0.8f, back, top);
- vertecies[29].tPos = Vec2<float>(0.99f, 0.01f);
- vertecies[30].pos = Vec3<float>(right + 0.8f, front, bottom);
- vertecies[30].tPos = Vec2<float>(0.01f, 0.99f);
- vertecies[31].pos = Vec3<float>(right + 0.8f, back, bottom);
- vertecies[31].tPos = Vec2<float>(0.99f, 0.99f);
- for (int i = 0; i < 16; i++)
- {
- vertecies[i].normal = Vec3<float>(0, 1, 0);
- }
- for (int i = 16; i < 32; i++)
- {
- vertecies[i].normal = Vec3<float>(1, 0, 0);
- }
- data->setVertecies(vertecies, 32);
- Polygon3D* p = new Polygon3D();
- p->indexAnz = 6 * 8;
- p->indexList = new int[p->indexAnz];
- for (int i = 0; i < 8; i++)
- {
- p->indexList[i * 6 + 0] = 0 + i * 4;
- p->indexList[i * 6 + 1] = 1 + i * 4;
- p->indexList[i * 6 + 2] = 2 + i * 4;
- p->indexList[i * 6 + 3] = 1 + i * 4;
- p->indexList[i * 6 + 4] = 3 + i * 4;
- p->indexList[i * 6 + 5] = 2 + i * 4;
- }
- data->addPolygon(p);
- // data->calculateNormals();
- data->release();
- }
- void createFluidCube(Bildschirm* zScreen)
- {
- Model3DData* data = zScreen->zGraphicsApi()->createModel("fluid");
- data->setAmbientFactor(0.f);
- data->setDiffusFactor(1.f);
- data->setSpecularFactor(0.f);
- float size = 1;
- float left, right, top, bottom;
- // Calculate the screen coordinates of the left side of the bitmap.
- right = (float)((-size / 2.0));
- // Calculate the screen coordinates of the right side of the bitmap.
- left = right + (float)size;
- // Calculate the screen coordinates of the top of the bitmap.
- top = (float)(size / 2.0);
- // Calculate the screen coordinates of the bottom of the bitmap.
- bottom = top - (float)size;
- float front = -size / 2;
- float back = front + size;
- Vertex3D* vertecies = new Vertex3D[24];
- for (int i = 0; i < 24; i++)
- vertecies[i].knochenId = 0;
- // front side
- vertecies[0].pos = Vec3<float>(left, front, top);
- vertecies[0].tPos = Vec2<float>(0.f, 0.f);
- vertecies[1].pos = Vec3<float>(right, front, top);
- vertecies[1].tPos = Vec2<float>(1.f, 0.f);
- vertecies[2].pos = Vec3<float>(left, front, bottom);
- vertecies[2].tPos = Vec2<float>(0.f, 1.f);
- vertecies[3].pos = Vec3<float>(right, front, bottom);
- vertecies[3].tPos = Vec2<float>(1.f, 1.f);
- // back side
- vertecies[4].pos = Vec3<float>(right, back, top);
- vertecies[4].tPos = Vec2<float>(0.0f, 0.0f);
- vertecies[5].pos = Vec3<float>(left, back, top);
- vertecies[5].tPos = Vec2<float>(1.0f, 0.0f);
- vertecies[6].pos = Vec3<float>(right, back, bottom);
- vertecies[6].tPos = Vec2<float>(0.0f, 1.0f);
- vertecies[7].pos = Vec3<float>(left, back, bottom);
- vertecies[7].tPos = Vec2<float>(1.0f, 1.0f);
- // left side
- vertecies[8].pos = Vec3<float>(left, back, top);
- vertecies[8].tPos = Vec2<float>(0.f, 0.f);
- vertecies[9].pos = Vec3<float>(left, front, top);
- vertecies[9].tPos = Vec2<float>(1.f, 0.f);
- vertecies[10].pos = Vec3<float>(left, back, bottom);
- vertecies[10].tPos = Vec2<float>(0.f, 1.f);
- vertecies[11].pos = Vec3<float>(left, front, bottom);
- vertecies[11].tPos = Vec2<float>(1.f, 1.f);
- // right side
- vertecies[12].pos = Vec3<float>(right, front, top);
- vertecies[12].tPos = Vec2<float>(0.0f, 0.0f);
- vertecies[13].pos = Vec3<float>(right, back, top);
- vertecies[13].tPos = Vec2<float>(1.0f, 0.0f);
- vertecies[14].pos = Vec3<float>(right, front, bottom);
- vertecies[14].tPos = Vec2<float>(0.0f, 1.0f);
- vertecies[15].pos = Vec3<float>(right, back, bottom);
- vertecies[15].tPos = Vec2<float>(1.0f, 1.0f);
- // top side
- vertecies[16].pos = Vec3<float>(left, back, top);
- vertecies[16].tPos = Vec2<float>(0.f, 0.f);
- vertecies[17].pos = Vec3<float>(right, back, top);
- vertecies[17].tPos = Vec2<float>(1.f, 0.f);
- vertecies[18].pos = Vec3<float>(left, front, top);
- vertecies[18].tPos = Vec2<float>(0.f, 1.f);
- vertecies[19].pos = Vec3<float>(right, front, top);
- vertecies[19].tPos = Vec2<float>(1.f, 1.f);
- // botom side
- vertecies[20].pos = Vec3<float>(left, front, bottom);
- vertecies[20].tPos = Vec2<float>(0.0f, 0.0f);
- vertecies[21].pos = Vec3<float>(right, front, bottom);
- vertecies[21].tPos = Vec2<float>(1.0f, 0.0f);
- vertecies[22].pos = Vec3<float>(left, back, bottom);
- vertecies[22].tPos = Vec2<float>(0.0f, 1.0f);
- vertecies[23].pos = Vec3<float>(right, back, bottom);
- vertecies[23].tPos = Vec2<float>(1.0f, 1.0f);
- data->setVertecies(vertecies, 24);
- // the order of the polygons has to be NORTH (front), EAST (left), SOUTH
- // (back), WEST (right), TOP, BOTTOM according to the Area definition front
- // side
- Polygon3D* p
- = new Polygon3D(); // looking from (0,0,0) to (1,0,0) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0;
- p->indexList[1] = 1;
- p->indexList[2] = 2;
- p->indexList[3] = 1;
- p->indexList[4] = 3;
- p->indexList[5] = 2;
- data->addPolygon(p);
- // left side
- p = new Polygon3D(); // looking from (0,0,0) to (0,1,0) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 8;
- p->indexList[1] = 1 + 8;
- p->indexList[2] = 2 + 8;
- p->indexList[3] = 1 + 8;
- p->indexList[4] = 3 + 8;
- p->indexList[5] = 2 + 8;
- data->addPolygon(p);
- // back side
- p = new Polygon3D(); // looking from (0,0,0) to (-1,0,0) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 4;
- p->indexList[1] = 1 + 4;
- p->indexList[2] = 2 + 4;
- p->indexList[3] = 1 + 4;
- p->indexList[4] = 3 + 4;
- p->indexList[5] = 2 + 4;
- data->addPolygon(p);
- // right side
- p = new Polygon3D(); // looking from (0,0,0) to (0,-1,0) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 12;
- p->indexList[1] = 1 + 12;
- p->indexList[2] = 2 + 12;
- p->indexList[3] = 1 + 12;
- p->indexList[4] = 3 + 12;
- p->indexList[5] = 2 + 12;
- data->addPolygon(p);
- // top side
- p = new Polygon3D(); // looking from (0,0,0) to (0,0,-1) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 16;
- p->indexList[1] = 1 + 16;
- p->indexList[2] = 2 + 16;
- p->indexList[3] = 1 + 16;
- p->indexList[4] = 3 + 16;
- p->indexList[5] = 2 + 16;
- data->addPolygon(p);
- // botom side
- p = new Polygon3D(); // looking from (0,0,0) to (0,0,1) to see this side
- p->indexAnz = 6;
- p->indexList = new int[p->indexAnz];
- p->indexList[0] = 0 + 20;
- p->indexList[1] = 1 + 20;
- p->indexList[2] = 2 + 20;
- p->indexList[3] = 1 + 20;
- p->indexList[4] = 3 + 20;
- p->indexList[5] = 2 + 20;
- data->addPolygon(p);
- data->calculateNormals();
- data->release();
- }
- void createModels(Bildschirm* zScreen)
- {
- createDefaultCube(zScreen);
- createGrass(zScreen);
- createFluidCube(zScreen);
- }
- struct FileInfo
- {
- Text path;
- __int64 size;
- int year;
- int month;
- int day;
- int seconds;
- };
- FactoryClient::FactoryClient()
- {
- client = 0;
- background = 0;
- foreground = 0;
- backgroundReader = 0;
- foregroundReader = 0;
- bgReaderUsage = 0;
- fgReaderUsage = 0;
- }
- FactoryClient::~FactoryClient()
- {
- if (client) disconnect();
- }
- void FactoryClient::loadServerInfo()
- {
- LoadMenu* loadMenu = (LoadMenu*)(Menu*)menuRegister->get("load");
- Text resourcePath = "data/resources/";
- resourcePath.append() << client->getServerIp() << "/"
- << client->getServerPort() << "/";
- Text tmp = resourcePath + "metainfo.dat";
- Datei metaInfo(tmp);
- Trie<FileInfo*> metaInfos;
- Array<FileInfo*> metaInfoList;
- Array<FileInfo*> downloadOrder;
- if (metaInfo.existiert())
- {
- loadMenu->beginNextStage(
- "reading resource metadata", (int)metaInfo.getSize());
- metaInfo.open(Datei::Style::lesen);
- while (!metaInfo.istEnde())
- {
- short len = 0;
- metaInfo.lese((char*)&len, 2);
- char* path = new char[len + 1];
- metaInfo.lese(path, len);
- path[len] = 0;
- FileInfo* fi = new FileInfo();
- fi->path = Text(path);
- fi->size = 0;
- metaInfo.lese((char*)&fi->year, 4);
- metaInfo.lese((char*)&fi->month, 4);
- metaInfo.lese((char*)&fi->day, 4);
- metaInfo.lese((char*)&fi->seconds, 4);
- metaInfos.set(path, len, fi);
- delete[] path;
- metaInfoList.add(fi);
- loadMenu->stageProgress(18 + len);
- }
- metaInfo.close();
- }
- short len = 0;
- foreground->getNachricht((char*)&len, 2);
- while (len)
- {
- char* path = new char[len + 1];
- foreground->getNachricht(path, len);
- path[len] = 0;
- FileInfo* fi = metaInfos.get(path, len);
- int year;
- int month;
- int day;
- int seconds;
- foreground->getNachricht((char*)&year, 4);
- foreground->getNachricht((char*)&month, 4);
- foreground->getNachricht((char*)&day, 4);
- foreground->getNachricht((char*)&seconds, 4);
- if (!fi || fi->year != year || fi->month != month || fi->day != day
- || fi->seconds != seconds)
- {
- if (!fi)
- {
- fi = new FileInfo();
- fi->path = Text(path);
- metaInfos.set(path, len, fi);
- metaInfoList.add(fi);
- }
- fi->year = year;
- fi->month = month;
- fi->day = day;
- fi->seconds = seconds;
- foreground->sende("\1", 1);
- foreground->getNachricht((char*)&fi->size, 8);
- downloadOrder.add(fi);
- }
- else
- {
- foreground->sende("\0", 1);
- }
- delete[] path;
- foreground->getNachricht((char*)&len, 2);
- }
- loadMenu->allProgress(1);
- char* buffer = new char[4096];
- loadMenu->beginNextStage(
- "download updated resouces", downloadOrder.getEintragAnzahl());
- for (FileInfo* info : downloadOrder)
- {
- loadMenu->beginNextStep(info->path, (int)info->size);
- tmp = resourcePath + info->path;
- Datei file(tmp);
- if (!file.existiert())
- {
- file.erstellen();
- }
- file.open(Datei::Style::schreiben);
- __int64 remaining = info->size;
- while (remaining > 0)
- {
- int toRead = remaining > 4096 ? 4096 : (int)remaining;
- foreground->getNachricht(buffer, toRead);
- file.schreibe(buffer, toRead);
- remaining -= toRead;
- loadMenu->stepProgress(toRead);
- }
- file.close();
- loadMenu->stageProgress(1);
- }
- delete[] buffer;
- loadMenu->allProgress(1);
- loadMenu->beginNextStage(
- "writing resource metadata", metaInfoList.getEintragAnzahl());
- if (!metaInfo.existiert())
- {
- metaInfo.erstellen();
- }
- metaInfo.open(Datei::Style::schreiben);
- for (FileInfo* info : metaInfoList)
- {
- short len = (short)info->path.getLength();
- metaInfo.schreibe((char*)&len, 2);
- metaInfo.schreibe(info->path.getText(), len);
- metaInfo.schreibe((char*)&info->year, 4);
- metaInfo.schreibe((char*)&info->month, 4);
- metaInfo.schreibe((char*)&info->day, 4);
- metaInfo.schreibe((char*)&info->seconds, 4);
- loadMenu->stageProgress(1);
- }
- metaInfo.close();
- loadMenu->allProgress(1);
- loadMenu->beginNextStage(
- "loading resources", metaInfoList.getEintragAnzahl());
- for (FileInfo* info : metaInfoList)
- {
- if (info->path.endsWith(".ltdb"))
- {
- LTDBDatei dat;
- dat.setDatei(new Text(resourcePath + info->path));
- dat.leseDaten(0);
- loadMenu->beginNextStep(info->path, dat.getBildAnzahl());
- for (Text* name : *dat.zBildListe())
- {
- Bild* b = dat.laden(0, new Text(*name));
- uiFactory.initParam.bildschirm->zGraphicsApi()
- ->createOrGetTextur(info->path + "/" + *name, b)
- ->release();
- loadMenu->stepProgress(1);
- }
- }
- else if (info->path.endsWith(".m3"))
- {
- M3Datei dat(resourcePath + info->path);
- dat.leseDaten();
- loadMenu->beginNextStep(info->path, dat.getModelAnzahl());
- for (int i = 0; i < dat.getModelAnzahl(); i++)
- {
- Model3DData* d = dat.ladeModel(dat.zModelName(i)->getText(),
- uiFactory.initParam.bildschirm->zGraphicsApi(),
- info->path + "/" + *dat.zModelName(i));
- d->release();
- loadMenu->stepProgress(1);
- }
- }
- loadMenu->stageProgress(1);
- }
- loadMenu->allProgress(1);
- createModels(uiFactory.initParam.bildschirm);
- loadMenu->allProgress(1);
- std::cout << "downloading server type information\n";
- // receive type information
- for (int i = 0; i < blockTypeCount; i++)
- blockTypes[i]->release();
- delete[] blockTypes;
- for (int i = 0; i < itemTypeCount; i++)
- itemTypes[i]->release();
- delete[] itemTypes;
- for (int i = 0; i < entityTypeCount; i++)
- entityTypes[i]->release();
- delete[] entityTypes;
- foregroundReader->lese((char*)&blockTypeCount, 4);
- blockTypes = new BlockType*[blockTypeCount];
- for (int i = 0; i < blockTypeCount; i++)
- {
- int id;
- foregroundReader->lese((char*)&id, 4);
- bool needsInstance;
- foregroundReader->lese((char*)&needsInstance, 1);
- bool needsSubscription;
- foregroundReader->lese((char*)&needsSubscription, 1);
- bool fluid;
- foregroundReader->lese((char*)&fluid, 1);
- char maxFlowDistance = 0;
- if (fluid) foregroundReader->lese((char*)&maxFlowDistance, 1);
- int maxHp;
- foregroundReader->lese((char*)&maxHp, 4);
- blockTypes[i] = new BlockType(id,
- needsInstance,
- ModelInfo(foregroundReader),
- maxHp,
- needsSubscription,
- fluid,
- maxFlowDistance);
- }
- loadMenu->allProgress(1);
- foregroundReader->lese((char*)&itemTypeCount, 4);
- itemTypes = new ItemType*[itemTypeCount];
- for (int i = 0; i < itemTypeCount; i++)
- {
- int id;
- foregroundReader->lese((char*)&id, 4);
- char len;
- foregroundReader->lese((char*)&len, 1);
- char* name = new char[len + 1];
- foregroundReader->lese(name, len);
- name[len] = 0;
- short tlen;
- foregroundReader->lese((char*)&tlen, 2);
- char* tooltipUIML = new char[tlen + 1];
- foregroundReader->lese(tooltipUIML, tlen);
- tooltipUIML[tlen] = 0;
- itemTypes[i] = new ItemType(
- id, ModelInfo(foregroundReader), Text(name), Text(tooltipUIML));
- delete[] name;
- delete[] tooltipUIML;
- }
- loadMenu->allProgress(1);
- foregroundReader->lese((char*)&entityTypeCount, 4);
- entityTypes = new EntityType*[entityTypeCount];
- for (int i = 0; i < entityTypeCount; i++)
- {
- int id;
- foregroundReader->lese((char*)&id, 4);
- entityTypes[i] = new EntityType(id, ModelInfo(foregroundReader));
- }
- loadMenu->allProgress(1);
- loadMenu->beginNextStage("rendering item icons", itemTypeCount);
- Kam3D* kam = new Kam3D();
- Welt3D* w = new Welt3D();
- w->addDiffuseLight(DiffuseLight{
- Vec3<float>(0.5f, 0.5f, -1.f), Vec3<float>(1.f, 1.f, 1.f)});
- kam->setWelt(w);
- kam->setBildschirmPosition(0, 0);
- kam->setBildschirmSize(50, 50);
- kam->setPosition(Vec3<float>(0, 0, 0));
- kam->setRotation(
- {(float)PI / 2.f, 0.f, std::atan2(0.f, -1.f) + (float)PI / 2});
- Bild* b = new Bild();
- b->neuBild(50, 50, 0);
- for (int i = 0; i < itemTypeCount; i++)
- {
- Model3D* mdl = new Model3D();
- Model3DData* data = itemTypes[i]->getItemModel();
- if (data)
- {
- Vec3<float> min = data->getMinPos();
- Vec3<float> max = data->getMaxPos();
- float maxX = MAX(
- MAX(MAX(abs(min.x), abs(max.x)), MAX(abs(min.y), abs(max.y))),
- MAX(abs(min.z), abs(max.z)));
- kam->setPosition(Vec3<float>(maxX * 3.5f, 0.f, 0.f));
- }
- mdl->setModelDaten(data);
- mdl->setModelTextur(itemTypes[i]->getItemTextur());
- mdl->setPosition(Vec3<float>(0.f, 0.f, 0.f));
- mdl->setDrehung(0.25f, 0.25f, 0.55f);
- mdl->setAmbientFactor(0.8f);
- mdl->setDiffusFactor(0.1f);
- mdl->setSpecularFactor(0.1f);
- mdl->setSize(itemTypes[i]->getSize());
- w->addZeichnung(mdl);
- w->tick(0);
- window->zBildschirm()->lock();
- DX11Textur* t = (DX11Textur*)window->zBildschirm()
- ->zGraphicsApi()
- ->createOrGetTextur(
- Text("rendered/items/") + itemTypes[i]->getId(),
- dynamic_cast<Bild*>(b->getThis()));
- window->zBildschirm()->zGraphicsApi()->renderKamera(kam, t);
- Bild* result = new Bild();
- t->copyToImage(result);
- itemTypes[i]->setBild(result);
- t->release();
- window->zBildschirm()->unlock();
- w->removeZeichnung(mdl);
- loadMenu->stageProgress(1);
- }
- b->release();
- kam->release();
- loadMenu->allProgress(1);
- }
- bool FactoryClient::connect(Text ip, unsigned short sslPort)
- {
- if (client) disconnect();
- client = new SSLKlient();
- if (!client->verbinde(sslPort, ip)) return false;
- char c;
- while (client->hatNachricht(1))
- client->getNachricht(&c, 1);
- this->ip = ip;
- return 1;
- }
- int FactoryClient::ping()
- {
- ZeitMesser zm;
- zm.messungStart();
- if (!client->sende("\3", 1)) return -1;
- char c;
- client->getNachricht(&c, 1);
- zm.messungEnde();
- return (int)(zm.getSekunden() * 1000);
- }
- int FactoryClient::status(Framework::Text name, Framework::Text secret)
- {
- if (!client->sende("\4", 1)) return 404;
- char c;
- client->getNachricht(&c, 1);
- if (c == 1)
- {
- char len = (char)name.getLength();
- client->sende(&len, 1);
- client->sende(name, len);
- short sLen = (short)secret.getLength();
- client->sende((char*)&sLen, 2);
- client->sende(secret, sLen);
- char res;
- client->getNachricht(&res, 1);
- if (res == 1) return 200;
- if (res == 0) return 403;
- }
- return 404;
- }
- int FactoryClient::join(
- Framework::Text name, Framework::Text& secret, unsigned short port)
- {
- client->sende("\1", 1);
- char len = (char)name.getLength();
- client->sende(&len, 1);
- client->sende(name, len);
- short sLen = (short)secret.getLength();
- client->sende((char*)&sLen, 2);
- client->sende(secret, sLen);
- char res;
- client->getNachricht(&res, 1);
- if (res == 1 || res == 2)
- {
- if (res == 2)
- {
- client->getNachricht((char*)&sLen, 2);
- char* buffer = new char[sLen + 1];
- client->getNachricht(buffer, sLen);
- buffer[sLen] = 0;
- secret = buffer;
- delete[] buffer;
- }
- short keyLen;
- client->getNachricht((char*)&keyLen, 2);
- char* key = new char[keyLen];
- client->getNachricht(key, keyLen);
- foreground = new Klient();
- if (!foreground->verbinde(port, ip))
- {
- delete[] key;
- return false;
- }
- if (!foreground->sende((char*)&keyLen, 2))
- {
- delete[] key;
- return false;
- }
- if (!foreground->sende(key, keyLen))
- {
- delete[] key;
- return false;
- }
- background = new Klient();
- if (!background->verbinde(port, ip))
- {
- delete[] key;
- foreground->release();
- foreground = 0;
- background->release();
- background = 0;
- return false;
- }
- if (!background->sende((char*)&keyLen, 2))
- {
- delete[] key;
- foreground->release();
- foreground = 0;
- background->release();
- background = 0;
- return false;
- }
- if (!background->sende(key, keyLen))
- {
- delete[] key;
- foreground->release();
- foreground = 0;
- background->release();
- background = 0;
- return false;
- }
- delete[] key;
- bool bg = 0;
- if (!foreground->sende((char*)&bg, 1))
- {
- delete[] key;
- return 201;
- }
- foregroundReader = new NetworkReader(foreground);
- bg = 1;
- if (!background->sende((char*)&bg, 1)) return 201;
- backgroundReader = new NetworkReader(background);
- char res;
- foregroundReader->lese(&res, 1);
- if (res != 1) return 403;
- backgroundReader->lese(&res, 1);
- if (res != 1) return 403;
- client->trenne();
- loadServerInfo();
- return 200;
- }
- if (res == 0) return 403;
- return 500;
- }
- void FactoryClient::disconnect()
- {
- if (client)
- {
- NetworkReader* fgReader = foregroundReader;
- NetworkReader* bgReader = backgroundReader;
- backgroundReader = 0;
- foregroundReader = 0;
- if (foreground) foreground->trenne();
- if (background) background->trenne();
- while (fgReaderUsage > 0 || bgReaderUsage > 0)
- Sleep(100);
- delete fgReader;
- delete bgReader;
- client->release();
- client = 0;
- if (foreground) foreground->release();
- foreground = 0;
- if (background) background->release();
- background = 0;
- }
- }
- NetworkReader* FactoryClient::getNextForegroundMessage()
- {
- fgReaderUsage++;
- if (!foreground) return 0;
- if (!foreground->isConnected()) return 0;
- if (!foreground->hatNachricht(0)) return 0;
- return foregroundReader;
- }
- NetworkReader* FactoryClient::getNextBackgroundMessage()
- {
- bgReaderUsage++;
- if (!background) return 0;
- if (!background->isConnected()) return 0;
- if (!background->hatNachricht(0)) return 0;
- return backgroundReader;
- }
- void FactoryClient::endMessageReading(bool bg)
- {
- if (bg)
- bgReaderUsage--;
- else
- fgReaderUsage--;
- }
- void FactoryClient::sendPlayerAction(const char* data, unsigned short length)
- {
- if (!foreground) return;
- cs.lock();
- length += 1;
- foreground->sende((char*)&length, 2);
- char msgId = 2;
- foreground->sende(&msgId, 1);
- foreground->sende((char*)data, length - 1);
- cs.unlock();
- }
- void FactoryClient::sendPlayerMovement(MovementFrame& frame)
- {
- if (!foreground) return;
- cs.lock();
- short length = 38;
- foreground->sende((char*)&length, 2);
- char msgId = 2; // player message
- foreground->sende(&msgId, 1);
- foreground->sende(&msgId, 1); // set movement
- foreground->sende((char*)&frame.direction.x, 4);
- foreground->sende((char*)&frame.direction.y, 4);
- foreground->sende((char*)&frame.direction.z, 4);
- foreground->sende((char*)&frame.targetPosition.x, 4);
- foreground->sende((char*)&frame.targetPosition.y, 4);
- foreground->sende((char*)&frame.targetPosition.z, 4);
- foreground->sende((char*)&frame.movementFlags, 4);
- foreground->sende((char*)&frame.duration, 8);
- cs.unlock();
- }
- void FactoryClient::entityAPIRequest(
- int entityId, const char* message, unsigned short length)
- {
- if (!foreground) return;
- cs.lock();
- length += 5;
- foreground->sende((char*)&length, 2);
- char msgId = 3;
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&entityId, 4);
- foreground->sende(message, length - 5);
- cs.unlock();
- }
- void FactoryClient::blockAPIRequest(
- Vec3<int> pos, const char* message, unsigned short length)
- {
- if (!foreground) return;
- cs.lock();
- length += 14;
- foreground->sende((char*)&length, 2);
- char msgId = 1;
- foreground->sende(&msgId, 1);
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&pos.x, 4);
- foreground->sende((char*)&pos.y, 4);
- foreground->sende((char*)&pos.z, 4);
- foreground->sende(message, length - 14);
- cs.unlock();
- }
- void FactoryClient::componentAPIRequest(
- int* address, int addrLen, const char* message, unsigned short length)
- {
- if (!foreground) return;
- cs.lock();
- short sum = length + addrLen * 4 + (addrLen > 2 ? 3 : 2);
- foreground->sende((char*)&sum, 2);
- if (addrLen > 2)
- {
- char msgId = 7; // dimension request
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&address[0], 4); // dimension id
- msgId = 1; // block request
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&address[1], 4); // position x
- foreground->sende((char*)&address[2], 4); // position y
- foreground->sende((char*)&address[3], 4); // position z
- msgId = 2; // component request
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&address[4], 4); // component index
- }
- else
- {
- char msgId = 3; // entity request
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&address[0], 4); // entity id
- msgId = 2; // component request
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&address[1], 4); // component index
- }
- foreground->sende(message, length);
- cs.unlock();
- }
- void FactoryClient::blockAPIRequest(
- int dimensionId, Vec3<int> pos, const char* message, unsigned short length)
- {
- if (!foreground) return;
- cs.lock();
- length += 18;
- foreground->sende((char*)&length, 2);
- char msgId = 7;
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&dimensionId, 4);
- msgId = 1;
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&pos.x, 4);
- foreground->sende((char*)&pos.y, 4);
- foreground->sende((char*)&pos.z, 4);
- foreground->sende(message, length - 18);
- cs.unlock();
- }
- void FactoryClient::chunkAPIRequest(
- Punkt center, const char* message, unsigned short length)
- {
- if (!foreground) return;
- length += 10;
- cs.lock();
- foreground->sende((char*)&length, 2);
- char type = 1;
- foreground->sende(&type, 1);
- type = 0;
- foreground->sende(&type, 1);
- foreground->sende((char*)¢er.x, 4);
- foreground->sende((char*)¢er.y, 4);
- foreground->sende(message, length - 10);
- cs.unlock();
- }
- void FactoryClient::dimensionAPIRequest(
- const char* message, unsigned short length)
- {
- if (!foreground) return;
- length += 1;
- cs.lock();
- foreground->sende((char*)&length, 2);
- char type = 1;
- foreground->sende(&type, 1);
- foreground->sende(message, length - 1);
- cs.unlock();
- }
- void FactoryClient::inventoryAPIRequest(
- Framework::Either<int, Framework::VecN<int, 4>> target,
- const char* message,
- unsigned short length)
- {
- if (!foreground) return;
- cs.lock();
- length += target.isA() ? 6 : 18;
- foreground->sende((char*)&length, 2);
- char msgId = 4;
- foreground->sende(&msgId, 1);
- bool isEntity = target.isA();
- foreground->sende((char*)&isEntity, 1);
- if (target.isA())
- {
- int id = target.getA();
- foreground->sende((char*)&id, 4);
- }
- else
- {
- for (int i = 0; i < 4; i++)
- {
- int v = target.getB()[i];
- foreground->sende((char*)&v, 4);
- }
- }
- foreground->sende(message, length - (target.isA() ? 6 : 18));
- cs.unlock();
- }
- void FactoryClient::uiRequest(
- Framework::Text dialogId, const char* message, unsigned short length)
- {
- if (!foreground) return;
- short nameLen = (short)dialogId.getLength();
- length += nameLen + 3;
- foreground->sende((char*)&length, 2);
- cs.lock();
- char msgId = 8;
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&nameLen, 2);
- foreground->sende(dialogId, nameLen);
- foreground->sende(message, length - nameLen - 3);
- cs.unlock();
- }
- void FactoryClient::craftingUIMLRequest(int itemTypeId)
- {
- if (!foreground) return;
- cs.lock();
- short length = 5;
- foreground->sende((char*)&length, 2);
- char msgId = 5;
- foreground->sende(&msgId, 1);
- foreground->sende((char*)&itemTypeId, 4);
- cs.unlock();
- }
- void FactoryClient::sendChatMessage(Framework::Text message)
- {
- if (!background) return;
- cs.lock();
- short length = message.getLength() + 4;
- background->sende((char*)&length, 2);
- char msgId = 6;
- background->sende(&msgId, 1);
- msgId = 0;
- background->sende(&msgId, 1);
- length = message.getLength();
- background->sende((char*)&length, 2);
- background->sende(message.getText(), message.getLength());
- cs.unlock();
- }
- void FactoryClient::chatAPIRequest(const char* data, unsigned short length)
- {
- if (!background) return;
- cs.lock();
- short totalLength = length + 1;
- background->sende((char*)&totalLength, 2);
- char msgId = 6;
- background->sende(&msgId, 1);
- background->sende(data, length);
- cs.unlock();
- }
- bool FactoryClient::isConnected()
- {
- return foreground && background && foreground->isConnected()
- && background->isConnected();
- }
- void FactoryClient::leaveGame()
- {
- cs.lock();
- disconnect();
- cs.unlock();
- }
|