Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Zitat
Meine Fehler bleiben aber bestehen. Der Else-Block wird weiterhin nicht ausgeführt und ich kann nicht z.B. 32*32 Chunks anlegen. Es geht im Augenblick nur 1*2 und wenn ich Glück hab auch mal 2*2.
Lass solche persönlichen Angriffe lieber bleiben, meine sind härter.
... und diese Signatur kürzer!
- übersichtlicher
- logischer
- verständlicher
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
#include "Section.h" inline int BlockWorld_Section::getBlockIndex(int x, int y, int z) { if(x >= Blocks_X) x = Blocks_X - 1; if(y >= Blocks_Y) y = Blocks_Y - 1; if(z >= Blocks_Z) z = Blocks_Z - 1; if(x < 0) x = 0; if(y < 0) y = 0; if(z < 0) z = 0; return x + y * Blocks_X + z * Blocks_X * Blocks_Y; } inline bool BlockWorld_Section::RandBlock(int x, int y, int z, int s) { return (x >= Blocks_X && s == 4) || //Links (y >= Blocks_Y && s == 0) || //Oben (z >= Blocks_Z && s == 2) || //Hinten (x < 0 && s == 5) || //Rechts (y < 0 && s == 1) || //Unten (z < 0 && s == 3); //Vorne } BlockWorld_Section::BlockWorld_Section() { Anzahl_Vertices = Blocks_X * Blocks_Y * Blocks_Z * 5; Anzahl_Indices = Blocks_X * Blocks_Y * Blocks_Z * 5; Block = new BlockWorld_Block[Blocks_X * Blocks_Y * Blocks_Z]; Section_Empty = false; } BlockWorld_Section::~BlockWorld_Section() { delete[] Block; } tbResult BlockWorld_Section::Init() { globalTime = 0; tbDirect3D& D3D = tbDirect3D::Instance(); BlockVertexBuffer.Init(2 * sizeof(BlockVertex), sizeof(BlockVertex), BlockVertex::VF, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT); BlockIndexBuffer.Init(2 * sizeof(WORD), sizeof(WORD), D3DFMT_INDEX16); Section_Empty == false; int i = 0; for(int x = 0; x < Blocks_X; x++) { for(int y = 0; y < Blocks_Y; y++) { for(int z = 0; z < Blocks_Z; z++) { if(y + SectionPosY < 128) i = tbIntRandom(0, 10000); if(y + SectionPosY == 128) i = tbIntRandom(0, 10); if(y + SectionPosY > 128) i = 0; if(i == 0) { Block[getBlockIndex(x, y, z)].ID = 0; } else { Block[getBlockIndex(x, y, z)].ID = 2; } } } } return TB_OK; } tbResult BlockWorld_Section::Exit() { BlockVertexBuffer.Exit(); BlockIndexBuffer.Exit(); return TB_OK; } tbResult BlockWorld_Section::Move(float Time) { globalTime += Time; return TB_OK; } tbResult BlockWorld_Section::Render(float Time) { if(!Section_Empty) { tbDirect3D& D3D = tbDirect3D::Instance(); D3D->SetStreamSource(0, BlockVertexBuffer.GetVB(), 0, sizeof(BlockVertex)); D3D->SetIndices(BlockIndexBuffer.GetIB()); D3D->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, Anzahl_Vertices, 0, Anzahl_Vertices / 2); } return TB_OK; } tbResult BlockWorld_Section::Update() { WORD Free_Vertex = 0; WORD Free_Index = 0; BlockVertex* TempVertex = new BlockVertex[Anzahl_Vertices]; WORD* TempIndex = new WORD[Anzahl_Vertices]; for(int x = 0; x < Blocks_X; x++) { for(int y = 0; y < Blocks_Y; y++) { for(int z = 0; z < Blocks_Z; z++) { if(Block[getBlockIndex(x, y, z)].ID != 0) { if(Block[getBlockIndex(x, y + 1, z)].ID == 0 || RandBlock(x, y + 1, z, 0)) //Oben { TempVertex[Free_Vertex].Position = tbVector3(SectionPosX + x, SectionPosY + y + 1, SectionPosZ + z); TempVertex[Free_Vertex + 1].Position = tbVector3(SectionPosX + x, SectionPosY + y + 1, SectionPosZ + z + 1); TempVertex[Free_Vertex + 2].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y + 1, SectionPosZ + z); TempVertex[Free_Vertex + 3].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y + 1, SectionPosZ + z + 1); TempIndex[Free_Index] = Free_Vertex; TempIndex[Free_Index + 1] = Free_Vertex + 1; TempIndex[Free_Index + 2] = Free_Vertex + 2; TempIndex[Free_Index + 3] = Free_Vertex + 2; TempIndex[Free_Index + 4] = Free_Vertex + 1; TempIndex[Free_Index + 5] = Free_Vertex + 3; TempVertex[Free_Vertex].Color = tbColor(255.0f, 255.0f, 0.0f); TempVertex[Free_Vertex + 1].Color = tbColor(255.0f, 255.0f, 0.0f); TempVertex[Free_Vertex + 2].Color = tbColor(255.0f, 255.0f, 0.0f); TempVertex[Free_Vertex + 3].Color = tbColor(255.0f, 255.0f, 0.0f); Free_Vertex += 4; Free_Index += 6; } if(Block[getBlockIndex(x, y - 1, z)].ID == 0 || RandBlock(x, y - 1, z, 1)) //Unten { TempVertex[Free_Vertex].Position = tbVector3(SectionPosX + x, SectionPosY + y, SectionPosZ + z); TempVertex[Free_Vertex + 1].Position = tbVector3(SectionPosX + x, SectionPosY + y, SectionPosZ + z + 1); TempVertex[Free_Vertex + 2].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y, SectionPosZ + z); TempVertex[Free_Vertex + 3].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y, SectionPosZ + z + 1); TempIndex[Free_Index] = Free_Vertex; TempIndex[Free_Index + 1] = Free_Vertex + 1; TempIndex[Free_Index + 2] = Free_Vertex + 2; TempIndex[Free_Index + 3] = Free_Vertex + 2; TempIndex[Free_Index + 4] = Free_Vertex + 1; TempIndex[Free_Index + 5] = Free_Vertex + 3; TempVertex[Free_Vertex].Color = tbColor(0.0f, 255.0f, 255.0f); TempVertex[Free_Vertex + 1].Color = tbColor(0.0f, 255.0f, 255.0f); TempVertex[Free_Vertex + 2].Color = tbColor(0.0f, 255.0f, 255.0f); TempVertex[Free_Vertex + 3].Color = tbColor(0.0f, 255.0f, 255.0f); Free_Vertex += 4; Free_Index += 6; } if(Block[getBlockIndex(x, y, z + 1)].ID == 0 || RandBlock(x, y, z + 1, 2)) //Hinten { TempVertex[Free_Vertex].Position = tbVector3(SectionPosX + x, SectionPosY + y, SectionPosZ + z + 1); TempVertex[Free_Vertex + 1].Position = tbVector3(SectionPosX + x, SectionPosY + y + 1, SectionPosZ + z + 1); TempVertex[Free_Vertex + 2].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y, SectionPosZ + z + 1); TempVertex[Free_Vertex + 3].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y + 1, SectionPosZ + z + 1); TempIndex[Free_Index] = Free_Vertex; TempIndex[Free_Index + 1] = Free_Vertex + 1; TempIndex[Free_Index + 2] = Free_Vertex + 2; TempIndex[Free_Index + 3] = Free_Vertex + 2; TempIndex[Free_Index + 4] = Free_Vertex + 1; TempIndex[Free_Index + 5] = Free_Vertex + 3; TempVertex[Free_Vertex].Color = tbColor(255.0f, 0.0f, 0.0f); TempVertex[Free_Vertex + 1].Color = tbColor(255.0f, 0.0f, 0.0f); TempVertex[Free_Vertex + 2].Color = tbColor(255.0f, 0.0f, 0.0f); TempVertex[Free_Vertex + 3].Color = tbColor(255.0f, 0.0f, 0.0f); Free_Vertex += 4; Free_Index += 6; } if(Block[getBlockIndex(x, y, z - 1)].ID == 0 || RandBlock(x, y, z - 1, 3)) //Vorne { TempVertex[Free_Vertex].Position = tbVector3(SectionPosX + x, SectionPosY + y, SectionPosZ + z); TempVertex[Free_Vertex + 1].Position = tbVector3(SectionPosX + x, SectionPosY + y + 1, SectionPosZ + z); TempVertex[Free_Vertex + 2].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y, SectionPosZ + z); TempVertex[Free_Vertex + 3].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y + 1, SectionPosZ + z); TempIndex[Free_Index] = Free_Vertex; TempIndex[Free_Index + 1] = Free_Vertex + 1; TempIndex[Free_Index + 2] = Free_Vertex + 2; TempIndex[Free_Index + 3] = Free_Vertex + 2; TempIndex[Free_Index + 4] = Free_Vertex + 1; TempIndex[Free_Index + 5] = Free_Vertex + 3; TempVertex[Free_Vertex].Color = tbColor(255.0f, 255.0f, 255.0f); TempVertex[Free_Vertex + 1].Color = tbColor(255.0f, 255.0f, 255.0f); TempVertex[Free_Vertex + 2].Color = tbColor(255.0f, 255.0f, 255.0f); TempVertex[Free_Vertex + 3].Color = tbColor(255.0f, 255.0f, 255.0f); Free_Vertex += 4; Free_Index += 6; } if(Block[getBlockIndex(x + 1, y, z)].ID == 0 || RandBlock(x + 1, y, z, 4)) //Links { TempVertex[Free_Vertex].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y, SectionPosZ + z); TempVertex[Free_Vertex + 1].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y + 1, SectionPosZ + z); TempVertex[Free_Vertex + 2].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y, SectionPosZ + z + 1); TempVertex[Free_Vertex + 3].Position = tbVector3(SectionPosX + x + 1, SectionPosY + y + 1, SectionPosZ + z + 1); TempIndex[Free_Index] = Free_Vertex; TempIndex[Free_Index + 1] = Free_Vertex + 1; TempIndex[Free_Index + 2] = Free_Vertex + 2; TempIndex[Free_Index + 3] = Free_Vertex + 2; TempIndex[Free_Index + 4] = Free_Vertex + 1; TempIndex[Free_Index + 5] = Free_Vertex + 3; TempVertex[Free_Vertex].Color = tbColor(255.0f, 0.0f, 255.0f); TempVertex[Free_Vertex + 1].Color = tbColor(255.0f, 0.0f, 255.0f); TempVertex[Free_Vertex + 2].Color = tbColor(255.0f, 0.0f, 255.0f); TempVertex[Free_Vertex + 3].Color = tbColor(255.0f, 0.0f, 255.0f); Free_Vertex += 4; Free_Index += 6; } if(Block[getBlockIndex(x - 1, y, z)].ID == 0 || RandBlock(x - 1, y, z, 5)) //Rechts { TempVertex[Free_Vertex].Position = tbVector3(SectionPosX + x, SectionPosY + y, SectionPosZ + z + 1); TempVertex[Free_Vertex + 1].Position = tbVector3(SectionPosX + x, SectionPosY + y + 1, SectionPosZ + z + 1); TempVertex[Free_Vertex + 2].Position = tbVector3(SectionPosX + x, SectionPosY + y, SectionPosZ + z); TempVertex[Free_Vertex + 3].Position = tbVector3(SectionPosX + x, SectionPosY + y + 1, SectionPosZ + z); TempIndex[Free_Index] = Free_Vertex; TempIndex[Free_Index + 1] = Free_Vertex + 1; TempIndex[Free_Index + 2] = Free_Vertex + 2; TempIndex[Free_Index + 3] = Free_Vertex + 2; TempIndex[Free_Index + 4] = Free_Vertex + 1; TempIndex[Free_Index + 5] = Free_Vertex + 3; TempVertex[Free_Vertex].Color = tbColor(0.0f, 0.0f, 255.0f); TempVertex[Free_Vertex + 1].Color = tbColor(0.0f, 0.0f, 255.0f); TempVertex[Free_Vertex + 2].Color = tbColor(0.0f, 0.0f, 255.0f); TempVertex[Free_Vertex + 3].Color = tbColor(0.0f, 0.0f, 255.0f); Free_Vertex += 4; Free_Index += 6; } } } } } if(Free_Vertex == 0 || Free_Index == 0) { Section_Empty == true; } else { BlockVertexBuffer.SetSize(Free_Vertex * sizeof(BlockVertex)); BlockIndexBuffer.SetSize(Free_Index * sizeof(WORD)); BlockVertexBuffer.SetVertices(0, Free_Vertex - 1, TempVertex); BlockIndexBuffer.SetIndices(0, Free_Index - 1, TempIndex); BlockVertexBuffer.Update(); BlockIndexBuffer.Update(); Section_Empty == false; } delete[] TempVertex; delete[] TempIndex; return TB_OK; } |
Lass solche persönlichen Angriffe lieber bleiben, meine sind härter.
... und diese Signatur kürzer!
- übersichtlicher
- logischer
- verständlicher
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »CeDoMain« (07.01.2014, 19:33)
Hast du denn schonmal den Debugger bemüht? Setzt doch einmal einen Breakpoint und step Zeile für Zeile durch.
Lass solche persönlichen Angriffe lieber bleiben, meine sind härter.
... und diese Signatur kürzer!
- übersichtlicher
- logischer
- verständlicher
Lass solche persönlichen Angriffe lieber bleiben, meine sind härter.
... und diese Signatur kürzer!
- übersichtlicher
- logischer
- verständlicher
Lass solche persönlichen Angriffe lieber bleiben, meine sind härter.
... und diese Signatur kürzer!
- übersichtlicher
- logischer
- verständlicher
Werbeanzeige