Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string.h>
  4. #include "cubemap.h"
  5.  
  6. #ifndef __CUBEMAP_H
  7. #define __CUBEMAP_H
  8. #include <zlib.h>
  9. typedef unsigned char uchar;
  10.  
  11. struct ogzHeader             // map file format header
  12. {
  13.     char magic[4];              // "OCTA"
  14.     int version;                // any >8bit quantity is little endian
  15.     int headersize;             // sizeof(header)
  16.     int worldsize;
  17.     int numents;
  18.     int numpvs;
  19.     int lightmaps;
  20.     int lightprecision, lighterror, lightlod;
  21.     uchar ambient;
  22.     uchar watercolour[3];
  23.     uchar blendmap;
  24.     uchar lerpangle, lerpsubdiv, lerpsubdivsize;
  25.     uchar bumperror;
  26.     uchar skylight[3];
  27.     uchar lavacolour[3];
  28.     uchar waterfallcolour[3];
  29.     uchar reserved[10];
  30.     char maptitle[128];
  31. };
  32.  
  33. class SauerMap
  34. {
  35.     public:
  36.         SauerMap(char *);
  37.         ogzHeader header;
  38.         void PrintMapData();
  39.  
  40.     private:
  41.         gzFile MapFile;
  42. };
  43. #endif
  44.  
  45. SauerMap::SauerMap(char *filename)
  46. {
  47.     MapFile = gzopen(filename, "r");
  48.     if(!MapFile)
  49.     {
  50.         std::cout << "ERROR: Failed to load \"" << filename << "\"" << std::endl;
  51.         return;
  52.     }
  53.     gzread(MapFile, &header, sizeof(ogzHeader));
  54. }
  55.  
  56. void SauerMap::PrintMapData()
  57. {
  58.     std::cout << "header " << header.magic << std::endl;
  59.     std::cout << "version " << header.version << std::endl;
  60.     std::cout << "headersize " << header.headersize << std::endl;
  61.     std::cout << "worldsize " << header.worldsize << std::endl;
  62.     std::cout << "numents " << header.numents << std::endl;
  63.     std::cout << "numpvs " << header.numpvs << std::endl;
  64.     std::cout << "lightmaps " << header.lightmaps << std::endl;
  65.     std::cout << "blendmap " << header.blendmap << std::endl;
  66.     std::cout << "lightprecision " << header.lightprecision << std::endl;
  67.     std::cout << "lighterror " << header.lighterror << std::endl;
  68.     std::cout << "lightlod " << header.lightlod << std::endl;
  69.  
  70.     std::cout << "ambient " << header.ambient << std::endl;
  71.     std::cout << "watercolour " << header.watercolour << std::endl;
  72.     std::cout << "lerpangle " << header.lerpangle << std::endl;
  73.     std::cout << "lerpsubdiv " << header.lerpsubdiv << std::endl;
  74.     std::cout << "lerpsubdivsize " << header.lerpsubdivsize << std::endl;
  75.     std::cout << "maptitle " << header.maptitle << std::endl;
  76. }
  77.  
  78. int main(int argc, char *argv[])
  79. {
  80.     if(argc > 1){
  81.         SauerMap ch(argv[1]);
  82.         if(strcmp(ch.header.magic,"OCTA"))
  83.         {
  84.             ch.PrintMapData();
  85.             std::cout<<"SUCCESS "<< argv[1] << " is a cube2 map " << std::endl;
  86.         }else std::cout<<"ERROR: "<< argv[1] <<" is not a valid Cube 2 map" << std::endl;
  87.     }else std::cout<<"ERROR: Usage c2mapreader.exe <mapname>"<<std::endl;
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement