Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Fr Jul 18, 2025 05:05

Foren-Übersicht » Programmierung » Allgemein
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 5 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: c nach delphi uff
BeitragVerfasst: Mo Apr 26, 2004 20:37 
Offline
DGL Member

Registriert: Mi Mär 24, 2004 16:45
Beiträge: 29
Hi,

ich habe für mein spiel mir nen BSP (das mapformat) Loader geholt, der schon in delphi geschrieben ist. Er ist dem von gametutorials.com sehr ähnlich nur hat er leider nicht die super optimierung des in c geschriebenen Loaders von gametutorials.com.
Da sind noch irgentso dinger die sich leafs nennen (und noch so n kram) mit dem man glaub ich rausfindet in welchem teil des levels man ist und daher auch was gemalt werden muss. (das wird ja vom leveleditor vorberechnet und is deshalb extrem schnell)

also hab ich mir den code in c geholt und jetzt friemel ich mir die benötigten stücke raus und übersetzte sie nach delphi.
Bin leider nich grad so n experte in C und deshalb hab ich ziemlich schwierigkeiten damit ... aber hier ersma der teil den ich schon übersetzt hab.

Code:
  1.  
  2. /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *
  3.  
  4.     // In this function we read from a bunch of new lumps.  These include
  5.     // the BSP nodes, the leafs, the leaf faces, BSP splitter planes and
  6.     // visibility data (clusters).
  7.  
  8.     // Store the number of nodes and allocate the memory to hold them
  9.     m_numOfNodes = lumps[kNodes].length / sizeof(tBSPNode);
  10.     m_pNodes     = new tBSPNode [m_numOfNodes];
  11.  
  12.     // Seek to the position in the file that hold the nodes and store them in m_pNodes
  13.     fseek(fp, lumps[kNodes].offset, SEEK_SET);
  14.     fread(m_pNodes, m_numOfNodes, sizeof(tBSPNode), fp);
  15.  
  16.     // Store the number of leafs and allocate the memory to hold them
  17.     m_numOfLeafs = lumps[kLeafs].length / sizeof(tBSPLeaf);
  18.     m_pLeafs     = new tBSPLeaf [m_numOfLeafs];
  19.  
  20.     // Seek to the position in the file that holds the leafs and store them in m_pLeafs
  21.     fseek(fp, lumps[kLeafs].offset, SEEK_SET);
  22.     fread(m_pLeafs, m_numOfLeafs, sizeof(tBSPLeaf), fp);
  23.  
  24.     // Now we need to go through and convert all the leaf bounding boxes
  25.     // to the normal OpenGL Y up axis.
  26.     for(i = 0; i < m_numOfLeafs; i++)
  27.     {
  28.         // Swap the min y and z values, then negate the new Z
  29.         int temp = m_pLeafs[i].min.y;
  30.         m_pLeafs[i].min.y = m_pLeafs[i].min.z;
  31.         m_pLeafs[i].min.z = -temp;
  32.  
  33.         // Swap the max y and z values, then negate the new Z
  34.         temp = m_pLeafs[i].max.y;
  35.         m_pLeafs[i].max.y = m_pLeafs[i].max.z;
  36.         m_pLeafs[i].max.z = -temp;
  37.     }
  38.  
  39.     // Store the number of leaf faces and allocate the memory for them
  40.     m_numOfLeafFaces = lumps[kLeafFaces].length / sizeof(int);
  41.     m_pLeafFaces     = new int [m_numOfLeafFaces];
  42.  
  43.     // Seek to the leaf faces lump, then read it's data
  44.     fseek(fp, lumps[kLeafFaces].offset, SEEK_SET);
  45.     fread(m_pLeafFaces, m_numOfLeafFaces, sizeof(int), fp);
  46.  
  47.     // Store the number of planes, then allocate memory to hold them
  48.     m_numOfPlanes = lumps[kPlanes].length / sizeof(tBSPPlane);
  49.     m_pPlanes     = new tBSPPlane [m_numOfPlanes];
  50.  
  51.     // Seek to the planes lump in the file, then read them into m_pPlanes
  52.     fseek(fp, lumps[kPlanes].offset, SEEK_SET);
  53.     fread(m_pPlanes, m_numOfPlanes, sizeof(tBSPPlane), fp);
  54.  
  55.     // Go through every plane and convert it's normal to the Y-axis being up
  56.     for(i = 0; i < m_numOfPlanes; i++)
  57.     {
  58.         float temp = m_pPlanes[i].vNormal.y;
  59.         m_pPlanes[i].vNormal.y = m_pPlanes[i].vNormal.z;
  60.         m_pPlanes[i].vNormal.z = -temp;
  61.     }
  62.  
  63.     // Seek to the position in the file that holds the visibility lump
  64.     fseek(fp, lumps[kVisData].offset, SEEK_SET);
  65.  
  66.     // Check if there is any visibility information first
  67.     if(lumps[kVisData].length)
  68.     {
  69.         // Read in the number of vectors and each vector's size
  70.         fread(&(m_clusters.numOfClusters),   1, sizeof(int), fp);
  71.         fread(&(m_clusters.bytesPerCluster), 1, sizeof(int), fp);
  72.  
  73.         // Allocate the memory for the cluster bitsets
  74.         int size = m_clusters.numOfClusters * m_clusters.bytesPerCluster;
  75.         m_clusters.pBitsets = new byte [size];
  76.  
  77.         // Read in the all the visibility bitsets for each cluster
  78.         fread(m_clusters.pBitsets, 1, sizeof(byte) * size, fp);
  79.     }
  80.     // Otherwise, we don't have any visibility data (prevents a crash)
  81.     else
  82.         m_clusters.pBitsets = NULL;
  83.  
  84. /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *
  85.  
  86.  


meine übersetzung:
Code:
  1.  
  2. /// new~~~~~~~~~~~~~~~~new
  3.     // In this function we read from a bunch of new lumps.  These include
  4.     // the BSP nodes, the leafs, the leaf faces, BSP splitter planes and
  5.     // visibility data (clusters).
  6.  
  7.     // Store the number of nodes and allocate the memory to hold them
  8.     m_numOfNodes := lumps[kNodes].length div sizeof(tBSPNode);
  9.     SetLength(m_pNodes,m_numOfNodes);//     := new tBSPNode [m_numOfNodes];
  10.  
  11.     // Seek to the position in the file that hold the nodes and store them in m_pNodes
  12.     seek(f, lumps[kNodes].offset);
  13.     blockread(f,m_pNodes[0], m_numOfNodes*sizeof(tBSPNode));
  14.     // Store the number of leafs and allocate the memory to hold them
  15.     m_numOfLeafs := lumps[kLeafs].length div sizeof(tBSPLeaf);
  16.     SetLength(m_pLeafs,m_numOfLeafs);//     = new tBSPLeaf [m_numOfLeafs];
  17.  
  18.     // Seek to the position in the file that holds the leafs and store them in m_pLeafs
  19.     seek(f, lumps[kLeafs].offset);
  20.     blockread(f,m_pLeafs[0], m_numOfLeafs*sizeof(tBSPLeaf));
  21.  
  22.     // Now we need to go through and convert all the leaf bounding boxes
  23.     // to the normal OpenGL Y up axis.
  24.     for i:=0 to m_numOfLeafs-1 do begin
  25.         // Swap the min y and z values, then negate the new Z
  26.         temp := m_pLeafs[i].min.y;
  27.         m_pLeafs[i].min.y := m_pLeafs[i].min.z;
  28.         m_pLeafs[i].min.z := -temp;
  29.  
  30.         // Swap the max y and z values, then negate the new Z
  31.         temp := m_pLeafs[i].max.y;
  32.         m_pLeafs[i].max.y := m_pLeafs[i].max.z;
  33.         m_pLeafs[i].max.z := -temp;
  34.   end;
  35.  
  36.     // Store the number of leaf faces and allocate the memory for them
  37.     m_numOfLeafFaces := lumps[kLeafFaces].length div sizeof(integer);
  38.     SetLength(m_pLeafFaces,m_numOfLeafFaces);//     = new int [m_numOfLeafFaces];
  39.  
  40.     // Seek to the leaf faces lump, then read it's data
  41.     seek(f, lumps[kLeafFaces].offset);
  42.     blockread(f,m_pLeafFaces[0], m_numOfLeafFaces*sizeof(integer));
  43.  
  44.     // Store the number of planes, then allocate memory to hold them
  45.     m_numOfPlanes := lumps[kPlanes].length div sizeof(tBSPPlane);
  46.     setLength(m_pPlanes,m_numOfPlanes);//     = new tBSPPlane [m_numOfPlanes];
  47.  
  48.     // Seek to the planes lump in the file, then read them into m_pPlanes
  49.     seek(f, lumps[kPlanes].offset);
  50.     blockread(f, m_pPlanes[0], m_numOfPlanes*sizeof(tBSPPlane));
  51.  
  52.     // Go through every plane and convert it's normal to the Y-axis being up
  53.     for i:=0 to m_numOfPlanes-1 do begin
  54.         temp := m_pPlanes[i].vNormal.y;
  55.         m_pPlanes[i].vNormal.y := m_pPlanes[i].vNormal.z;
  56.         m_pPlanes[i].vNormal.z := -temp;
  57.   end;
  58.  
  59.     // Seek to the position in the file that holds the visibility lump
  60.     seek(f, lumps[kVisData].offset);
  61.  
  62.     // Check if there is any visibility information first
  63.     if (lumps[kVisData].length>0) then begin
  64.  
  65.         // Read in the number of vectors and each vector's size
  66.     // also die beiden hier machn nen fehler
  67.         blockread(f,m_clusters[0].numOfClusters,     1*sizeof(integer));
  68.         blockread(f,m_clusters[0].bytesPerCluster, 1*sizeof(integer));
  69.  
  70.         // Allocate the memory for the cluster bitsets
  71. // hier - das weiss ich noch nit weil ich noch nich den teil mit bitsets übersetzt hab
  72.         int size = m_clusters.numOfClusters * m_clusters.bytesPerCluster;
  73.         m_clusters.pBitsets = new byte [size];
  74.  
  75.         // Read in the all the visibility bitsets for each cluster
  76.         blockread(f, m_clusters[0].pBitsets, 1*sizeof(byte) * size);
  77.  
  78.     // Otherwise, we don't have any visibility data (prevents a crash)
  79.     end ;//else
  80.         //m_clusters.pBitsets = NULL;
  81. /// new~~~~~~~~~~~~~~~~end
  82.  


also wer jetzt immer noch bock hat weiterzulesen...
Also ich bin mir ersma total unsicher ob das was ich übersetzt hab überhaupt richtig ist - hab nich ma n c compiler und da der code noch nich fertig übersetzt ist weiss ich auch nich ob ich das richtig übersetzt hab.
Also falls jemand beim drübergucken nen Fehler findet bitte sagt es mir ...

aber jetzt zu meinm wirklichn problem:
Code:
  1.  
  2.         // Read in the number of vectors and each vector's size
  3.     // also die beiden hier machn nen fehler
  4.         blockread(f,m_clusters[0].numOfClusters,     1*sizeof(integer));
  5.         blockread(f,m_clusters[0].bytesPerCluster, 1*sizeof(integer));
  6.  

Dieser Code läuft nicht und ich weiss nicht wie er korrekt lauten müsste.

Falls jemand tatsächlich so nen langen post freiwillig durchgelesen hat und mir dann auch noch helfen kann - schon ma thx im vorraus :)

ps: falls jemand weiss wo es schon ne fertige übersetzung vom gametutorials code gibt wäre ich sehr dankbar


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Apr 27, 2004 17:15 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Aug 28, 2002 19:27
Beiträge: 568
Wohnort: Chemnitz / Sachsen
erstens : die leafs sollten eigentlich in jeden sinnvollen bsp-loader sein.
zweitens : die vorgerechneten dinger sind wahrscheinlich PVS - Daten.

ich würde man auf zfx.com (oder org, net, de, oder so) schaun, da hat jemand einen bsp-loader in delphi für dx, das sollte nicht sooo schwierig sein.

bei den blockread muss ich mal fragen, was da fürn fehler kommt, es kann am datentyp liegen, oder an den dateien an sich.

_________________
Aktuelles Projekt :
www.PicPlace.de


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Apr 27, 2004 17:51 
Offline
DGL Member
Benutzeravatar

Registriert: Sa Dez 28, 2002 11:13
Beiträge: 2244
Hier http://harry.paintner.bei.t-online.de/Q3MapView/ gibt es auch einen recht fortgeschrittenen Q3Bsp Viewer mit Delphi Quelltext.
Was mich in deinem Quelltext wundert ist die Anpassung der Achsen. Bei Quake ist die Z Achse nach oben, aber das kann man doch eigentlich so lassen.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Apr 27, 2004 18:35 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Feb 24, 2003 18:19
Beiträge: 165
Wohnort: Cologne
zum blockread:

ich denke du hast beim Aufruf der Prozedur Reset auch den zweiten Parameter mit drin, denn sonst würde das andere auch nicht laufen ;) -> reset(f, 1);

Du könntest schonmal einige Sachen ausschließen wenn du ausserdem bei den fehlerhaften BlockRead's einen vierten Parameter mitangibst, sprich eine variable in die die tatsächliche Byte-Menge geschrieben wird. wenn der fehler dann immer noch auftritt liegt es schonmal nicht dadran, dass dein programm aus irgendwelchen gründen am datei-ende lesen will... ansonsten mal gucken ob auch mit dem array alles stimmt - ich weiss zwar net ob der dynamisch ist aber jedenfalls ist kein SetLength(m_Clusters, .... in deinem Code-Snippet :)

_________________
www.omfg.biz - aktuelles projekt


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Apr 29, 2004 15:56 
Offline
DGL Member

Registriert: Mi Mär 24, 2004 16:45
Beiträge: 29
ja das mit dem dynamischen array könnte sein...

dann danke erstmal und ich werde dass sobald ich zeit hab alles ausprobieren.

melde mich dann wieder um zu sagen obs geklappt hat.


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 5 Beiträge ] 
Foren-Übersicht » Programmierung » Allgemein


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 9 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.008s | 14 Queries | GZIP : On ]