Guest User

Untitled

a guest
Dec 5th, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. MapParser.h:
  2.  
  3. #ifndef MAPPARSER_H
  4. #define MAPPARSER_H
  5.  
  6. #include "AtlasEngine.h"
  7. #include "DataStructures.h"
  8.  
  9. #include <string>
  10. #include <GL\freeglut\freeglut.h>
  11.  
  12. extern "C"
  13. {
  14.     #include "SOIL.h"
  15. }
  16.  
  17. struct RGB
  18. {
  19.     int R;
  20.     int G;
  21.     int B;
  22. };
  23.  
  24. class MapParser
  25. {
  26. public:
  27.     MapParser(std::string imagename);
  28.     ~MapParser();
  29.  
  30.     RGB MapParser::GetColour(int x, int y);
  31.  
  32.     void MapParser::DumpPixels(std::string outputfile);
  33.  
  34. private:
  35.     int _w;
  36.     int _h;
  37.     unsigned char* _image;
  38. };
  39.  
  40. #endif
  41.  
  42. mapparser.cpp:
  43.  
  44. #include "MapParser.h"
  45.  
  46. MapParser::MapParser(std::string imagename)
  47. {
  48.     _image = SOIL_load_image(imagename.c_str(), &_w, &_h, 0, SOIL_LOAD_RGB);
  49. }
  50.  
  51. MapParser::~MapParser()
  52. {
  53.  
  54. }
  55.  
  56. RGB MapParser::GetColour(int x, int y)
  57. {
  58.     RGB pixel;
  59.  
  60.     pixel.R = (int)_image[y * (_w * 3) + (x * 3) + 0];
  61.     pixel.G = (int)_image[y * (_w * 3) + (x * 3) + 1];
  62.     pixel.B = (int)_image[y * (_w * 3) + (x * 3) + 2];
  63.  
  64.     return pixel;
  65. }
  66.  
  67. std::string SelectOutlining(int value)
  68. {
  69.     if (value < 10)
  70.     {
  71.         return "   ";
  72.     }
  73.     else if (value < 100)
  74.     {
  75.         return "  ";
  76.     }
  77.     else
  78.     {
  79.         return " ";
  80.     }
  81. }
  82.  
  83. void MapParser::DumpPixels(std::string outputfile)
  84. {
  85.     std::ofstream filestream(outputfile);
  86.     for (int i = 0; i < _h; i++)
  87.     {
  88.         for (int j = 0; j < _w; j += 1)
  89.         {
  90.             RGB pixel = MapParser::GetColour(j, i);
  91.             filestream << pixel.R << SelectOutlining(pixel.R) << pixel.G << SelectOutlining(pixel.G) << pixel.B << SelectOutlining(pixel.B) << "|";
  92.         }
  93.         filestream << "\n";
  94.     }
  95.     filestream.close();
  96. }
  97.  
  98. main.h:
  99.  
  100. #ifndef MAIN_H
  101. #define MAIN_H
  102.  
  103. #include <string>
  104. #include <iostream>
  105. #include "MapParser.h"
  106.  
  107.  
  108. void main();
  109. #endif
  110.  
  111. main.cpp:
  112.  
  113. #include "Main.h"
  114.  
  115. void main()
  116. {
  117.    
  118. }
  119.  
  120. snippet of atlasengine.h van de class die de link errorgeeft:
  121. #ifndef ATLAS_H
  122. #define ATLAS_H
  123.  
  124. #include <list>
  125. #include <string>
  126. #include <map>
  127. #include <vector>
  128. #include <sstream>
  129.  
  130. extern "C" {
  131. #include "lua.h"
  132. #include "lauxlib.h"
  133. #include "lualib.h"
  134. }
  135. #include "LuaBridge.h"
  136. #include "LuaScript.h"
  137. ...
  138.  
  139. //Error class that is used to throw and display errors
  140. class AtlasError :
  141.     public std::runtime_error
  142. {
  143. public:
  144.     AtlasError(int type, std::string c_message);
  145.     ~AtlasError();
  146.  
  147.     //displays the error message
  148.     std::string ErrorMessage();
  149.  
  150. private:
  151.     //error type
  152.     int _type;
  153.     //custom message
  154.     std::string _custom;
  155. };
  156.  
  157. ..
  158. // AtlasErrorclass functions:
  159.  
  160. AtlasError::AtlasError(int type, std::string c_message)
  161.     :runtime_error("AtlasEngine Error")
  162. {
  163.     _type = type;
  164.     _custom = c_message;
  165. }
  166.  
  167. AtlasError::~AtlasError()
  168. {
  169.  
  170. }
  171.  
  172. std::string AtlasError::ErrorMessage()
  173. {
  174.     std::stringstream ss;
  175.     switch (_type)
  176.     {
  177.     case 0://file error
  178.         ss << "Could not parse lua file: " << _custom;
  179.         break;
  180.     case 1://key error when parsing
  181.         ss << "Missing key when parsing: '" << _custom << "'";
  182.         break;
  183.     case 2://parsing error with luaref
  184.         ss << "Parsing error because of luaref exception: " << _custom;
  185.         break;
  186.     case 3://invalid route
  187.         ss << "Invalid route with number: " << _custom;
  188.         break;
  189.     }
  190.  
  191.     return ss.str();
  192. }
Advertisement
Add Comment
Please, Sign In to add comment