浏览代码

LoaderTR2 supports Animated Textuers

Thomas Buck 10 年前
父节点
当前提交
1c6648ddbf
共有 5 个文件被更改,包括 245 次插入13 次删除
  1. 4
    0
      ChangeLog.md
  2. 6
    0
      include/TextureManager.h
  3. 31
    0
      src/TextureManager.cpp
  4. 160
    7
      src/UI.cpp
  5. 44
    6
      src/loader/LoaderTR2.cpp

+ 4
- 0
ChangeLog.md 查看文件

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20141129 ]
6
+    * LoaderTR2 now supports loading animated textiles
7
+
5
     [ 20141128 ]
8
     [ 20141128 ]
6
     * Added FPS Histogram Debug UI
9
     * Added FPS Histogram Debug UI
10
+    * Added RunTime Settings Debug UI
7
 
11
 
8
     [ 20141127 ]
12
     [ 20141127 ]
9
     * Started work on loading the object texture mapping, with debug UI
13
     * Started work on loading the object texture mapping, with debug UI

+ 6
- 0
include/TextureManager.h 查看文件

90
     int numTiles();
90
     int numTiles();
91
     TextureTile& getTile(int index);
91
     TextureTile& getTile(int index);
92
 
92
 
93
+    void addAnimatedTile(int index, int tile);
94
+    int numAnimatedTiles();
95
+    int getFirstTileAnimation(int index);
96
+    int getNextTileAnimation(int tile);
97
+
93
   private:
98
   private:
94
     std::vector<unsigned int>& getIds(TextureStorage s);
99
     std::vector<unsigned int>& getIds(TextureStorage s);
95
 
100
 
101
     std::vector<unsigned int> mTextureIdsSystem;
106
     std::vector<unsigned int> mTextureIdsSystem;
102
 
107
 
103
     std::vector<TextureTile*> tiles;
108
     std::vector<TextureTile*> tiles;
109
+    std::vector<std::vector<int>> animations;
104
 };
110
 };
105
 
111
 
106
 TextureManager& getTextureManager();
112
 TextureManager& getTextureManager();

+ 31
- 0
src/TextureManager.cpp 查看文件

164
     return *tiles.at(index);
164
     return *tiles.at(index);
165
 }
165
 }
166
 
166
 
167
+void TextureManager::addAnimatedTile(int index, int tile) {
168
+    while (index >= animations.size())
169
+        animations.push_back(std::vector<int>());
170
+
171
+    animations.at(index).push_back(tile);
172
+}
173
+
174
+int TextureManager::numAnimatedTiles() {
175
+    return animations.size();
176
+}
177
+
178
+int TextureManager::getFirstTileAnimation(int index) {
179
+    assert(index < animations.size());
180
+    assert(animations.at(index).size() > 0);
181
+    return animations.at(index).at(0);
182
+}
183
+
184
+int TextureManager::getNextTileAnimation(int tile) {
185
+    for (int a = 0; a < animations.size(); a++) {
186
+        for (int i = 0; i < animations.at(a).size(); i++) {
187
+            if (animations.at(a).at(i) == tile) {
188
+                if (i < (animations.at(a).size() - 1))
189
+                    return animations.at(a).at(i + 1);
190
+                else
191
+                    return animations.at(a).at(0);
192
+            }
193
+        }
194
+    }
195
+    return -1;
196
+}
197
+
167
 std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
198
 std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
168
     if (s == TextureStorage::GAME)
199
     if (s == TextureStorage::GAME)
169
         return mTextureIdsGame;
200
         return mTextureIdsGame;

+ 160
- 7
src/UI.cpp 查看文件

6
  */
6
  */
7
 
7
 
8
 #include <algorithm>
8
 #include <algorithm>
9
+#include <cstring>
9
 
10
 
10
 #include "global.h"
11
 #include "global.h"
11
 #include "Console.h"
12
 #include "Console.h"
186
     Console::display();
187
     Console::display();
187
 
188
 
188
     if (ImGui::Begin("Engine")) {
189
     if (ImGui::Begin("Engine")) {
189
-        if (ImGui::CollapsingHeader("RunTime Info")) {
190
+        if (ImGui::CollapsingHeader("Engine Info")) {
190
             ImGui::Text("Uptime: %lums", systemTimerGet());
191
             ImGui::Text("Uptime: %lums", systemTimerGet());
191
             ImGui::Text("Frames per Second: %luFPS", getRunTime().getFPS());
192
             ImGui::Text("Frames per Second: %luFPS", getRunTime().getFPS());
192
             if (getRunTime().getHistoryFPS().size() > 1) {
193
             if (getRunTime().getHistoryFPS().size() > 1) {
193
                 static bool scroll = true;
194
                 static bool scroll = true;
194
                 if (scroll) {
195
                 if (scroll) {
195
                     int offset = getRunTime().getHistoryFPS().size() - 1;
196
                     int offset = getRunTime().getHistoryFPS().size() - 1;
196
-                    if (offset > 15)
197
-                        offset = 15;
197
+                    if (offset > 10)
198
+                        offset = 10;
198
                     ImGui::PlotLines("FPS", &getRunTime().getHistoryFPS()[1],
199
                     ImGui::PlotLines("FPS", &getRunTime().getHistoryFPS()[1],
199
                             getRunTime().getHistoryFPS().size() - 1,
200
                             getRunTime().getHistoryFPS().size() - 1,
200
                             getRunTime().getHistoryFPS().size() - offset - 1);
201
                             getRunTime().getHistoryFPS().size() - offset - 1);
207
             }
208
             }
208
         }
209
         }
209
 
210
 
211
+        if (ImGui::CollapsingHeader("RunTime Settings")) {
212
+            bool showFPS = getRunTime().getShowFPS();
213
+            if (ImGui::Checkbox("Show FPS##runtime", &showFPS)) {
214
+                getRunTime().setShowFPS(showFPS);
215
+            }
216
+            ImGui::SameLine();
217
+            bool running = getRunTime().isRunning();
218
+            if (ImGui::Checkbox("Running (!)##runtime", &running)) {
219
+                getRunTime().setRunning(running);
220
+            }
221
+            ImGui::SameLine();
222
+            bool sound = getSound().getEnabled();
223
+            if (ImGui::Checkbox("Sound##runtime", &sound)) {
224
+                getSound().setEnabled(sound);
225
+            }
226
+            ImGui::SameLine();
227
+            bool fullscreen = getWindow().getFullscreen();
228
+            if (ImGui::Checkbox("Fullscreen##runtime", &fullscreen)) {
229
+                getWindow().setFullscreen(fullscreen);
230
+            }
231
+
232
+            float vol = getSound().getVolume();
233
+            if (ImGui::InputFloat("Volume##runtime", &vol, 0.0f, 0.0f, 3, ImGuiInputTextFlags_EnterReturnsTrue)) {
234
+                if (vol < 0.0f)
235
+                    vol = 0.0f;
236
+                if (vol > 1.0f)
237
+                    vol = 1.0f;
238
+                getSound().setVolume(vol);
239
+            }
240
+
241
+            int w = getWindow().getWidth();
242
+            if (ImGui::InputInt("Width##runtime", &w, 10, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
243
+                if (w < 1)
244
+                    w = 1;
245
+                getWindow().setSize(w, getWindow().getHeight());
246
+            }
247
+            int h = getWindow().getHeight();
248
+            if (ImGui::InputInt("Height##runtime", &h, 10, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
249
+                if (h < 1)
250
+                    h = 1;
251
+                getWindow().setSize(getWindow().getWidth(), h);
252
+            }
253
+
254
+            static int fr = 0;
255
+            char buff[1024];
256
+            strncpy(buff, getRunTime().getBaseDir().c_str(), 1024);
257
+            if (ImGui::InputText("BaseDir##runtime", buff, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
258
+                getRunTime().setBaseDir(buff);
259
+                fr = getRunTime().getFPS();
260
+            }
261
+            if (fr > 0) {
262
+                ImGui::SameLine();
263
+                ImGui::Text("Done!##runtime1");
264
+                fr--;
265
+            }
266
+
267
+            static int fr2 = 0;
268
+            char buff2[1024];
269
+            strncpy(buff2, getRunTime().getPakDir().c_str(), 1024);
270
+            if (ImGui::InputText("PakDir##runtime", buff2, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
271
+                getRunTime().setPakDir(buff2);
272
+                fr2 = getRunTime().getFPS();
273
+            }
274
+            if (fr2 > 0) {
275
+                ImGui::SameLine();
276
+                ImGui::Text("Done!##runtime2");
277
+                fr2--;
278
+            }
279
+
280
+            static int fr3 = 0;
281
+            char buff3[1024];
282
+            strncpy(buff3, getRunTime().getAudioDir().c_str(), 1024);
283
+            if (ImGui::InputText("AudioDir##runtime", buff3, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
284
+                getRunTime().setAudioDir(buff3);
285
+                fr3 = getRunTime().getFPS();
286
+            }
287
+            if (fr3 > 0) {
288
+                ImGui::SameLine();
289
+                ImGui::Text("Done!##runtime3");
290
+                fr3--;
291
+            }
292
+
293
+            static int fr4 = 0;
294
+            char buff4[1024];
295
+            strncpy(buff4, getRunTime().getDataDir().c_str(), 1024);
296
+            if (ImGui::InputText("DataDir##runtime", buff4, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
297
+                getRunTime().setDataDir(buff4);
298
+                fr4 = getRunTime().getFPS();
299
+            }
300
+            if (fr4 > 0) {
301
+                ImGui::SameLine();
302
+                ImGui::Text("Done!##runtime4");
303
+                fr4--;
304
+            }
305
+        }
306
+
210
         static bool visibleTex = false;
307
         static bool visibleTex = false;
211
         static bool visibleTile = false;
308
         static bool visibleTile = false;
309
+        static bool visibleAnim = false;
212
         if (ImGui::CollapsingHeader("Texture Viewer")) {
310
         if (ImGui::CollapsingHeader("Texture Viewer")) {
213
             static bool game = getGame().isLoaded();
311
             static bool game = getGame().isLoaded();
214
             static int index = 0;
312
             static int index = 0;
245
             if (ImGui::Button("Show##texshow")) {
343
             if (ImGui::Button("Show##texshow")) {
246
                 visibleTex = true;
344
                 visibleTex = true;
247
                 visibleTile = false;
345
                 visibleTile = false;
346
+                visibleAnim = false;
248
             }
347
             }
249
             ImGui::SameLine();
348
             ImGui::SameLine();
250
             if (ImGui::Button("Clear##texclear")) {
349
             if (ImGui::Button("Clear##texclear")) {
285
                 if (ImGui::Button("Show##tileshow")) {
384
                 if (ImGui::Button("Show##tileshow")) {
286
                     visibleTile = true;
385
                     visibleTile = true;
287
                     visibleTex = false;
386
                     visibleTex = false;
387
+                    visibleAnim = false;
288
                 }
388
                 }
289
                 ImGui::SameLine();
389
                 ImGui::SameLine();
290
                 if (ImGui::Button("Clear##tileclear")) {
390
                 if (ImGui::Button("Clear##tileclear")) {
301
                             (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
401
                             (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
302
                 }
402
                 }
303
             } else {
403
             } else {
304
-                ImGui::Text("Please load a level!");
404
+                ImGui::Text("Please load a level using the new loader!");
405
+            }
406
+        }
407
+
408
+        if (ImGui::CollapsingHeader("Animated Textile Viewer")) {
409
+            if (getTextureManager().numAnimatedTiles() > 0) {
410
+                static int index = 0;
411
+                static int tile = getTextureManager().getFirstTileAnimation(index);
412
+                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
413
+                if (ImGui::SliderInt("##animslide", &index, 0, getTextureManager().numAnimatedTiles() - 1)) {
414
+                    tile = getTextureManager().getFirstTileAnimation(index);
415
+                }
416
+                ImGui::PopItemWidth();
417
+                ImGui::SameLine();
418
+                if (ImGui::Button("+##animplus", ImVec2(0, 0), true)) {
419
+                    if (index < (getTextureManager().numAnimatedTiles() - 1))
420
+                        index++;
421
+                    else
422
+                        index = 0;
423
+                    tile = getTextureManager().getFirstTileAnimation(index);
424
+                }
425
+                ImGui::SameLine();
426
+                if (ImGui::Button("-##animminus", ImVec2(0, 0), true)) {
427
+                    if (index > 0)
428
+                        index--;
429
+                    else
430
+                        index = getTextureManager().numAnimatedTiles() - 1;
431
+                    tile = getTextureManager().getFirstTileAnimation(index);
432
+                }
433
+                ImGui::SameLine();
434
+                static int fr = 0;
435
+                if (ImGui::Button("Show##animshow")) {
436
+                    visibleAnim = true;
437
+                    visibleTex = false;
438
+                    visibleTile = false;
439
+                }
440
+                ImGui::SameLine();
441
+                if (ImGui::Button("Clear##animclear")) {
442
+                    getRender().debugDisplayTextile();
443
+                    visibleAnim = false;
444
+                }
445
+                if (visibleAnim) {
446
+                    if (fr > 0) {
447
+                        fr--;
448
+                    } else {
449
+                        getRender().debugDisplayTextile(tile,
450
+                                ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),
451
+                                ImGui::GetWindowPos().y,
452
+                                (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
453
+                        fr = getRunTime().getFPS() / 2;
454
+                        tile = getTextureManager().getNextTileAnimation(tile);
455
+                    }
456
+                    ImGui::Text("Current Tile: %d", tile);
457
+                }
458
+            } else {
459
+                ImGui::Text("Please load a level with animated textures!");
305
             }
460
             }
306
         }
461
         }
307
 
462
 
339
             }
494
             }
340
         }
495
         }
341
 
496
 
342
-        /*
343
-        if (ImGui::CollapsingHeader("UI Help")) {
497
+        if (ImGui::CollapsingHeader("ImGui UI Help")) {
344
             ImGui::ShowUserGuide();
498
             ImGui::ShowUserGuide();
345
         }
499
         }
346
-        */
347
     }
500
     }
348
     ImGui::End();
501
     ImGui::End();
349
 
502
 

+ 44
- 6
src/loader/LoaderTR2.cpp 查看文件

276
 
276
 
277
         // TODO store floor data somewhere
277
         // TODO store floor data somewhere
278
     }
278
     }
279
+
280
+    if (numFloorData > 0)
281
+        getLog() << "LoaderTR2: Found " << numFloorData << " words FloorData, unimplemented!" << Log::endl;
279
 }
282
 }
280
 
283
 
281
 void LoaderTR2::loadMeshes() {
284
 void LoaderTR2::loadMeshes() {
292
     uint32_t numMeshPointers = file.readU32();
295
     uint32_t numMeshPointers = file.readU32();
293
 
296
 
294
     if ((numMeshData == 0) || (numMeshPointers == 0)) {
297
     if ((numMeshData == 0) || (numMeshPointers == 0)) {
295
-        //! \fixme debug level regulating output?
296
         getLog() << "LoaderTR2: No mesh data found!" << Log::endl;
298
         getLog() << "LoaderTR2: No mesh data found!" << Log::endl;
297
         return;
299
         return;
298
     }
300
     }
438
 
440
 
439
         // TODO store static meshes somewhere
441
         // TODO store static meshes somewhere
440
     }
442
     }
443
+
444
+    if (numStaticMeshes > 0)
445
+        getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes, unimplemented!" << Log::endl;
441
 }
446
 }
442
 
447
 
443
 void LoaderTR2::loadTextures() {
448
 void LoaderTR2::loadTextures() {
515
 
520
 
516
         // TODO store cameras somewhere
521
         // TODO store cameras somewhere
517
     }
522
     }
523
+
524
+    if (numCameras > 0)
525
+        getLog() << "LoaderTR2: Found " << numCameras << " Cameras, unimplemented!" << Log::endl;
518
 }
526
 }
519
 
527
 
520
 void LoaderTR2::loadSoundSources() {
528
 void LoaderTR2::loadSoundSources() {
533
 
541
 
534
         // TODO store sound sources somewhere
542
         // TODO store sound sources somewhere
535
     }
543
     }
544
+
545
+    if (numSoundSources > 0)
546
+        getLog() << "LoaderTR2: Found " << numSoundSources << " SoundSources, unimplemented!" << Log::endl;
536
 }
547
 }
537
 
548
 
538
 void LoaderTR2::loadBoxesOverlapsZones() {
549
 void LoaderTR2::loadBoxesOverlapsZones() {
575
 }
586
 }
576
 
587
 
577
 void LoaderTR2::loadAnimatedTextures() {
588
 void LoaderTR2::loadAnimatedTextures() {
578
-    uint32_t numAnimatedTextures = file.readU32();
589
+    uint32_t numWords = file.readU32() - 1;
590
+    uint16_t numAnimatedTextures = file.readU16();
579
     std::vector<uint16_t> animatedTextures;
591
     std::vector<uint16_t> animatedTextures;
580
-    for (unsigned int a = 0; a < numAnimatedTextures; a++) {
592
+    for (unsigned int a = 0; a < numWords; a++) {
581
         animatedTextures.push_back(file.readU16());
593
         animatedTextures.push_back(file.readU16());
582
     }
594
     }
583
 
595
 
584
-    // TODO store animated textures somewhere. Format?
596
+    int pos = 0;
597
+    for (unsigned int a = 0; a < numAnimatedTextures; a++) {
598
+        int count = animatedTextures.at(pos) + 1;
599
+        if ((pos + count) >= numWords) {
600
+            getLog() << "LoaderTR2: Invalid AnimatedTextures ("
601
+                << pos + count << " >= " << numWords << ")!" << Log::endl;
602
+            return;
603
+        }
604
+
605
+        for (int i = 0; i < count; i++) {
606
+            getTextureManager().addAnimatedTile(a, animatedTextures.at(pos + i + 1));
607
+        }
608
+
609
+        pos += count + 1;
610
+    }
611
+
612
+    if (pos != numWords)
613
+        getLog() << "LoaderTR2: Extra bytes at end of AnimatedTextures?" << Log::endl;
585
 }
614
 }
586
 
615
 
587
 void LoaderTR2::loadItems() {
616
 void LoaderTR2::loadItems() {
605
 
634
 
606
         // TODO store items somewhere
635
         // TODO store items somewhere
607
     }
636
     }
637
+
638
+    if (numItems > 0)
639
+        getLog() << "LoaderTR2: Found " << numItems << " Items, unimplemented!" << Log::endl;
608
 }
640
 }
609
 
641
 
610
 void LoaderTR2::loadCinematicFrames() {
642
 void LoaderTR2::loadCinematicFrames() {
623
     }
655
     }
624
 
656
 
625
     if (numCinematicFrames > 0)
657
     if (numCinematicFrames > 0)
626
-        getLog() << "LoaderTR2: Found CinematicFrames, not yet implemented!" << Log::endl;
658
+        getLog() << "LoaderTR2: Found " << numCinematicFrames
659
+            << " CinematicFrames, not yet implemented!" << Log::endl;
627
 }
660
 }
628
 
661
 
629
 void LoaderTR2::loadDemoData() {
662
 void LoaderTR2::loadDemoData() {
633
 
666
 
634
     // TODO store demo data somewhere, find out meaning
667
     // TODO store demo data somewhere, find out meaning
635
     if (numDemoData > 0)
668
     if (numDemoData > 0)
636
-        getLog() << "LoaderTR2: Found DemoData, not yet implemented!" << Log::endl;
669
+        getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, not yet implemented!" << Log::endl;
637
 }
670
 }
638
 
671
 
639
 void LoaderTR2::loadSoundMap() {
672
 void LoaderTR2::loadSoundMap() {
661
 
694
 
662
         // TODO store sound details somewhere
695
         // TODO store sound details somewhere
663
     }
696
     }
697
+
698
+    if (numSoundDetails > 0)
699
+        getLog() << "LoaderTR2: Found " << numSoundDetails << " SoundDetails, unimplemented!" << Log::endl;
664
 }
700
 }
665
 
701
 
666
 void LoaderTR2::loadSampleIndices() {
702
 void LoaderTR2::loadSampleIndices() {
671
     }
707
     }
672
 
708
 
673
     // TODO store sample indices somewhere
709
     // TODO store sample indices somewhere
710
+    if (numSampleIndices > 0)
711
+        getLog() << "LoaderTR2: Found " << numSampleIndices << " SampleIndices, unimplemented!" << Log::endl;
674
 }
712
 }
675
 
713
 
676
 void LoaderTR2::loadExternalSoundFile(std::string f) {
714
 void LoaderTR2::loadExternalSoundFile(std::string f) {

正在加载...
取消
保存