Esempio n. 1
0
void Stream::loadOgg(const char *filename)
{
   sound = filename;

   file = fopen(filename, "rb");
   if (!file)
      throw RubyException(rb_eRuntimeError, "Cannot open the stream file.");
   ov_open(file, &stream, NULL, 0);

   info = ov_info(&stream, -1);
   comment = ov_comment(&stream, -1);

   format = SAMPLES_FORMAT;
   
   alGenBuffers(2, buffers);
   if (alGetError() != AL_NO_ERROR)
      throw RubyException(rb_eRuntimeError, "Cannot generate the buffer.");

   generateSource();
   if (alGetError() != AL_NO_ERROR)
     throw RubyException(rb_eRuntimeError, "Cannot generate sources.");

   setPos(0.f, 0.f, 0.f);
   setVelocity(0.f, 0.f, 0.f);
   setDirection(0.f, 0.f, 0.f);

   setPitch(1.f);
   setGain(1.f);
}
Esempio n. 2
0
void Buffer::createFromDrawable(Drawable &obj) {
   shouldDelete = true;

   if (obj.getW() > 512 || obj.getH() > 512)
      throw RubyException(rb_eRuntimeError, "Drawable too big for a buffer.");

   int width = obj.getW();
   int height = obj.getH();
   img = oslCreateImage(width, height, OSL_IN_VRAM, OSL_PF_8888);
   if (!img) {
      img = oslCreateImage(width, height, OSL_IN_RAM, OSL_PF_8888);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Buffer could not be created");
   }
   else {
      Buffer::registerInVram(img);
   }

   OSL_IMAGE *old = oslGetDrawBuffer();
   setActual();

   obj.clearMove();
   obj.setPos(0, 0);
   obj.draw();
   obj.cancelMove();

   oslSetDrawBuffer(old);
}
Esempio n. 3
0
void Buffer::resize(int w, int h) {
   if (!shouldDelete)
      throw RubyException(rb_eRuntimeError, "Not allowed to resize this Buffer");

   OSL_IMAGE *old_image = img;
   OSL_IMAGE *old_buffer = oslGetDrawBuffer();
   
   img = oslCreateImage(w, h, OSL_IN_VRAM, img->pixelFormat);
   if (!img) {
      img = oslCreateImage(w, h, OSL_IN_RAM, img->pixelFormat);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Could not recreate the buffer.");
   }
   else {
      Buffer::registerInVram(img);
   }

   setActual();
   oslDrawImageXY(old_image, 0, 0);
   oslSetDrawBuffer(old_buffer);

   if (old_image->location == OSL_IN_RAM)
      oslDeleteImage(old_image);
   else
      Buffer::removeFromVram(old_image);
}
Esempio n. 4
0
Buffer::Buffer(int w, int h, int format): shouldDelete(true) {
   setClass("Buffer");

   if (w > 512 || h > 512)
      throw RubyException(rb_eRuntimeError, 
			  "Either width or height is greter than 512.");

   img = oslCreateImage(w, h, OSL_IN_VRAM, format);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Buffer could not be created.");
}
Esempio n. 5
0
Buffer::Buffer(Sprite &obj): shouldDelete(true) {
   setClass("Buffer");

   img = oslCreateImageCopy(obj.getImage(), OSL_IN_VRAM);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Buffer could not be created");
}
Esempio n. 6
0
Buffer::Buffer(const Buffer &obj): shouldDelete(true) {
   setClass("Buffer");

   img = oslCreateImageCopy(obj.img, OSL_IN_VRAM);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Buffer could not be copied.");
}
    // evaluate a ruby statement with no return value. If a ruby exception is raised
    // the description is translated into a C++ exception, which is thrown as an openstudio::RubyException.
    void evalString(const std::string &t_str)
    {

      VALUE val = rb_str_new2(t_str.c_str());
      int error;

      // save and restore the current working directory in case the call to ruby upsets it
//      QDir cwd = QDir::current();
      rb_protect(evaluateSimpleImpl,val,&error);
//      QDir::setCurrent(cwd.dirName());


      if (error != 0)
      {
        VALUE errval = rb_eval_string("$!.to_s");
        char *str = StringValuePtr(errval);
        std::string err(str);

        VALUE locval = rb_eval_string("[email protected]_s");
        str = StringValuePtr(locval);
        std::string loc(str);

        throw RubyException(err, loc);
      } 
    }
Esempio n. 8
0
void Buffer::createFromGeom(int w, int h, int format) {
   shouldDelete = true;

   if (w > 512 || h > 512)
      throw RubyException(rb_eRuntimeError,
			  "Either width or height is greter than 512.");

   img = oslCreateImage(w, h, OSL_IN_VRAM, format);
   if (!img) {
      img = oslCreateImage(w, h, OSL_IN_RAM, format);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Buffer could not be created.");
   }
   else {
      Buffer::registerInVram(img);
   }
}
Esempio n. 9
0
void Buffer::createFromBuffer(const Buffer &obj) {
   shouldDelete = true;

   img = oslCreateImageCopy(obj.img, OSL_IN_VRAM);
   if (!img) {
      img = oslCreateImageCopy(obj.img, OSL_IN_RAM);
      if (!img)
	 throw RubyException(rb_eRuntimeError, "Buffer could not be copied.");
   }
}
Esempio n. 10
0
Buffer::Buffer(Drawable &obj): shouldDelete(true) {
   setClass("Buffer");

   if (obj.getW() > 512 || obj.getH() > 512)
      throw RubyException(rb_eRuntimeError, "Drawable too big for a buffer.");
   
   img = oslCreateImage(obj.getW(), obj.getH(), OSL_IN_VRAM, OSL_PF_8888);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Buffer could not be created");
   
   OSL_IMAGE *old = oslGetDrawBuffer();
   setActual();

   obj.clearMove();
   obj.setPos(0, 0);
   obj.draw();
   obj.cancelMove();

   oslSetDrawBuffer(old);
}
Esempio n. 11
0
void Sound::loadWav(const char *filename)
{
   sound = filename;

   buffer = Manager::getInstance().getBuffer(filename);

   // We create a source, binded to our buffer :
   generateSource();
   if (alGetError() != AL_NO_ERROR)
      throw RubyException(rb_eRuntimeError, "Cannot generator source.");

   setBuffer(buffer);

   setPos(0.f, 0.f, 0.f);
   setVelocity(0.f, 0.f, 0.f);
   setDirection(0.f, 0.f, 0.f);
   
   if (alGetError() != AL_NO_ERROR)
      throw RubyException(rb_eRuntimeError, "Cannot set buffer.");
}
Esempio n. 12
0
void Buffer::resize(int w, int h) {
   OSL_IMAGE *old_image = img;
   OSL_IMAGE *old_buffer = oslGetDrawBuffer();
   
   img = oslCreateImage(w, h, OSL_IN_VRAM, img->pixelFormat);
   if (!img)
      throw RubyException(rb_eRuntimeError, "Could not recreate the buffer.");
   
   setActual();
   oslDrawImageXY(old_image, 0, 0);
   oslSetDrawBuffer(old_buffer);

   oslDeleteImage(old_image);
}
Esempio n. 13
0
Buffer::Buffer(OSL_IMAGE *arg, bool copy): img(arg) {
   shouldDelete = copy;
  
   if (copy) {
      img = oslCreateImageCopy(arg, OSL_IN_VRAM);
      if (!img) {
	 img = oslCreateImageCopy(arg, OSL_IN_RAM);
	 if (!img)
	    throw RubyException(rb_eRuntimeError, "Buffer could not be copied.");
      }
      else {
	 Buffer::registerInVram(img);
      }
   }
   else
      img = arg;

   setClass("Buffer"); 
}
Esempio n. 14
0
 void RubyException::raise(Exception* exception, bool make_backtrace) {
   throw RubyException(exception, make_backtrace);
   // Not reached.
 }