X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=contrib%2Fbobtoolz%2FDPatch.cpp;h=30bb5c60029e90342021d20bd32faf4c97bf7b2e;hp=1c0ee385d184628b69d121148242d894e1371a39;hb=0f319946a6e6fbddc51888c150f8be46bc4b142c;hpb=12b372f89ce109a4db9d510884fbe7d05af79870 diff --git a/contrib/bobtoolz/DPatch.cpp b/contrib/bobtoolz/DPatch.cpp index 1c0ee385..30bb5c60 100644 --- a/contrib/bobtoolz/DPatch.cpp +++ b/contrib/bobtoolz/DPatch.cpp @@ -21,17 +21,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "DPatch.h" -#include "gtkr_list.h" +#include #include "str.h" +#include "scenelib.h" -//#include "DPoint.h" -//#include "DPlane.h" -//#include "DBrush.h" -//#include "DEPair.h" -#include "DPatch.h" -//#include "DEntity.h" +#include "ipatch.h" #include "misc.h" #include "./dialogs/dialogs-gtk.h" @@ -50,6 +46,7 @@ DPatch::DPatch() { width = MIN_PATCH_WIDTH; height = MIN_PATCH_HEIGHT; + QER_entity = NULL; QER_brush = NULL; } @@ -73,47 +70,53 @@ void CopyDrawVert(const drawVert_t* in, drawVert_t* out) VectorCopy(in->xyz, out->xyz); } -void DPatch::BuildInRadiant(void* entity) +void DPatch::BuildInRadiant(scene::Node* entity) { -#if 0 - int nIndex = g_FuncTable.m_pfnCreatePatchHandle(); - //$ FIXME: m_pfnGetPatchHandle - patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData(nIndex); + NodeSmartReference patch(GlobalPatchCreator().createPatch()); - b->patchBrush = true; - b->pPatch = Patch_Alloc(); - b->pPatch->setDims(width,height); + scene::Node& parent = entity != 0 ? *entity : GlobalRadiant().getMapWorldEntity(); + Node_getTraversable(parent)->insert(patch); + GlobalPatchCreator().Patch_setShader(patch, texture); + GlobalPatchCreator().Patch_resize(patch, height, width); + PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints(patch); for(int x = 0; x < height; x++) { for(int y = 0; y < width; y++) { - float *p = b->pPatch->ctrlAt(ROW,x,y); - p[0] = points[x][y].xyz[0]; - p[1] = points[x][y].xyz[1]; - p[2] = points[x][y].xyz[2]; - p[3] = points[x][y].st[0]; - p[4] = points[x][y].st[1]; + PatchControl& p = matrix(y, x); + p.m_vertex[0] = points[x][y].xyz[0]; + p.m_vertex[1] = points[x][y].xyz[1]; + p.m_vertex[2] = points[x][y].xyz[2]; + p.m_texcoord[0] = points[x][y].st[0]; + p.m_texcoord[1] = points[x][y].st[1]; } } + GlobalPatchCreator().Patch_controlPointsChanged(patch); + + QER_entity = entity; + QER_brush = patch.get_pointer(); - if(entity) - g_FuncTable.m_pfnCommitBrushHandleToEntity(QER_brush, entity); - else - g_FuncTable.m_pfnCommitBrushHandle(QER_brush); + +#if 0 + int nIndex = g_FuncTable.m_pfnCreatePatchHandle(); + //$ FIXME: m_pfnGetPatchHandle + patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData(nIndex); + + b->patchBrush = true; + b->pPatch = Patch_Alloc(); + b->pPatch->setDims(width,height); for(int x = 0; x < width; x++) for(int y = 0; y < height; y++) CopyDrawVert(&points[x][y], &pm->ctrl[x][y]); - QER_patch = pm; - /* if(entity) { // strcpy(pm->d_texture->name, texture); brush_t* brush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle(); - brush->patchBrush = TRUE; + brush->patchBrush = true; brush->pPatch = pm; pm->pSymbiot = brush; @@ -135,9 +138,29 @@ void DPatch::BuildInRadiant(void* entity) #endif } -void DPatch::LoadFromBrush(scene::Node* brush) +void DPatch::LoadFromPatch(scene::Instance& patch) { - QER_brush = brush; + QER_entity = patch.path().parent().get_pointer(); + QER_brush = patch.path().top().get_pointer(); + + PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints(patch.path().top()); + + width = static_cast(matrix.x()); + height = static_cast(matrix.y()); + + for(int x = 0; x < height; x++) + { + for(int y = 0; y < width; y++) + { + PatchControl& p = matrix(y, x); + points[x][y].xyz[0] = p.m_vertex[0]; + points[x][y].xyz[1] = p.m_vertex[1]; + points[x][y].xyz[2] = p.m_vertex[2]; + points[x][y].st[0] = p.m_texcoord[0]; + points[x][y].st[1] = p.m_texcoord[1]; + } + } + SetTexture(GlobalPatchCreator().Patch_getShader(patch.path().top())); #if 0 SetTexture(brush->pPatch->GetShader()); @@ -160,25 +183,15 @@ void DPatch::LoadFromBrush(scene::Node* brush) #endif } -void DPatch::RemoveFromRadiant() -{ - if(QER_brush) - { -#if 0 - g_FuncTable.m_pfnDeleteBrushHandle(QER_brush); -#endif - } -} - bool DPatch::ResetTextures(const char *oldTextureName, const char *newTextureName) { if( !oldTextureName || !strcmp(texture, oldTextureName)) { strcpy(texture, newTextureName); - return TRUE; + return true; } - return FALSE; + return false; } void Build1dArray(vec3_t* array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT], @@ -205,8 +218,8 @@ void Build1dArray(vec3_t* array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HE void Print1dArray(vec3_t* array, int size) { for(int i = 0; i < size; i++) - Sys_Printf("(%.0f %.0f %.0f)\t", array[i][0], array[i][1], array[i][2]); - Sys_Printf("\n"); + globalOutputStream() << "(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t"; + globalOutputStream() << "\n"; } bool Compare1dArrays(vec3_t* a1, vec3_t* a2, int size) @@ -309,11 +322,11 @@ DPatch* DPatch::MergePatches(patch_merge_t merge_info, DPatch *p1, DPatch *p2) int i; for(i = 0; i < p1->height; i++, y++) for(int x = 0; x < p1->width; x++) - memcpy(&newPatch->points[x][y], &p1->points[x][i], sizeof(drawVert_t)); + newPatch->points[x][y] = p1->points[x][i]; for(i = 1; i < p2->height; i++, y++) for(int x = 0; x < p2->width; x++) - memcpy(&newPatch->points[x][y], &p2->points[x][i], sizeof(drawVert_t)); + newPatch->points[x][y] = p2->points[x][i]; // newPatch->Invert(); @@ -322,16 +335,13 @@ DPatch* DPatch::MergePatches(patch_merge_t merge_info, DPatch *p1, DPatch *p2) void DPatch::Invert() { - drawVert_t vertTemp; int i, j; for(i = 0 ; i < width ; i++ ) { for(j = 0; j < height / 2; j++) { - memcpy(&vertTemp, &points[i][height - 1- j], sizeof (drawVert_t)); - memcpy(&points[i][height - 1 - j], &points[i][j], sizeof(drawVert_t)); - memcpy(&points[i][j], &vertTemp, sizeof(drawVert_t)); + std::swap(points[i][height - 1- j], points[i][j]); } } } @@ -339,7 +349,6 @@ void DPatch::Invert() void DPatch::Transpose() { int i, j, w; - drawVert_t dv; if ( width > height ) { @@ -350,14 +359,12 @@ void DPatch::Transpose() if ( j < height ) { // swap the value - memcpy(&dv, &points[j][i], sizeof(drawVert_t)); - memcpy(&points[j][i], &points[i][j], sizeof(drawVert_t)); - memcpy(&points[i][j], &dv, sizeof(drawVert_t)); + std::swap(points[j][i], points[i][j]); } else { // just copy - memcpy(&points[i][j], &points[j][i], sizeof(drawVert_t)); + points[i][j] = points[j][i]; } } } @@ -371,14 +378,12 @@ void DPatch::Transpose() if ( j < width ) { // swap the value - memcpy(&dv, &points[i][j], sizeof(drawVert_t)); - memcpy(&points[i][j], &points[j][i], sizeof(drawVert_t)); - memcpy(&points[j][i], &dv, sizeof(drawVert_t)); + std::swap(points[i][j], points[j][i]); } else { // just copy - memcpy(&points[j][i], &points[i][j], sizeof(drawVert_t)); + points[j][i] = points[i][j]; } } } @@ -391,9 +396,9 @@ void DPatch::Transpose() Invert(); } -list DPatch::Split(bool rows, bool cols) +std::list DPatch::Split(bool rows, bool cols) { - list patchList; + std::list patchList; int i; int x, y; @@ -411,7 +416,7 @@ list DPatch::Split(bool rows, bool cols) { for(x = 0; x < p.width; x++) { - memcpy(&p.points[x][y], &points[x][(i*2)+y], sizeof(drawVert_t)); + p.points[x][y] = points[x][(i*2)+y]; } } patchList.push_back(p); @@ -419,13 +424,13 @@ list DPatch::Split(bool rows, bool cols) if(cols && width >= 5) { - list patchList2; + std::list patchList2; - for(list::iterator patches = patchList.begin(); patches != patchList.end(); patches++) + for(std::list::iterator patches = patchList.begin(); patches != patchList.end(); patches++) { - list patchList3 = (*patches).Split(false, true); + std::list patchList3 = (*patches).Split(false, true); - for(list::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++) + for(std::list::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++) patchList2.push_front(*patches2); } @@ -446,7 +451,7 @@ list DPatch::Split(bool rows, bool cols) { for(y = 0; y < p.height; y++) { - memcpy(&p.points[x][y], &points[(i*2)+x][y], sizeof(drawVert_t)); + p.points[x][y] = points[(i*2)+x][y]; } }