示例#1
0
  Explode::Explode(Entity::GameObject* _p) : Component::abstract(_p), untilBOOM(-1), exploding(false) {
    attachCallback(Event::Info::Clock,
		   new Event::FixedCallback([this, _p] (Event::Data&) {
		       if (!untilBOOM) {
			 std::cout << "here is....." << std::endl;
			 delete _p;
			 std::cout << "..... the segfault?" << std::endl;
			 return ;
		       }
		       if (untilBOOM > 0)
			 untilBOOM -= 1;
		       if (!untilBOOM) {
			 EXPLODE(_p);
		       }
		     }));
    attachCallback(Event::Info::Explosion,
		   new Event::FixedCallback([this, _p] (Event::Data& e) {
		       Event::Type::Explosion* event =
			 reinterpret_cast<Event::Type::Explosion*>(&e);
		       double x;
		       double y;

		       if (exploding)
			 return ;
		       _p->getPosition(x, y);
		       if (Component::matchPosition(event->x, event->y, x, y)) {
			 EXPLODE(_p);
			 exploding = true;
			 untilBOOM = 0;
		       }
		     }));
  }
示例#2
0
    void hex_grid_t::load_from_file(std::string const& filepath)
    {
        SDL_RWops* io = SDL_RWFromFile(filepath.c_str(), "rb");

        if (!io)
        {
            EXPLODE("hex_grid_t::load_to_file()");  //todo: handle errors better
        }


        hxm_header_t header;
        size_t num_read = SDL_RWread(io, &header, sizeof (hxm_header_t), 1);
        ASSERT(num_read > 0, "Error reading file header");


        init(header.map_size, header.chunk_size);

        for_each_chunk([&](hex_grid_chunk_t& chunk)
        {
            SDL_RWread(io, &(chunk.size), sizeof(glm::uvec2), 1);

            for(auto& column : chunk.cells)
            {
                size_t num_r = SDL_RWread(io, column.data(), sizeof(hex_grid_cell_t), column.size());
                ASSERT(num_r == column.size(), "");
                LOG("read %d cells", num_r);
            }
        });


        SDL_RWclose(io);
    }
示例#3
0
 /**
  * Setup paths, insuring to include the CoreJS system/default path
  *
  * @param {vector<string>} reference to a vector that will contain the various paths
  */
 void Module::getPaths(vector<string> &usePaths)
 {
    
    // If our env var for default path location is not there, add it.
    if((Env::Get(string("FAE_MODULE_PATH"))).empty())
       Env::Set(string("FAE_MODULE_PATH"), string("/Users/weslcope/Desktop/Fae/modules/Core/test"));
      
    // Setup a vector to hold our paths (tmp)
    vector<string> paths;
    // Macro to split up our path env var and place each one in 
    // our tmp 'paths' vector.
    EXPLODE(paths, Env::Get("FAE_MODULE_PATH"), ":");
    
    // Add our paths to the referenced path vector passed to us.
    for(unsigned int i = 0; i < paths.size(); i++)
       usePaths.push_back(paths[i]);
    
    // See if we have a home directory set
    // If so, be sure to add our hidden folder to our paths.
    if((Env::Get(string("HOME"))).empty())
    {
       string userpath = Env::Get(string("HOME"));
       userpath += "/.fae-packages";
       usePaths.push_back(userpath);
    } 
 }
示例#4
0
    // https://wiki.libsdl.org/SDL_RWops?highlight=%28%5CbCategoryStruct%5Cb%29%7C%28CategoryIO%29
    // https://wiki.libsdl.org/SDL_RWwrite?highlight=%28%5CbCategoryIO%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruct%29
    void hex_grid_t::save_to_file(std::string const& filepath)
    {
        WARN_IF(!chunks.empty(), "Saving an empty map");

        SDL_RWops* io = SDL_RWFromFile(filepath.c_str(), "wb");

        if(!io)
        {
            EXPLODE("hex_grid_t::save_to_file() error");  //todo: handle errors better
        }

        hxm_header_t header;
        header.version = 0;
        header.chunk_size = chunk_size();
        header.map_size = size;

        size_t num_written = SDL_RWwrite(io, (void*)&header, sizeof(hxm_header_t), 1);

        if(num_written != 1)
        {
            EXPLODE("error writing hxm header");
        }


        for_each_chunk([&](hex_grid_chunk_t const& chunk)
        {
            SDL_RWwrite(io, (void*)&chunk.size, sizeof(glm::uvec2), 1);
            for(auto column : chunk.cells)
            {
                size_t num_w = SDL_RWwrite(io, column.data(), sizeof(hex_grid_cell_t), column.size());
                ASSERT(num_w == column.size(), "chunk save error");
                LOG("wrote %d cells", num_w);
            }
        });
        

        SDL_RWclose(io);
    }
示例#5
0
    void asdf_multiplat_t::init_SDL() {
        //init video subsystem
        if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
            EXPLODE("Could not initialize SDL: %s.", SDL_GetError());
            running = false;
            return;
        }

        //set GL version to 3.3
        //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
        //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); //set 24 bit depth buffer
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //turn on double buffering

        //SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
        //SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);


        //create window
        uint32_t flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;

        if (settings.fullscreen)
            flags |= SDL_WINDOW_FULLSCREEN;
        if (settings.borderless)
            flags |= SDL_WINDOW_BORDERLESS;

        main_window = SDL_CreateWindow(WINDOW_TITLE.c_str(),
                                        SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                        settings.resolution_width, settings.resolution_height,
                                        flags);
        checkSDLError(__LINE__);
        ASSERT(main_window != 0, "Unable to create window");

        //create OpenGL context
        gl_context = SDL_GL_CreateContext(main_window);
        checkSDLError(__LINE__);

        ASSERT(gl_context != nullptr, "Unable to create OpenGL Context");

        prev_ticks = SDL_GetTicks();
        //SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);

        SDL_GL_SetSwapInterval(1);
        LOG("SDL Initialized");
    }
示例#6
0
    void create_dir(std::string const& path)
    {
        ASSERT(!is_directory(path), "Directory already exists at %s", path.c_str());
        ASSERT(!is_file(path), "Cannot create directory, File already exists at %s", path.c_str());


#ifdef MSVC
        ASSERT(path.length() < 248, "Windows CreateDirectory() does not support paths longer than 248 chars. Tell a programmer to use the Unicode version");
        bool status = CreateDirectory(path.c_str());

        /*
        if(status == ERROR_ALREADY_EXISTS)
            todo: throw exception?
        else if(status == ERROR_PATH_NOT_FOUND)
            todo: throw exception?
        */
#else
        EXPLODE("todo: posix version of create_dir()");
#endif
    }
示例#7
0
 void hex_grid_t::shrink(glm::ivec2 shrink_amount, resize_x_direction_e, resize_y_direction_e)
 {
     ASSERT(shrink_amount.x >=0 && shrink_amount.y >= 0, "");
     EXPLODE("todo: hex_grid_t::shrink()");
 }