Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Duke0200

Pages: [1]
1
General / Re: [XCode] Trying to use C++11 features
« on: May 28, 2016, 09:35:48 pm »
Actually I just got everything to work. Essentially what I did was make the Tiles const pointers

//Tile.cpp

Tile::Tile() : color(*new sf::Color(0,0,0)), canMoveIn(false), name("void") {}

Tile::Tile(sf::Color c, bool moveIn, std::string n) : color(c), name(n) {
    this->canMoveIn = moveIn;
}

const Tile *Tile::FLOOR = new Tile::Tile(sf::Color(0, 126, 0), true, "floor");
const Tile *Tile::WALL = new Tile::Tile(sf::Color(126, 126, 126), false, "wall");
const Tile *Tile::VOID = new Tile::Tile();
 

Made some functions constant, made the tiles 2d vector in dungeon store const Tile *, and change their functions to go with it.
//Dungeon.cpp
Dungeon::Dungeon(int width, int height) : width(width/Tile::TILE_SIZE), height(height/Tile::TILE_SIZE), tiles(this->height) {
    //I had a BAD_ACCESS error or something here so I did the following line of code.
    tiles = vector<vector<const Tile *>>(this->height);
    for (int y = 0; y < this->height; y++) {
        tiles.push_back(vector<const Tile *>(this->width));
        for(int x = 0; x < this->width; x++) {
            tiles[y].push_back(Tile::VOID);
        }
    }
    for (int x = 0; x < this->width; x++) {
        for (int y = 0; y < this->height; y++) {
            tiles[y][x] = rand() % 10 < 5 ? Tile::FLOOR : Tile::WALL;
        }
    }
}

const Tile * Dungeon::tile(int x, int y ) {
    if (x < 0 || x >= width || y < 0 || y >= height) {
        return Tile::VOID;
    }
    return tiles[y][x];
}

 

So I suppose thank you guys

2
General / Re: [XCode] Trying to use C++11 features
« on: May 28, 2016, 09:15:14 pm »
I use std::vector<std::vector<Tile>> to store the instances. Here's the code for the Dungeon constructor which stores the tiles

//Dungeon.cpp

Dungeon::Dungeon(int width, int height) : width(width/Tile::TILE_SIZE), height(height/Tile::TILE_SIZE), tiles(this->height) {
    for (int y = 0; y < this->height; y++) {
        tiles.push_back(vector<Tile>(this->width));
    }
    for (int x = 0; x < this->width; x++) {
        for (int y = 0; y < this->height; y++) {
            tiles[x][y] = rand() % 10 < 5 ? Tile::FLOOR : Tile::WALL;
        }
    }
}
 

Then the Dungeon.h file with the things that I think you want.

//Dungeon.h

class Dungeon {
private:
    //! Storage for tiles.
    std::vector<std::vector<Tile>> tiles;
   
    //! width of dungeon
    int width,
    //! height of dungeon
    height;
   
public:
    /**
     Creates a dungeon.
     
     @param width width that is divided by Tile TILE_SIZE
     @param height height that is divided by Tile TILE_SIZE
     */

     // TILE_SIZE is a static const defined in Tile.h that equals 8 at the moment
    Dungeon(int width, int height);
 

I also made a default constructor for Tile, but when I built it, it still failed. The default constructor for Tile is essentially Tile::VOID. Tile(sf::Color(0,0,0), false, "void")

Thank you for your help.

3
General / Re: [XCode] Trying to use C++11 features
« on: May 28, 2016, 08:22:20 pm »
Thing is - my Tile constructor matches up with the variables that I'm trying to make.

Here's the code for the constructors and variables

//Tile.h

#include <SFML/Graphics.hpp>
#include <string>

using namespace sf;

class Tile {
   
private:
    Tile(sf::Color c, bool moveIn, std::string n);
   
public:
   
    sf::Color color;
    bool canMoveIn;
    std::string name;
   
    const static Tile FLOOR, WALL, VOID;
};

 

//Tile.cpp

#include "Tile.h"

Tile::Tile(sf::Color c, bool moveIn, std::string n) : color(c), name(n) {
    canMoveIn = moveIn;
}

const Tile Tile::FLOOR(sf::Color(0, 126, 0), true, "floor");
const Tile Tile::WALL(sf::Color(126, 126, 126), false, "wall");
const Tile Tile::VOID(sf::Color(0,0,0), false, "void");
 

I'm sorry for turning this into a "Fix my Code" Situation I just have no idea how to fix this since, in my eyes, it's correct, or at least should be.

4
General / Re: [XCode] Trying to use C++11 features
« on: May 28, 2016, 08:12:34 pm »
I get a semantic error in a file called memory. It says

"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:1645:31: No matching constructor for initialization of 'Tile'"

Then the other two which I think are caused by it are one in the Linker

 "clang: error: linker command failed with exit code 1 (use -v to see invocation)"

and an error in the file lipo
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: /Users/trystan/Library/Developer/Xcode/DerivedData/TESTING-avrlnzthtflfbdcaogumbsfcstwk/Build/Intermediates/TESTING.build/Debug/TESTING.build/Objects-normal/i386/TESTING (No such file or directory)"

5
General / [XCode] Trying to use C++11 features
« on: May 28, 2016, 07:54:17 pm »
Basically my code is like this -
MyObject MyObject::Object(thingThatGoesIntoObject)
Which is a C++11 feature.

I am using XCode and everytime I build it, I get 3 errors, one being the cause which I know is that my compiler isn't setup to be C++11. I've tried to change the compiler to libc++ (the LLVM version) as well as the stdlibc++. I've also tried changing the C++ Dialect to C++11 and GNU++11 but nothing has been working. In the Build Options menu, my Compiler for the C-languages (C/C++/Obj-C) is Apple LLVM 6.1. I'm pretty sure I'm using XCode 6.4 apparently. Do I need to revert to a lower XCode version (I've been seeing XCode version 4.x and 5.x being used) or do I need to change the compiler information?

Thanks for the help.

Pages: [1]
anything