Exemple #1
0
 bit_string bit_string::operator~() const {
     if (!empty()) {
         bit_string tmp = *this;
         for (iterator it = tmp.begin(); it != tmp.end(); ++it)
             *it = ~(*it);
         tmp.unusebits(tmp.unusebits());
         return tmp;
     }
     return bit_string();
 }
Exemple #2
0
 bit_string operator^(const bit_string& ls, const bit_string& rs) {
     if (ls.size() || rs.size()) {
         bit_string tmp;
         const bit_string& maxsb = (ls.size() > rs.size()) ? ls : rs;
         const bit_string& minsb = (ls.size() > rs.size()) ? rs : ls;
         tmp.assign(maxsb.begin(), maxsb.end());
         for (std::size_t i = 0; i < minsb.size(); ++i) {
             tmp[i] ^= minsb[i];
         }
         if (maxsb.size() == minsb.size())
             tmp.unusebits(std::min(minsb.unusebits(), maxsb.unusebits()));
         else
             tmp.unusebits(maxsb.unusebits());
         return tmp;
     }
     return bit_string();
 }
Exemple #3
0
 void list_notes(player *p,char *str)
 {
   int num;
   note *scan;
   char *oldstack;

   oldstack=stack;

   num=atoi(str);
   if (num<0 || num>=NOTE_HASH_SIZE) {
     tell_player(p,"Number not in range.\n");
     return;
   }

   strcpy(stack,"Notes:\n");
   stack=strchr(stack,0);
   for(scan=n_hash[num];scan;scan=scan->hash_next) {
     if (scan->flags&NEWS_ARTICLE) 
       sprintf(stack,"[%d] %s + %s",scan->id,
	       scan->name,scan->header);
     else 
       sprintf(stack,"[%d] %s - %s",scan->id,scan->name,
	       bit_string(scan->flags));
     stack=strchr(stack,0);
     if (scan->flags&NOT_READY) {
       strcpy(stack,"(DEFUNCT)\n");
       stack=strchr(stack,0);
     }
     else *stack++='\n';
   }
   strcpy(stack," --\n");
   stack=strchr(stack,0);
   stack++;
   tell_player(p,oldstack);
   stack=oldstack;
 }
    void sprite_sheet::incremental_load(const application_folder & in_application_folder)
    {
        switch(internal_status)
        {
            case sprite_sheet_status::ready:
            case sprite_sheet_status::failed:
                break;
            case sprite_sheet_status::waiting_to_load:
            {
                if(internal_loaded_file_data.status() == file_data_status::waiting_to_load)
                {
                    internal_status = sprite_sheet_status::loading;
                    internal_loaded_file_data.load(in_application_folder, internal_sheet_file_path.c_str());
                }
                break;
            }
            case sprite_sheet_status::loading:
            {
                if(internal_loaded_file_data.status() == file_data_status::loading)
                {
                }
                else if(internal_loaded_file_data.status() == file_data_status::ready)
                {
                    auto file_data = internal_loaded_file_data.data();
                    atl::input_bit_string_type bit_string(file_data.data(), file_data.data() + file_data.size());
                    
                    // Load frames:
                    glActiveTexture(GL_TEXTURE0);

                    uint32_t numSheets;
                    atl::bit_string_read_chunked_integer<uint32_t>(bit_string, numSheets, 3);
                    uint32_t totalSprites;
                    atl::bit_string_read_chunked_integer<uint32_t>(bit_string, totalSprites, 7);

                    sprites.resize(totalSprites);
                    textures.resize(numSheets);

                    for(auto & sheetId : textures)
                    {
                        // give the sheet a valid opengl texture ID
                        glGenTextures(1, &sheetId);
                        check_gl_errors();

                        uint32_t fontSheetWidthPower, fontSheetHeightPower;
                        atl::bit_string_read_ranged_integer<uint32_t>(bit_string, fontSheetWidthPower, 0, 12);
                        atl::bit_string_read_ranged_integer<uint32_t>(bit_string, fontSheetHeightPower, 0, 12);
                        uint32_t sheetWidth = 1 << fontSheetWidthPower;
                        uint32_t sheetHeight = 1 << fontSheetHeightPower;

                        atl::size2f sheetSize(sheetWidth, sheetHeight);

                        uint32_t sheetSprites;
                        atl::bit_string_read_ranged_integer<uint32_t>(bit_string, sheetSprites, 0, totalSprites);
                        while(sheetSprites-- > 0)
                        {
                            // Deserialize the frame index:
                            uint32_t spriteIndex;
                            atl::bit_string_read_ranged_integer<uint32_t>(bit_string, spriteIndex, 0, totalSprites - 1);

                            // Deserialize the texture coordinates:
                            atl::box2f l_texCoords;
                            {
                                uint32_t l_texT, l_texR, l_texB, l_texL;
                                atl::bit_string_read_ranged_integer<uint32_t>(bit_string, l_texT, 0, sheetHeight);
                                atl::bit_string_read_ranged_integer<uint32_t>(bit_string, l_texR, 0, sheetWidth);
                                atl::bit_string_read_ranged_integer<uint32_t>(bit_string, l_texB, 0, sheetHeight);
                                atl::bit_string_read_ranged_integer<uint32_t>(bit_string, l_texL, 0, sheetWidth);

                                if(l_texR - l_texL == 1)
                                {
                                    l_texCoords.l = l_texCoords.r = (float(l_texL) + 0.5f) / float(sheetWidth);
                                }
                                else
                                {
                                    l_texCoords.l = (float(l_texL)) / float(sheetWidth);
                                    l_texCoords.r = (float(l_texR)) / float(sheetWidth);
                                }

                                if(l_texB - l_texT == 1)
                                {
                                    l_texCoords.t = l_texCoords.b = (float(l_texT) + 0.5f) / float(sheetHeight);
                                }
                                else
                                {
                                    l_texCoords.t = (float(l_texT)) / float(sheetHeight);
                                    l_texCoords.b = (float(l_texB)) / float(sheetHeight);
                                }
                            }

                            // Deserialize the drawn area:
                            atl::box2f l_area;
                            atl::bit_string_read_values(bit_string, l_area.t, l_area.r, l_area.b, l_area.l);

                            sprites[spriteIndex].set(sheetId, l_texCoords, l_area);
                        }

                        // Decode PNG data and upload to card:
                        glBindTexture(GL_TEXTURE_2D, sheetId);

                        int32_t numPNGBytesInt32;
                        atl::bit_string_read_value(bit_string, numPNGBytesInt32);
                        size_t numPNGBytes = numPNGBytesInt32;
                        atl::bit_string_skip_to_next_byte(bit_string);
                        const unsigned char * l_pngBytes = bit_string.ptr;
                        bit_string.ptr += numPNGBytes;

                        unsigned char * imageDataOut = nullptr;
                        unsigned int imageWidthOut;
                        unsigned int imageHeightOut;
                        unsigned int decodeError = lodepng_decode32(&imageDataOut, &imageWidthOut, &imageHeightOut, l_pngBytes, numPNGBytes);
                        atl_fatal_if(decodeError > 0, "Couldn't decode PNG in sprite sheet");
                        atl_fatal_if(imageWidthOut != sheetWidth || imageHeightOut != sheetHeight, "PNG in sprite sheet of unexpected size");

                        // Allocate GL resource:
                        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
                        check_gl_errors();
                        glTexImage2D(GL_TEXTURE_2D,
                                        0,
                                        GL_RGBA,
                                        atl::integer_cast<GLsizei>(sheetWidth, [](){}),
                                        atl::integer_cast<GLsizei>(sheetHeight, [](){}),
                                        0,
                                        GL_RGBA,
                                        GL_UNSIGNED_BYTE,
                                        imageDataOut);
                        check_gl_errors();
                        GLint lFilteringMode = internal_texture_filtering_mode == texture_filtering_mode::linear ? GL_LINEAR : GL_NEAREST;
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, lFilteringMode);
                        check_gl_errors();
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, lFilteringMode);
                        check_gl_errors();

                        delete[] imageDataOut;
                    }
                    internal_loaded_file_data.free();
                    internal_status = sprite_sheet_status::ready;
                }
                else
                {
                    internal_status = sprite_sheet_status::failed;
                }
                break;
            }
        }
    }
        Modifier_eventModifier,
        Modifier_semaphoreModifier,
    };

    struct Modifier : public ITU_T_CHOICE(Modifier_enum) {


        ITU_T_CHOICE_CTORS(Modifier);

        ITU_T_CHOICEC_DECL(eventModifier, ISO_9506_MMS_1::AttachToEventCondition, Modifier_eventModifier);
        ITU_T_CHOICEC_DECL(semaphoreModifier, ISO_9506_MMS_1::AttachToSemaphore, Modifier_semaphoreModifier);

        ITU_T_ARCHIVE_FUNC;
    };

    const ServiceSupportOptions serviceSupportOptions_status = bit_string(true, 0);
    const ServiceSupportOptions serviceSupportOptions_getNameList = bit_string(true, 1);
    const ServiceSupportOptions serviceSupportOptions_identify = bit_string(true, 2);
    const ServiceSupportOptions serviceSupportOptions_rename = bit_string(true, 3);
    const ServiceSupportOptions serviceSupportOptions_read = bit_string(true, 4);
    const ServiceSupportOptions serviceSupportOptions_write = bit_string(true, 5);
    const ServiceSupportOptions serviceSupportOptions_getVariableAccessAttributes = bit_string(true, 6);
    const ServiceSupportOptions serviceSupportOptions_defineNamedVariable = bit_string(true, 7);
    const ServiceSupportOptions serviceSupportOptions_defineScatteredAccess = bit_string(true, 8);
    const ServiceSupportOptions serviceSupportOptions_getScatteredAccessAttributes = bit_string(true, 9);
    const ServiceSupportOptions serviceSupportOptions_deleteVariableAccess = bit_string(true, 10);
    const ServiceSupportOptions serviceSupportOptions_defineNamedVariableList = bit_string(true, 11);
    const ServiceSupportOptions serviceSupportOptions_getNamedVariableListAttributes = bit_string(true, 12);
    const ServiceSupportOptions serviceSupportOptions_deleteNamedVariableList = bit_string(true, 13);
    const ServiceSupportOptions serviceSupportOptions_defineNamedType = bit_string(true, 14);
    const ServiceSupportOptions serviceSupportOptions_getNamedTypeAttributes = bit_string(true, 15);
Exemple #6
0
 bit_string operator+(const bit_string& ls, const bit_string& rs) {
     octet_sequnce rslt = ls.as_octet_sequnce();
     std::size_t rsltsize = itu::split_bits_in_octets(rslt, ls.unusebits(), rs.as_octet_sequnce(), rs.unusebits());
     return bit_string(rslt, rsltsize);
 }