Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MapParser.h:
- #ifndef MAPPARSER_H
- #define MAPPARSER_H
- #include "AtlasEngine.h"
- #include "DataStructures.h"
- #include <string>
- #include <GL\freeglut\freeglut.h>
- extern "C"
- {
- #include "SOIL.h"
- }
- struct RGB
- {
- int R;
- int G;
- int B;
- };
- class MapParser
- {
- public:
- MapParser(std::string imagename);
- ~MapParser();
- RGB MapParser::GetColour(int x, int y);
- void MapParser::DumpPixels(std::string outputfile);
- private:
- int _w;
- int _h;
- unsigned char* _image;
- };
- #endif
- mapparser.cpp:
- #include "MapParser.h"
- MapParser::MapParser(std::string imagename)
- {
- _image = SOIL_load_image(imagename.c_str(), &_w, &_h, 0, SOIL_LOAD_RGB);
- }
- MapParser::~MapParser()
- {
- }
- RGB MapParser::GetColour(int x, int y)
- {
- RGB pixel;
- pixel.R = (int)_image[y * (_w * 3) + (x * 3) + 0];
- pixel.G = (int)_image[y * (_w * 3) + (x * 3) + 1];
- pixel.B = (int)_image[y * (_w * 3) + (x * 3) + 2];
- return pixel;
- }
- std::string SelectOutlining(int value)
- {
- if (value < 10)
- {
- return " ";
- }
- else if (value < 100)
- {
- return " ";
- }
- else
- {
- return " ";
- }
- }
- void MapParser::DumpPixels(std::string outputfile)
- {
- std::ofstream filestream(outputfile);
- for (int i = 0; i < _h; i++)
- {
- for (int j = 0; j < _w; j += 1)
- {
- RGB pixel = MapParser::GetColour(j, i);
- filestream << pixel.R << SelectOutlining(pixel.R) << pixel.G << SelectOutlining(pixel.G) << pixel.B << SelectOutlining(pixel.B) << "|";
- }
- filestream << "\n";
- }
- filestream.close();
- }
- main.h:
- #ifndef MAIN_H
- #define MAIN_H
- #include <string>
- #include <iostream>
- #include "MapParser.h"
- void main();
- #endif
- main.cpp:
- #include "Main.h"
- void main()
- {
- }
- snippet of atlasengine.h van de class die de link errorgeeft:
- #ifndef ATLAS_H
- #define ATLAS_H
- #include <list>
- #include <string>
- #include <map>
- #include <vector>
- #include <sstream>
- extern "C" {
- #include "lua.h"
- #include "lauxlib.h"
- #include "lualib.h"
- }
- #include "LuaBridge.h"
- #include "LuaScript.h"
- ...
- //Error class that is used to throw and display errors
- class AtlasError :
- public std::runtime_error
- {
- public:
- AtlasError(int type, std::string c_message);
- ~AtlasError();
- //displays the error message
- std::string ErrorMessage();
- private:
- //error type
- int _type;
- //custom message
- std::string _custom;
- };
- ..
- // AtlasErrorclass functions:
- AtlasError::AtlasError(int type, std::string c_message)
- :runtime_error("AtlasEngine Error")
- {
- _type = type;
- _custom = c_message;
- }
- AtlasError::~AtlasError()
- {
- }
- std::string AtlasError::ErrorMessage()
- {
- std::stringstream ss;
- switch (_type)
- {
- case 0://file error
- ss << "Could not parse lua file: " << _custom;
- break;
- case 1://key error when parsing
- ss << "Missing key when parsing: '" << _custom << "'";
- break;
- case 2://parsing error with luaref
- ss << "Parsing error because of luaref exception: " << _custom;
- break;
- case 3://invalid route
- ss << "Invalid route with number: " << _custom;
- break;
- }
- return ss.str();
- }
Advertisement
Add Comment
Please, Sign In to add comment