Exemple #1
0
Turtles* newTurtle(int faixa){
	Turtles* t = (Turtles*)malloc(sizeof(Turtles));
	t->faixa = faixa;
	t->vy = 0;
	t->x = rand() % 561 + 120;
	switch(faixa){
	case 1:
		t->width = 0.12375 * get_h_res();
		t->y = 0.35 *get_h_res();
		t->vx = -40/getFPS() * 2;
		break;
	case 4:
		t->width = 0.08125 * get_h_res();
		t->y = 0.20 *get_h_res();
		t->vx = -(40/getFPS())*2;
		break;
	default:
		break;
	}
	int num = rand() % 10;
	t->anim = 0;
	t->desenho = 0;
	if(num >= 8){
		t->anim = 1;
		t->desenho = rand() % 3;
	}
	return t;
}
Exemple #2
0
    void SimplePT::update(double deltaTime)
    {
        float dt = (float)deltaTime;

        // Update window title
        static int32_t fps = -1;

        if (getFPS() != fps)
        {
            // Update FPS
            fps = getFPS();

            // Update title
            std::stringstream ss;
            ss << "SimplePT [ FPS: " << fps << " ]";

            glfwSetWindowTitle(mWindow, ss.str().c_str());
        }

        // Input updates
        // Capture mouse on click
        if (glfwGetMouseButton(mWindow, GLFW_MOUSE_BUTTON_LEFT))
        {
            glfwSetInputMode(mWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
        }

        // Camera movement
        mCamera.update(dt);
    }
void
TestApp::render() {
  if(getFPS()>1.0f)
    speedFactor = SPEEDCONST/getFPS();
  
  glDisable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glDisable(GL_TEXTURE_2D);
  glDisable(GL_LIGHTING);
  
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  cam->toOpenGL();

  /*  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(800, 0, 600, 0, 0, 1.);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();*/

  glEnable(GL_FRAGMENT_PROGRAM_ARB);
  progFp->bind();
  //shader->setUniform("heightfield", 0);
  glClientActiveTextureARB(GL_TEXTURE0);
  tex->bind();
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

  glColor3f(1, 1, 0);
  glBegin(GL_QUADS);
  for(int i = 0; i < 1; i++) {
    glTexCoord2f(0, 1);
    glVertex3f(-0.01, 0.01, i*0.01);
    glTexCoord2f(0, 0);
    glVertex3f(-0.01, -0.01, i*0.01);
    glTexCoord2f(1, 0);
    glVertex3f(0.01, -.01, i*0.01);
    glTexCoord2f(1, 1);
    glVertex3f(.01, .01, i*0.01);
  }
  glEnd();
/*  glBegin(GL_QUADS);
    glTexCoord2f(0, 1);
    glVertex2f(0, 0);
    glTexCoord2f(0, 0);
    glVertex2f(256, 0);
    glTexCoord2f(1, 0);
    glVertex2f(256, 256);
    glTexCoord2f(1, 1);
    glVertex2f(0, 256);
  glEnd();
*/
  glDisable(GL_FRAGMENT_PROGRAM_ARB);
  Shader::useFixedPipeline();

  printInfos();
}
// FlameParticle2D
//---------------------------------------------------------------------------
FlameParticle2D::FlameParticle2D(	const fXYZ  &pos,
                                  float        scaleMin,
                                  float        scaleRand,
                                  float        lifetime,
                                  int          layer) : Particle2D(pos)
{
    if (lifetime <= 0.0f) {
        isAlive = false;
    }

    FlameParticle2D::layer = layer;

    scale = getScale(scaleMin, scaleRand);

    // There are 2 explosion images to choose from.
    int picNum = rand() % 2;

    if (picNum == 0) {
        index = getPakIndex(scale, staticPackedExplosion0.size());
        packedSurface.setData(* (staticPackedExplosion0[index]) );
    } else if (picNum == 1) {
        index = getPakIndex(scale, staticPackedExplosion1.size());
        packedSurface.setData(* (staticPackedExplosion1[index]));
    } else {
        assert(false);
    }

    // Check for accelerated flames.
    packedSurface.setFPS(getFPS(explosionFPS, 0));
} // end FlameParticle2D::FlameParticle2D
Exemple #5
0
void DBConsole::swap() {
	//## SHOW FPS #####
	write("FPS: " + std::to_string((int)getFPS()), BUFFER_W - 10, 0);

	//## FPS #####

	long delta = getCurrentTimeMillis() - lastRenderTime;

	if (FPS_LIMITER > 0) {
		while (delta < (1000.0 / (FPS_LIMITER + 3))) {
			delta = getCurrentTimeMillis() - lastRenderTime;
			doSystemSleep(0);
		}
	}

	fpsSum += delta;
	lastRenderTime = getCurrentTimeMillis();
	fpsCount++;
	if (fpsSum > 1000) {
		fps = 1 / (fpsSum / (fpsCount * 1000.0));
		fpsSum = fpsCount = 0;
	}

	//## SWAPPING #####
	for (int x = 0; x < BUFFER_W; x++) {
		for (int y = 0; y < BUFFER_H; y++) {
			if (buffer[x][y] != display[x][y]) {
				writeToConsole(buffer[x][y], x, y);
				display[x][y] = buffer[x][y];
			}
		}
	}
}
Exemple #6
0
/** Update TestApp */
void TestApp::update(double dt)
{
    Game::update(dt);

    // Update title with FPS
    static int fps = -1;
    
    if (getFPS() != fps)
    {
        fps = getFPS();

        std::stringstream ss;
        ss << "FPS: " << fps;
        mWindow.setTitle(ss.str().c_str());
    }
}
Exemple #7
0
void SampleBase::onShowMessage()
{
	pushMessage( "fps= %f" , getFPS() );

	for( int i = 0 ; i < 7 ; ++i )
		pushMessage( mDevMsg[i].c_str() );
}
Exemple #8
0
void Renderer::drawHUD()
{
	char outputBuffer[30];
	
	glPushMatrix();

	glEnable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);

	//black background
	glColor4f(0,0,0,.7);
	
	//draw background box
	glBegin(GL_QUADS);
		glVertex3f(-1.9, 1.47, -2);
		glVertex3f(-1.9, 1.185, -2);
		glVertex3f(-1.2, 1.185, -2);
		glVertex3f(-1.2, 1.47, -2);

	//draw paused indicator
	if(paused){
		glVertex3f(-.2, .1, -2);
		glVertex3f(-.2, -.1, -2);
		glVertex3f(.2, -.1, -2);
		glVertex3f(.2, .1, -2);
	}
	glEnd();

	//white text
	glColor4f(1,1,1,1);

	sprintf(outputBuffer, "Captured:    %i", orbsCaptured);
	glRasterPos3f(-1.85,1.4,-2);
	printString(GLUT_BITMAP_9_BY_15,outputBuffer);

	sprintf(outputBuffer, "Remaining:   %i", orbsReleased - orbsCaptured);
	glRasterPos3f(-1.85,1.35,-2);
	printString(GLUT_BITMAP_9_BY_15,outputBuffer);

	sprintf(outputBuffer, "Score:       %i", score);
	glRasterPos3f(-1.85,1.30,-2);
	printString(GLUT_BITMAP_9_BY_15,outputBuffer);

	sprintf(outputBuffer, "FPS:         %#.2f", getFPS());
	glRasterPos3f(-1.85,1.22,-2);
	printString(GLUT_BITMAP_9_BY_15,outputBuffer);

	if(paused){
        sprintf(outputBuffer, "PAUSED");
		glRasterPos3f(-.085,-.01,-2);
		printString(GLUT_BITMAP_9_BY_15,outputBuffer);
	}
	
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);
	
	glPopMatrix();
}
Exemple #9
0
bool
FBGui::run()
{
//  GNASH_REPORT_FUNCTION;

#ifdef USE_TSLIB
    int ts_loop_count = 0;
#endif

    VirtualClock& timer = getClock();
    int delay = 0;
    
    // let the GUI recompute the x/y scale factors to best fit the whole screen
    resize_view(_validbounds.width(), _validbounds.height());

    float fps = getFPS();
    
    // FIXME: this value is arbitrary, and will make any movie with
    // less than 12 frames eat up more of the cpu. It should probably
    // be a much lower value, like 2.
    if (fps > 12) {
        delay = static_cast<int>(100000/fps);
    } else {
        // 10ms per heart beat
        delay = 10000;
    }
    // log_debug(_("Movie Frame Rate is %d, adjusting delay to %dms"), fps,
    //           _interval * delay);
    
    // This loops endlessly at the frame rate
    while (!terminate_request) {  
        // wait the "heartbeat" inteval. _interval is in milliseconds,
        // but gnashSleep() wants nanoseconds, so adjust by 1000.
        gnashSleep(_interval * 1000);
        // TODO: Do we need to check the real time slept or is it OK when we woke
        // up early because of some Linux signal sent to our process (and thus
        // "advance" faster than the "heartbeat" interval)? - Udo

#ifdef USE_TSLIB
        ts_loop_count++; //increase loopcount
#endif
        
        // check input devices
        checkForData();

        // advance movie  
        Gui::advance_movie(this);

        // check if we've reached a timeout
        if (_timeout && timer.elapsed() >= _timeout ) {
            break;
        }
    }

    return true;
}
Exemple #10
0
void
TestApp::printInfos()
{
  font->setColor(1, 1, 1);
  font->printf(0, height-16, "Fps: %.2f", getFPS());
  font->printf(0, height-32, "Speed factor: %.6f", speedFactor);
  
  font->setColor(1, 0, 0);
  font->printf(0, 16, "OpenGL error: %s", Renderer::getGLErrorString());
}
void drawFPS (void)
{
	GLfloat textColor[3] = { 1.0f, 1.0f, 1.0f };
	char * string = calloc ((strlen ("FPS = ") + 4), sizeof(char));
	sprintf(string, "FPS = %d", getFPS());
	
	drawString (0.6, 0.1, textColor, string);
	
	free (string);
}
Exemple #12
0
void FPS::update()
{
    if(mClock.getElapsedTime().asSeconds() >= 1.f)
    {
        mFps = mFrame/mClock.getElapsedTime().asSeconds();
        mFrame = 0;
        mClock.restart();
        std::cout << "FPS:" << getFPS() << "\n";
    }

    ++mFrame;
}
Exemple #13
0
int gameMainOpen(void)
{

    unsigned int joy;
    tmouse *mo;

    int sound;
    int draw;
    
      

        actualLevel->view.buf=GetVideo();
        
        joy=GetJoystick();
        mo=getMouseInf();
        
        actualLevel->mouse=mo;
        actualLevel->key=joy;
        
   
        draw=getDrawFrame();
    
        switch (runStateGame) 
        {
            case 0:
                if(loadGame(actualLevel,draw)) 
                    runStateGame=1;
            break;
            case 1:
                runGame(actualLevel,draw);
            break;        
            default:
            break;
        }
        
    
        wipeView(&actualLevel->transiction);
              
        if(getRenderAudio())
            sound=SRenderAudio();
        
        if(draw) FlipVideo();
        WaitSyncTimer();  
        
        
        getFPS(&Vfpsg,&Vfps);
		
      
        return draw;
             
   
}
Exemple #14
0
void Window::drawFPS()
{
    std::ostringstream fpsText;
    fpsText << std::setprecision(3) << getFPS() << " FPS";

    const util::BitmapFont* font = getSmallFont();
    const PixelViewport& pvp = getPixelViewport();

    glRasterPos3f( pvp.w - 60.f, pvp.h - 16.f , 0.99f );
    glColor3f( .8f, .8f, .8f );

    font->draw( fpsText.str( ));
}
std::string MyDirectDrawSw::getDebugInfo() const
{
    const int BuffSize = 256;
    char buff[BuffSize];
    std::snprintf(buff, BuffSize, "FPS %f, frametime %f\nMode %dx%dx%d, num surfaces: %d",
                  getFPS(),
                  getFrameTime(),
                  mDispMode.width,
                  mDispMode.height,
                  mDispMode.bpp,
                  mSurfaces.size());
    return buff;
}
Exemple #16
0
/*****************************************************************************
 * Demux: reads and demuxes data packets
 *****************************************************************************
 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
 *****************************************************************************/
static int Demux( demux_t *p_demux)
{
    demux_sys_t *p_sys = p_demux->p_sys;
    block_t *p_block_in, *p_block_out;

    if( ( p_block_in = stream_Block( p_demux->s, HEVC_BLOCK_SIZE ) ) == NULL )
    {
        return 0;
    }

    p_block_in->i_dts = VLC_TS_INVALID;
    p_block_in->i_pts = VLC_TS_INVALID;

    while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) )
    {
        while( p_block_out )
        {
            block_t *p_next = p_block_out->p_next;

            p_block_out->p_next = NULL;

            p_block_out->i_dts = p_sys->i_dts;
            p_block_out->i_pts = VLC_TS_INVALID;

            uint8_t nal_type = p_block_out->p_buffer[4] & 0x7E;

            /*Get fps from vps if available and not already forced*/
            if( p_sys->f_fps == 0.0f && nal_type == 0x40 )
            {
                if( getFPS( p_demux, p_block_out) )
                {
                    msg_Err(p_demux,"getFPS failed");
                    return 0;
                }
            }

            /* Update DTS only on VCL NAL*/
            if( nal_type < 0x40 && p_sys->f_fps )
            {
                es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_dts );
                p_sys->i_dts += (int64_t)((float)CLOCK_FREQ / p_sys->f_fps);
            }

            es_out_Send( p_demux->out, p_sys->p_es, p_block_out );

            p_block_out = p_next;

        }
    }
    return 1;
}
Exemple #17
0
void MetadataStream::convertTimestampToFrameIndex(
    long long timestamp, long long duration,
    long long& frameIndex, long long& numOfFrames )
{
    frameIndex = 0, numOfFrames = 0;
    unsigned int i = 0;
    for(; i < videoSegments.size(); i++)
    {
        auto segment = videoSegments[i];
        if (segment->getTime() <= timestamp && segment->getTime() + segment->getDuration() >= timestamp)
        {
            frameIndex += (long long)((timestamp - segment->getTime()) * segment->getFPS() / 1000);
            if (segment->getTime() + segment->getDuration() >= timestamp + duration)
                numOfFrames = (long long)(duration * segment->getFPS() / 1000);
            else
                numOfFrames = (long long)((segment->getTime() + segment->getDuration() - timestamp) * segment->getFPS() / 1000);
            break;
        }
        frameIndex += (long long)(segment->getDuration() * segment->getFPS() / 1000);
    }
    if (i == videoSegments.size())
        frameIndex = Metadata::UNDEFINED_FRAME_INDEX, numOfFrames = Metadata::UNDEFINED_FRAMES_NUMBER;
}
void drawHUD(Player *p, PlayerVisual *pV) {
	char temp[1024];
	char pause_message[128];
	float pause_color[3];

	getPauseString(pause_message, pause_color);

	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	rasonly(&pV->display);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	/*
		drawHud: parameters
		- Viewport Width
		- Viewport Height
		- Score (or -1 if disabled)
		- AI status ("computer player" or "")
		- Speed digital (absolute value)
		- Speed analog (1 for default speed, > 1 during acceleration)
		- Booster value (between 0 and 1)
		- fps
		- pause message
		- pause message r,g,b colors
	*/

	sprintf(temp, "drawHUD(%d, %d, %d, \"%s\", %f, %f, %f, %f, %d, \"%s\", %f, %f, %f)",
		pV->display.vp_w, pV->display.vp_h,
		gSettingsCache.show_scores ? p->data->score : -1,
		gSettingsCache.show_ai_status ?
		(p->ai->active ? "AI_COMPUTER" : "") : "",
		p->data->speed,
		p->data->speed / (2 * game2->rules.speed),
		p->data->booster / getSettingf("booster_max"),
		p->data->wall_buster / getSettingf("wall_buster_max"),
		getFPS(),
		pause_message,
		pause_color[0],
		pause_color[1],
		pause_color[2]
		);

	glScalef(pV->display.vp_w / 1024.0f, pV->display.vp_w / 1024.0f, 1.0f);
	// fprintf(stderr, "%s\n", temp);
	scripting_Run(temp);

	glDisable(GL_BLEND);
	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
}
Exemple #19
0
void Window::drawFPS()
{
    std::ostringstream fpsText;
    fpsText << std::setprecision(3) << getFPS() << " FPS";

    const Font* font = getSmallFont();
    const PixelViewport& pvp = getPixelViewport();

    glLogicOp( GL_XOR );
    glEnable( GL_COLOR_LOGIC_OP );
    glRasterPos3f( pvp.w - 60.f, 10.f , 0.99f );
    glColor3f( 1.f, 1.f, 1.f );

    font->draw( fpsText.str( ));
}
Exemple #20
0
void MetadataStream::convertFrameIndexToTimestamp(
    long long frameIndex, long long numOfFrames,
    long long& timestamp, long long& duration )
{
    long long localFrameIndex = 0;
    timestamp = 0, duration = 0;
    unsigned int i = 0;
    for (; i < videoSegments.size(); i++)
    {
        auto segment = videoSegments[i];
        if (localFrameIndex + (long long)(segment->getDuration() * segment->getFPS() / 1000) > frameIndex)
        {
            timestamp = (long long)(segment->getTime() + (frameIndex - localFrameIndex) / segment->getFPS() * 1000);
            if (localFrameIndex + segment->getDuration() * segment->getFPS() / 1000 > frameIndex + numOfFrames)
                duration = (long long)(numOfFrames / segment->getFPS() * 1000);
            else
                duration = (long long)(segment->getTime() + segment->getDuration() - timestamp);
            break;
        }
        localFrameIndex += (long long)(segment->getDuration() * segment->getFPS() / 1000);
    }
    if (i == videoSegments.size())
        timestamp = Metadata::UNDEFINED_TIMESTAMP, duration = Metadata::UNDEFINED_DURATION;
}
Exemple #21
0
void Monitor::run()
{
	stopExec = false;
	int fps = getFPS();
	if(fps < 1)
		fps = 30;

	int delay = 1000/fps;
	while(mInitialized && !stopExec && mCurrentFrameNumber < mLastFrameNumber)
	{
		moveToFrame(mCurrentFrameNumber + 1);
		emit imageChanged();
		msleep(delay);
	}
	stopExec = true;
}
std::string PerfTimer::getFormattedTime(bool isShowAverage) const
{
	string show_name = name_;
	if(!desc_.empty())
	{
		show_name = desc_;
	}
	char str[1000];
	if(isShowAverage) 
	{
		sprintf(str, "%s: %0.3lfs (%0.2lf fps, %0.3lfms)", show_name.c_str(), getTime(), getFPS(), getAverageTime() * 1000.0);
	} else
	{
		sprintf(str, "%s: %0.3lfs", show_name.c_str(), getTime());
	}
	string ret(str);
	return ret;
}
void display(void)
{
    // Clear the screen with the background colour (set in myinit)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    model_view = mat4(1.0f);
    model_view *= Translate(0.0f, 0.0f, -15.0f);
    HMatrix r;
    Ball_Value(Arcball,r);

    mat4 mat_arcball_rot(
        r[0][0], r[0][1], r[0][2], r[0][3],
        r[1][0], r[1][1], r[1][2], r[1][3],
        r[2][0], r[2][1], r[2][2], r[2][3],
        r[3][0], r[3][1], r[3][2], r[3][3]);
    model_view *= mat_arcball_rot;

    mat4 view = model_view;
    glUniformMatrix4fv( uView, 1, GL_TRUE, view );

    // Previously glScalef(Zoom, Zoom, Zoom);
    model_view *= Scale(Zoom);
	model_view *= Translate(0.0f, 0.0f, -10.0f);
	model_view *= RotateX(10);


	//if(prologue < 20) {
	//	model_view *= Translate(0.0f, -20.0f+prologue, 0.0f);
	//	cam_eye = vec4(rotateX, 0.0, rotateZ, 1.0);
	//	model_view *= LookAt(cam_eye, cam_ref, cam_up);
	//}
	
	//if(timeline > 57)
	//	model_view *= Translate(0.0f, -temp3, -0.0f);

	// Draw Scene
	drawScene();

	// Draw Leaf
	if(timeline < 8.0f) {
		mvstack.push(model_view);
			model_view *= Translate(0.0f, 25.0f-prologue, 0.0f);
			model_view *= RotateZ(leafSway);
			model_view *= Translate(4.0f, -1.0f-prologue, 3.0f);
			drawLeaf();
		model_view = mvstack.pop();
	}

	/*/ // Draw Bee
	if(timeline > 35.0f && timeline < 38.0f) {
		mvstack.push(model_view);
			model_view *= Translate(15.0f-(temp2-230), pathBeeVert, 4.5f);
			model_view *= Scale(0.5f, 0.5f, 0.5f);
			drawBee();
		model_view = mvstack.pop();
	}
	/*/ 
    //draw GFS
	mvstack.push(model_view);

	if(timeline>28&&timeline<36)
		{
			model_view *= Translate(47.5f-temp5/2, 0.0f, 3.0f);
		    model_view*=RotateY(-90);
			record=40.0f-temp5/2;
	    }

	else if(timeline>=36&&timeline<=40)
	{

		model_view *= Translate(7.5f, 0.0f, 4.0);
		model_view*=RotateY(-135);
	}
	else if(timeline>40&&timeline<59)
	{
		model_view *= Translate(7.5f+temp6/4, 0.0f, 2.0f);
		model_view *= RotateY(90);
	}
	if(timeline>=28)
		drawGFS(1,1,1);

	model_view = mvstack.pop();

	// Draw Male
	mvstack.push(model_view);
		if(timeline > 20.0f && timeline < 24.0f) {
			model_view *= Translate(-5.0f+temp, 0.0f, 2.25f);
			prevX = -5.0+temp;
		}
		else if(timeline >= 24.0f && timeline < 27.0f)
			model_view *= Translate(prevX-temp, 0.0f, 2.25f);
		else if(timeline > 30.5 && timeline < 36.0) {
			model_view *= Translate(-25.0+temp2/10, -.75f, 4.5f);
			prevX = -25.0+temp2/10;
			model_view *= RotateY(90);
		}
		else if(timeline >= 35.0f && timeline < 55.0) {
			model_view *= Translate(prevX, -.75f, 4.5f);
			model_view *= RotateY(135);
		}
		drawDiaoSi(0.3f, 0.6f, .6f);
	model_view = mvstack.pop();

	// Draw Female
	if(timeline > 8.0f) {
		mvstack.push(model_view);
			if(timeline < 12.0f) {
				model_view *= Translate(29.0f-2*timeline, -1.25f, 4.5f);
				model_view *= RotateY(-90);
			}

			if(timeline > 12.0f && timeline < 13.5) {
				model_view *= Translate(5.0f, -1.25f, 4.5f);
				model_view *= RotateY(-90+temp*1.25);
			}

			if(timeline > 13.5f && timeline < 40.0f || timeline > 53.75)
				model_view *= Translate(5.0f, 0.0f, 2.25f);

			if(timeline >= 40.0f && timeline < 59.0f) {
				model_view *= Translate(5.5f+temp6/4, -1.25f, 4.5f);
				model_view *= RotateY(90);
			}

		/*/	if(timeline > 50.0f && timeline < 53.75) {
				if(15.0f-(temp2-560)/10 > 5.0) {
					model_view *= Translate(15.0-(temp2-560)/10, -1.25f, 4.5f);
					prevY = 15.0-(temp2-560)/10;
				}
				else
					model_view *= Translate(prevY, -1.25f, 4.5f);

				if(timeline < 52.6f)
					model_view *= RotateY(-90);
				else
					model_view *= RotateY(-90+temp*2);
			}
		 /*/
			if(timeline < 59.0)
				drawFemale(1.0f, 0.0, 1.0f);
			//else
			//	drawFemale(1.0f, 1.0f, 1.0f);

		model_view = mvstack.pop();
	}

	if(timeline > 59.0)
		exit(0);

	getFPS();

    glutSwapBuffers();
    if(Recording == 1)
        FrSaver.DumpPPM(Width, Height) ;
}
void MGFWrapper::draw()
{
	bool noRenderingNeeded = isSelectiveTileRenderingActive() && !MGMovingObject::anyMovingMO() && !isFramingOngoing() && !renderAllTiles();

	if(!noRenderingNeeded)
	{
		// Draw all tiles visible in the window...
		int tX, tY;
		for(int x = 0; x < m_Map.getWidth(); x++)
		{
			tX = x * m_Map.getTileWidth() + m_Map.getScrollX();
			for(int y = 0; y < m_Map.getHeight(); y++)
			{
				// Only draw the tiles actually visible (+1 to draw partly visible tiles) in the window...
				tY = y * m_Map.getTileHeight() + m_Map.getScrollY();
				if(  (tX <= getWindow()->getWidth() + m_Map.getTileWidth()) &&
					 (tX >= 0 - m_Map.getTileWidth()) &&
					 (tY <= getWindow()->getHeight() + m_Map.getTileHeight()) &&
					 (tY >= 0 - m_Map.getTileHeight()) &&
					 (!isSelectiveTileRenderingActive() || renderAllTiles() || m_Map.isMarkedForRendering(x, y)) )
				{
					getWindow()->drawSprite(textures[TEX_GRASS], 0, 0, tX, tY, m_Map.getTileWidth(), m_Map.getTileHeight());
					m_Map.unmarkForRendering(x, y);
				}
			}
		}

		// Draw all moving objects...
		int oX, oY;
		for(std::list<MGMovingObject>::iterator it = m_MO.begin(); it != m_MO.end(); it++)
		{
			oX = it->getTileX() * m_Map.getTileWidth() + m_Map.getScrollX() + it->getXOffset();
			oY = it->getTileY() * m_Map.getTileHeight() + m_Map.getScrollY() + it->getYOffset();
			// Only draw visible moving objects...
			if(detectCollisionRectangle(oX, oY, oX + m_Map.getTileWidth(), oY + m_Map.getTileHeight(), 0, 0, getWindow()->getWidth(), getWindow()->getHeight()))
			{
				getWindow()->drawSprite(textures[TEX_MO_0 + it->getOwner()], 0, 0, oX, oY, m_Map.getTileWidth(), m_Map.getTileHeight());
				if(!it->isIdle() && isSelectiveTileRenderingActive())
				{
					m_Map.markForRendering(it->getTileX(), it->getTileY());
					m_Map.markForRendering(it->getTileX() + 1, it->getTileY() + 1);
					m_Map.markForRendering(it->getTileX() - 1, it->getTileY() - 1);
					m_Map.markForRendering(it->getTileX() + 1, it->getTileY() - 1);
					m_Map.markForRendering(it->getTileX() - 1, it->getTileY() + 1);
					m_Map.markForRendering(it->getTileX() + 1, it->getTileY());
					m_Map.markForRendering(it->getTileX() - 1, it->getTileY());
					m_Map.markForRendering(it->getTileX(), it->getTileY() + 1);
					m_Map.markForRendering(it->getTileX(), it->getTileY() - 1);
				}

				if(it->isMarked())
				{
					getWindow()->drawSprite(textures[TEX_REDFRAME], 0, 0, oX, oY, m_Map.getTileWidth(), m_Map.getTileHeight());
				}
			}
		}

		// Draw all stationary objects...
		drawAllSOWithTexHandles();

		// Draw a frame around the edge of the map
		getWindow()->drawRectangleRGB(m_Map.getLeftEdge(), m_Map.getTopEdge(), m_Map.getWindowWidth() - m_Map.getLeftEdge() - m_Map.getRightEdge(), m_Map.getWindowHeight() - m_Map.getBottomEdge() - m_Map.getTopEdge(),  0x00, 0x00, 0xFF);

		// Draw the mini map if enabled. Also draw all objects on it...
		drawBasicMiniMap(16, 16);
	}

	// Example of how text can be printed on screen.. Here FPS and time left between frames.
	getWindow()->drawText((std::string("MOs: ") + MGFramework::toString((int)getNumberOfMO()) + 
		std::string("(") + MGFramework::toString((int)MGMovingObject::nMovingMO()) + std::string(")") + std::string("      ")).c_str(), 
			 16, getWindow()->getWidth() - m_Map.getWidth() - 16, m_Map.getHeight() + 30, 0, 0, 0, 0, 255, 0);
	getWindow()->drawText((std::string("FD : ") + MGFramework::toString((int)getLastFrameDelayTime()) + std::string("      ")).c_str(), 
			 16, getWindow()->getWidth() - m_Map.getWidth() - 16, m_Map.getHeight() + 50, 0, 0, 0, 0, 255, 0);
	getWindow()->drawText((std::string("FPS: ") + MGFramework::toString((int)getFPS()) + std::string("      ")).c_str(), 
			 16, getWindow()->getWidth() - m_Map.getWidth() - 16, m_Map.getHeight() + 70, 0, 0, 0, 0, 255, 0);
	getWindow()->drawText((std::string("DT: ") + MGFramework::toString(getWindow()->getDrawnSpritesCounter()) + std::string("      ")).c_str(), 
			 16, getWindow()->getWidth() - m_Map.getWidth() - 16, m_Map.getHeight() + 90, 0, 0, 0, 0, 255, 0);


	// Draw marking frame if marking is ongoing
	if(!noRenderingNeeded)
	{
		if(isFramingOngoing())
		{
			getWindow()->drawRectangleRGB(getFrameStartX(), getFrameStartY(), getFrameEndX(), getFrameEndY(),  0xFF, 0x00, 0x00);
		}
	}


}
// create
//---------------------------------------------------------------------------
void PuffParticle2D::create(	PUFF_TYPE particleType,
                             float     scaleMin,
                             float     scaleRand,
                             int       FPSmin,
                             int       FPSrand,
                             int       layer,
                             int       shadowLayer,
                             int       isFarAway /* = 0 */)
{
    assert(scaleMin >= 0.0);
    assert(scaleRand >= 0.0);

    scale = getScale(scaleMin, scaleRand);

    PuffParticle2D::layer       = layer;
    PuffParticle2D::shadowLayer = shadowLayer;
    PuffParticle2D::isFarAway   = isFarAway;

    index = getPakIndex(scale, staticPackedSmokeLightPuff.size());

    if (particleType == LIGHT) {
        packedSurface.setData( *(staticPackedSmokeLightPuff[index]) );
        packedSurfaceShadow.setData( *(staticPackedSmokeLightPuff[index]) );
    } else if (particleType == DARK) {
        packedSurface.setData( *(staticPackedSmokeDarkPuff[index]) );
        packedSurfaceShadow.setData( *(staticPackedSmokeDarkPuff[index]) );
    } else if (particleType == DIRT) {
        packedSurface.setData( *(staticPackedDirtPuff[index]) );
        packedSurfaceShadow.setData( *(staticPackedDirtPuff[index]) );
    } else {
        throw Exception("ERROR: Unsupported particleType.");
    }

    packedSurfaceShadow.setDrawModeBlend(&Palette::colorTableDarkenALittle);

    if (GameConfig::video_blendsmoke) {
        int randColorTable = rand() % 4;

        if (randColorTable == 0) {
            packedSurface.setDrawModeBlend(&Palette::colorTable2080);
        } else if(randColorTable == 1) {
            packedSurface.setDrawModeBlend(&Palette::colorTable4060);
        } else if(randColorTable == 2) {
            packedSurface.setDrawModeBlend(&Palette::colorTable6040);
        } else if(randColorTable == 3) {
            packedSurface.setDrawModeBlend(&Palette::colorTable8020);

        } else {
            assert(false);
        }

    } else {
        packedSurface.setDrawModeSolid();
    }

    packedSurface.setFPS(getFPS(FPSmin, FPSrand));

    // If the particles are far away, speed them up.
    if (isFarAway) {
        assert(packedSurface.getFPS() > 0);

        packedSurface.setFPS(packedSurface.getFPS() * 2.0f);
    }

    // Set the shadow FPS to match the non-shadow particle.
    packedSurfaceShadow.setFPS(packedSurface.getFPS());

} // end PuffParticle2D::create
Exemple #26
0
	void VehicleSim::update(double dt)
	{
		for (b2Body* body = _physWorld.GetBodyList(); body; body = body->GetNext())
		{
			// Simulate rolling resistance
			// Simple version of rolling resistance using formula given by spec
			// Frr = -Crr * v
			// A better implementation of rolling resistance would
			// counteract the movement due to other forces
			// such that a coefficient of 1 would equal no movement
			// To calculate this, you could resolve the forces on the body into the direction of
			// the vector perpendicular to the normal of the contact and then multiply that
			// by the coefficient of friction of the contact
			for (b2ContactEdge* contactEdge = body->GetContactList(); contactEdge; contactEdge = contactEdge->next)
			{ 
				b2Contact* contact = contactEdge->contact;

				// Get fixtures
				b2Fixture* fixA = contact->GetFixtureA();
				b2Fixture* fixB = contact->GetFixtureB();

				b2Fixture* bodyFix = (fixA->GetBody() == body ? fixA : fixB);

				if (bodyFix->GetShape()->GetType() == b2Shape::e_circle)
				{
					// Get friction of fixtures
					float ca = fixA->GetFriction();
					float cb = fixB->GetFriction();

					// Calculate coefficient of friction for this contact
					// (average of both coefficients of friction)
					float c = contact->GetFriction();

					// Calculate force due to rolling resistance
					// F_rr = v * -c_rr
					b2Vec2 F_rr = -c * body->GetLinearVelocity();

					// Apply rolling resistance
					body->ApplyForceToCenter(F_rr, true);
				}
			}

			// Simple aerodynamic drag, calculated using the formula
			// Fad = -Cad * v|v|
			// Where Cad = the cross sectional area of the car
			// And v is the velocity
			// The cross sectional area is scaled down from world coordinates
			// by a factor of 1000 to produce nice results
			// A more complicated form of aerodynamic drag can be calculated
			// the mass density p of the air (dependent on its temperature and pressure),
			// and the drag coefficient Cd calculated using the object's geometry
			// The formula for this would be Fd = 0.5 * p * v|v| * Cd * Cad
			// But this is beyond the scope of this simulation
			b2Fixture* fixtures = body->GetFixtureList();
			if (fixtures != nullptr)
			{
				b2AABB aabb = fixtures->GetAABB(0);

				for (b2Fixture* fix = fixtures; fix; fix = fix->GetNext())
				{
					// The cross sectional area is estimated using the AABB of each shape
					aabb.Combine(fix->GetAABB(0));
				}

				b2Vec2 size = 0.001f * (aabb.upperBound - aabb.lowerBound);

				// Reverse size to get an approximation of cross sectional area
				float temp = size.x;
				size.x = size.y;
				size.y = temp;

				// Calculate v|v|
				b2Vec2 vsquared = body->GetLinearVelocity().Length() * body->GetLinearVelocity();

				// Calculate force of aerodynamic drag
				b2Vec2 Fad(-size.x * vsquared.x, -size.y * vsquared.y);

				// Apply force to body
				body->ApplyForceToCenter(Fad, true);
			}
		}

		// Update physics system
		double time = glfwGetTime();
		float stepTime = (1.0f / _timeStep);
		while (_lastPhysicsUpdate + stepTime < time)
		{
			if (_simulationRunning)
				doStep();

			_lastPhysicsUpdate += stepTime;
		}

		// Update options
		if (!_worldOptionsTabButton->Hidden())
		{
			for (auto it = _updatableOptions.begin(); it != _updatableOptions.end(); ++it)
			{
				(*it)->update();
			}
		}

		// Do frame update
		doFrameInput(dt);

		// Get inner area of dock
		Gwen::Rect innerBounds = _guiDock->GetInnerBounds();

		// Update camera's viewport
		_camera.setViewport(innerBounds.x, innerBounds.y, innerBounds.w, innerBounds.h);

		// Update camera's matrix
		if (innerBounds.h > 0)
		{
			float aspect = (float)innerBounds.w / innerBounds.h;
			_camera.orthographic(_orthoScale, aspect);
		}

		// Handle motor for each joint
		for (auto joint = _physWorld.GetJointList(); joint; joint = joint->GetNext())
		{
			MotorInput* motorInput = (MotorInput*)joint->GetUserData();

			if (motorInput != nullptr)
			{
				motorInput->update(_window, joint);
			}
		}

		// Set window title
		const int TITLE_LEN = 1024;
		char title[1024];
		sprintf(title, VEHICLESIM_TITLE_FORMAT, getFPS());
		glfwSetWindowTitle(_window, title);
	}
Exemple #27
0
double Video::getLengthTime(){
	return getLengthFrames()/getFPS();
}
Exemple #28
0
MStatus AlembicNode::compute(const MPlug & plug, MDataBlock & dataBlock)
{
    MStatus status;

    // update the frame number to be imported
    MDataHandle speedHandle = dataBlock.inputValue(mSpeedAttr, &status);
    double speed = speedHandle.asDouble();

    MDataHandle offsetHandle = dataBlock.inputValue(mOffsetAttr, &status);
    double offset = offsetHandle.asDouble();

    MDataHandle timeHandle = dataBlock.inputValue(mTimeAttr, &status);
    MTime t = timeHandle.asTime();
    double inputTime = t.as(MTime::kSeconds);

    double fps = getFPS();

    // scale and offset inputTime.
    inputTime = computeAdjustedTime(inputTime, speed, offset/fps);

    // this should be done only once per file
    if (mFileInitialized == false)
    {
        mFileInitialized = true;

        MDataHandle dataHandle = dataBlock.inputValue(mAbcFileNameAttr);
        MFileObject fileObject;
        fileObject.setRawFullName(dataHandle.asString());
        MString fileName = fileObject.resolvedFullName();

        // TODO, make sure the file name, or list of files create a valid
        // Alembic IArchive

        // initialize some flags for plug update
        mSubDInitialized = false;
        mPolyInitialized = false;

        // When an alembic cache will be imported at the first time using
        // AbcImport, we need to set mIncludeFilterAttr (filterHandle) to be
        // mIncludeFilterString for later use. When we save a maya scene(.ma)
        // mIncludeFilterAttr will be saved. Then when we load the saved
        // .ma file, mIncludeFilterString will be set to be mIncludeFilterAttr.
        MDataHandle includeFilterHandle =
                        dataBlock.inputValue(mIncludeFilterAttr, &status);
        MString& includeFilterString = includeFilterHandle.asString();

       if (mIncludeFilterString.length() > 0)
        {
            includeFilterHandle.set(mIncludeFilterString);
            dataBlock.setClean(mIncludeFilterAttr);
        }
        else if (includeFilterString.length() > 0)
        {
            mIncludeFilterString = includeFilterString;
        }

        MDataHandle excludeFilterHandle =
                        dataBlock.inputValue(mExcludeFilterAttr, &status);
        MString& excludeFilterString = excludeFilterHandle.asString();

       if (mExcludeFilterString.length() > 0)
        {
            excludeFilterHandle.set(mExcludeFilterString);
            dataBlock.setClean(mExcludeFilterAttr);
        }
        else if (excludeFilterString.length() > 0)
        {
            mExcludeFilterString = excludeFilterString;
        }


        MFnDependencyNode dep(thisMObject());
        MPlug allSetsPlug = dep.findPlug("allColorSets");
        CreateSceneVisitor visitor(inputTime, !allSetsPlug.isNull(),
            MObject::kNullObj, CreateSceneVisitor::NONE, "",
            mIncludeFilterString, mExcludeFilterString);

        {
           mData.getFrameRange(mSequenceStartTime, mSequenceEndTime);
            MDataHandle startFrameHandle = dataBlock.inputValue(mStartFrameAttr,
                                                                &status);
            startFrameHandle.set(mSequenceStartTime*fps);
            MDataHandle endFrameHandle = dataBlock.inputValue(mEndFrameAttr,
                                                                &status);
            endFrameHandle.set(mSequenceEndTime*fps);
        }
    }

    // Retime
    MDataHandle cycleHandle = dataBlock.inputValue(mCycleTypeAttr, &status);
    short playType = cycleHandle.asShort();
    inputTime = computeRetime(inputTime, mSequenceStartTime, mSequenceEndTime,
                              playType);

    clamp<double>(mSequenceStartTime, mSequenceEndTime, inputTime);

    // update only when the time lapse is big enough
    if (fabs(inputTime - mCurTime) > 0.00001)
    {
        mOutRead = std::vector<bool>(mOutRead.size(), false);
        mCurTime = inputTime;
    }

    if (plug == mOutPropArrayAttr)
    {

        if (mOutRead[0])
        {
            dataBlock.setClean(plug);
            return MS::kSuccess;
        }

        mOutRead[0] = true;

        unsigned int propSize =
            static_cast<unsigned int>(mData.mPropList.size());

        if (propSize > 0)
        {
            MArrayDataHandle outArrayHandle = dataBlock.outputValue(
                mOutPropArrayAttr, &status);

            unsigned int outHandleIndex = 0;
            MDataHandle outHandle;

            // for all of the nodes with sampled attributes
            for (unsigned int i = 0; i < propSize; i++)
            {
                // only use the handle if it matches the index.
                // The index wont line up in the sparse case so we
                // can just skip that element.
                if (outArrayHandle.elementIndex() == outHandleIndex++)
                {
                    outHandle = outArrayHandle.outputValue();
                }
                else
                {
                    continue;
                }

                if (mData.mPropList[i].mArray.valid())
                {
                    readProp(mCurTime, mData.mPropList[i].mArray, outHandle);
                }
                else if (mData.mPropList[i].mScalar.valid())
                {
                    // for visibility only
                    if (mData.mPropList[i].mScalar.getName() ==
                        Alembic::AbcGeom::kVisibilityPropertyName)
                    {
                        Alembic::Util::int8_t visVal = 1;
                        mData.mPropList[i].mScalar.get(&visVal,
                            Alembic::Abc::ISampleSelector(mCurTime,
                                Alembic::Abc::ISampleSelector::kNearIndex ));
                        outHandle.setGenericBool(visVal != 0, false);
                    }
                    else
                    {
                        // for all scalar props
                        readProp(mCurTime, mData.mPropList[i].mScalar, outHandle);
                    }
                }
                outArrayHandle.next();
            }
            outArrayHandle.setAllClean();
        }

    }
    else if (plug == mOutTransOpArrayAttr )
    {
        if (mOutRead[1])
        {
            dataBlock.setClean(plug);
            return MS::kSuccess;
        }

        mOutRead[1] = true;

        unsigned int xformSize =
            static_cast<unsigned int>(mData.mXformList.size());

        if (xformSize > 0)
        {
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutTransOpArrayAttr, &status);

            MPlug arrayPlug(thisMObject(), mOutTransOpArrayAttr);

            MDataHandle outHandle;
            unsigned int outHandleIndex = 0;

            for (unsigned int i = 0; i < xformSize; i++)
            {
                std::vector<double> sampleList;

                if (mData.mIsComplexXform[i])
                {
                    readComplex(mCurTime, mData.mXformList[i], sampleList);
                }
                else
                {
                    Alembic::AbcGeom::XformSample samp;
                    read(mCurTime, mData.mXformList[i], sampleList, samp);
                }

                unsigned int sampleSize = (unsigned int)sampleList.size();

                for (unsigned int j = 0; j < sampleSize; j++)
                {
                    // only use the handle if it matches the index.
                    // The index wont line up in the sparse case so we
                    // can just skip that element.
                    if (outArrayHandle.elementIndex() == outHandleIndex++)
                    {
                        outHandle = outArrayHandle.outputValue(&status);
                    }
                    else
                        continue;

                    outArrayHandle.next();
                    outHandle.set(sampleList[j]);
                }
            }
            outArrayHandle.setAllClean();
        }
    }
    else if (plug == mOutLocatorPosScaleArrayAttr )
    {
        if (mOutRead[8])
        {
            dataBlock.setClean(plug);
            return MS::kSuccess;
        }

        mOutRead[8] = true;

        unsigned int locSize =
            static_cast<unsigned int>(mData.mLocList.size());

        if (locSize > 0)
        {
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutLocatorPosScaleArrayAttr, &status);

            MPlug arrayPlug(thisMObject(), mOutLocatorPosScaleArrayAttr);

            MDataHandle outHandle;
            unsigned int outHandleIndex = 0;

            for (unsigned int i = 0; i < locSize; i++)
            {
                std::vector< double > sampleList;
                read(mCurTime, mData.mLocList[i], sampleList);

                unsigned int sampleSize = (unsigned int)sampleList.size();
                for (unsigned int j = 0; j < sampleSize; j++)
                {
                    // only use the handle if it matches the index.
                    // The index wont line up in the sparse case so we
                    // can just skip that element.
                    if (outArrayHandle.elementIndex() == outHandleIndex++)
                    {
                        outHandle = outArrayHandle.outputValue(&status);
                    }
                    else
                        continue;

                    outArrayHandle.next();
                    outHandle.set(sampleList[j]);
                }
            }
            outArrayHandle.setAllClean();
        }
    }
    else if (plug == mOutSubDArrayAttr)
    {
        if (mOutRead[2])
        {
            // Reference the output to let EM know we are the writer
            // of the data. EM sets the output to holder and causes
            // race condition when evaluating fan-out destinations.
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutSubDArrayAttr, &status);
            const unsigned int elementCount = outArrayHandle.elementCount();
            for (unsigned int j = 0; j < elementCount; j++)
            {
                outArrayHandle.outputValue().data();
                outArrayHandle.next();
            }
            outArrayHandle.setAllClean();
            return MS::kSuccess;
        }

        mOutRead[2] = true;

        unsigned int subDSize =
            static_cast<unsigned int>(mData.mSubDList.size());

        if (subDSize > 0)
        {
            MArrayDataHandle outArrayHandle = dataBlock.outputValue(
                mOutSubDArrayAttr, &status);

            MDataHandle outHandle;

            for (unsigned int j = 0; j < subDSize; j++)
            {
                // these elements can be sparse if they have been deleted
                if (outArrayHandle.elementIndex() != j)
                {
                    continue;
                }

                outHandle = outArrayHandle.outputValue(&status);
                outArrayHandle.next();

                MObject obj = outHandle.data();
                if (obj.hasFn(MFn::kMesh))
                {
                    MFnMesh fnMesh(obj);
                    readSubD(mCurTime, fnMesh, obj, mData.mSubDList[j],
                        mSubDInitialized);
                    outHandle.set(obj);
                }
            }
            mSubDInitialized = true;
            outArrayHandle.setAllClean();
        }
        // for the case where we don't have any nodes, we want to make sure
        // to push out empty meshes on our connections, this can happen if
        // the input file was offlined, currently we only need to do this for
        // meshes as Nurbs, curves, and the other channels don't crash Maya
        else
        {
            MArrayDataHandle outArrayHandle = dataBlock.outputValue(
                mOutSubDArrayAttr, &status);

            if (outArrayHandle.elementCount() > 0)
            {
                do
                {
                    MDataHandle outHandle = outArrayHandle.outputValue();
                    MObject obj = outHandle.data();
                    if (obj.hasFn(MFn::kMesh))
                    {
                        MFloatPointArray emptyVerts;
                        MIntArray emptyCounts;
                        MIntArray emptyConnects;
                        MFnMesh emptyMesh;
                        emptyMesh.create(0, 0, emptyVerts, emptyCounts,
                            emptyConnects, obj);
                        outHandle.set(obj);
                    }
                }
                while (outArrayHandle.next() == MS::kSuccess);
            }
            mSubDInitialized = true;
            outArrayHandle.setAllClean();
        }
    }
    else if (plug == mOutPolyArrayAttr)
    {
        if (mOutRead[3])
        {
            // Reference the output to let EM know we are the writer
            // of the data. EM sets the output to holder and causes
            // race condition when evaluating fan-out destinations.
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutPolyArrayAttr, &status);
            const unsigned int elementCount = outArrayHandle.elementCount();
            for (unsigned int j = 0; j < elementCount; j++)
            {
                outArrayHandle.outputValue().data();
                outArrayHandle.next();
            }
            outArrayHandle.setAllClean();
            return MS::kSuccess;
        }

        mOutRead[3] = true;

        unsigned int polySize =
            static_cast<unsigned int>(mData.mPolyMeshList.size());

        if (polySize > 0)
        {
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutPolyArrayAttr, &status);

            MDataHandle outHandle;

            for (unsigned int j = 0; j < polySize; j++)
            {
                // these elements can be sparse if they have been deleted
                if (outArrayHandle.elementIndex() != j)
                {
                    continue;
                }

                outHandle = outArrayHandle.outputValue(&status);
                outArrayHandle.next();

                MObject obj = outHandle.data();
                if (obj.hasFn(MFn::kMesh))
                {
                    MFnMesh fnMesh(obj);
                    readPoly(mCurTime, fnMesh, obj, mData.mPolyMeshList[j],
                        mPolyInitialized);
                    outHandle.set(obj);
                }
            }
            mPolyInitialized = true;
            outArrayHandle.setAllClean();
        }
        // for the case where we don't have any nodes, we want to make sure
        // to push out empty meshes on our connections, this can happen if
        // the input file was offlined, currently we only need to do this for
        // meshes as Nurbs, curves, and the other channels don't crash Maya
        else
        {
            MArrayDataHandle outArrayHandle = dataBlock.outputValue(
                mOutPolyArrayAttr, &status);

            if (outArrayHandle.elementCount() > 0)
            {
                do
                {
                    MDataHandle outHandle = outArrayHandle.outputValue(&status);
                    MObject obj = outHandle.data();
                    if (obj.hasFn(MFn::kMesh))
                    {
                        MFloatPointArray emptyVerts;
                        MIntArray emptyCounts;
                        MIntArray emptyConnects;
                        MFnMesh emptyMesh;
                        emptyMesh.create(0, 0, emptyVerts, emptyCounts,
                            emptyConnects, obj);
                        outHandle.set(obj);
                    }
                }
                while (outArrayHandle.next() == MS::kSuccess);
            }
            mPolyInitialized = true;
            outArrayHandle.setAllClean();
        }
    }
    else if (plug == mOutCameraArrayAttr)
    {
        if (mOutRead[4])
        {
            dataBlock.setClean(plug);
            return MS::kSuccess;
        }

        mOutRead[4] = true;

        unsigned int cameraSize =
            static_cast<unsigned int>(mData.mCameraList.size());

        if (cameraSize > 0)
        {
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutCameraArrayAttr, &status);
            MPlug arrayPlug(thisMObject(), mOutCameraArrayAttr);
            double angleConversion = 1.0;

            switch (MAngle::uiUnit())
            {
                case MAngle::kRadians:
                    angleConversion = 0.017453292519943295;
                break;
                case MAngle::kAngMinutes:
                    angleConversion = 60.0;
                break;
                case MAngle::kAngSeconds:
                    angleConversion = 3600.0;
                break;
                default:
                break;
            }

            MDataHandle outHandle;
            unsigned int index = 0;

            for (unsigned int cameraIndex = 0; cameraIndex < cameraSize;
                cameraIndex++)
            {
                Alembic::AbcGeom::ICamera & cam =
                    mData.mCameraList[cameraIndex];
                std::vector<double> array;

                read(mCurTime, cam, array);

                for (unsigned int dataIndex = 0; dataIndex < array.size();
                    dataIndex++, index++)
                {
                    // skip over sparse elements
                    if (index != outArrayHandle.elementIndex())
                    {
                        continue;
                    }

                    outHandle = outArrayHandle.outputValue(&status);
                    outArrayHandle.next();

                    // not shutter angle index, so not an angle
                    if (dataIndex != 11)
                    {
                        outHandle.set(array[dataIndex]);
                    }
                    else
                    {
                        outHandle.set(array[dataIndex] * angleConversion);
                    }
                }  // for the per camera data handles
            }  // for each camera
            outArrayHandle.setAllClean();
        }
    }
    else if (plug == mOutNurbsSurfaceArrayAttr)
    {
        if (mOutRead[5])
        {
            // Reference the output to let EM know we are the writer
            // of the data. EM sets the output to holder and causes
            // race condition when evaluating fan-out destinations.
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutNurbsSurfaceArrayAttr, &status);
            const unsigned int elementCount = outArrayHandle.elementCount();
            for (unsigned int j = 0; j < elementCount; j++)
            {
                outArrayHandle.outputValue().data();
                outArrayHandle.next();
            }
            outArrayHandle.setAllClean();
            return MS::kSuccess;
        }

        mOutRead[5] = true;

        unsigned int nSurfaceSize =
            static_cast<unsigned int>(mData.mNurbsList.size());

        if (nSurfaceSize > 0)
        {
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutNurbsSurfaceArrayAttr, &status);

            MDataHandle outHandle;

            for (unsigned int j = 0; j < nSurfaceSize; j++)
            {
                // these elements can be sparse if they have been deleted
                if (outArrayHandle.elementIndex() != j)
                    continue;

                outHandle = outArrayHandle.outputValue(&status);
                outArrayHandle.next();

                MObject obj = outHandle.data();
                if (obj.hasFn(MFn::kNurbsSurface))
                {
                    readNurbs(mCurTime, mData.mNurbsList[j], obj);
                    outHandle.set(obj);
                }
            }
            outArrayHandle.setAllClean();
        }
    }
    else if (plug == mOutNurbsCurveGrpArrayAttr)
    {
        if (mOutRead[6])
        {
            // Reference the output to let EM know we are the writer
            // of the data. EM sets the output to holder and causes
            // race condition when evaluating fan-out destinations.
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutNurbsCurveGrpArrayAttr, &status);
            const unsigned int elementCount = outArrayHandle.elementCount();
            for (unsigned int j = 0; j < elementCount; j++)
            {
                outArrayHandle.outputValue().data();
                outArrayHandle.next();
            }
            outArrayHandle.setAllClean();
            return MS::kSuccess;
        }

        mOutRead[6] = true;

        unsigned int nCurveGrpSize =
            static_cast<unsigned int>(mData.mCurvesList.size());

        if (nCurveGrpSize > 0)
        {
            MArrayDataHandle outArrayHandle =
                dataBlock.outputValue(mOutNurbsCurveGrpArrayAttr, &status);
            MDataHandle outHandle;

            std::vector<MObject> curvesObj;
            for (unsigned int i = 0; i < nCurveGrpSize; ++i)
            {
                readCurves(mCurTime, mData.mCurvesList[i],
                    mData.mNumCurves[i], curvesObj);
            }

            std::size_t numChild = curvesObj.size();

            // not the best way to do this
            // only reading bunches of curves based on the connections would be
            // more efficient when there is a bunch of broken connections
            for (unsigned int i = 0; i < numChild; i++)
            {
                if (outArrayHandle.elementIndex() != i)
                {
                    continue;
                }

                outHandle = outArrayHandle.outputValue(&status);
                outArrayHandle.next();
                status = outHandle.set(curvesObj[i]);
            }

            outArrayHandle.setAllClean();
        }
    }
    else
    {
        return MS::kUnknownParameter;
    }

    dataBlock.setClean(plug);
    return status;
}
Exemple #29
0
void ZVision::cheatCodes(uint8 key) {
	Location loc = _scriptManager->getCurrentLocation();
	// Do not process cheat codes while in the game menus
	if (loc.world == 'g' && loc.room == 'j')
		return;

	pushKeyToCheatBuf(key);

	if (getGameId() == GID_GRANDINQUISITOR) {
		if (checkCode("IMNOTDEAF")) {
			// Unknown cheat
			_renderManager->showDebugMsg(Common::String::format("IMNOTDEAF cheat or debug, not implemented"));
		}

		if (checkCode("3100OPB")) {
			_renderManager->showDebugMsg(Common::String::format("Current location: %c%c%c%c",
			                                    _scriptManager->getStateValue(StateKey_World),
			                                    _scriptManager->getStateValue(StateKey_Room),
			                                    _scriptManager->getStateValue(StateKey_Node),
			                                    _scriptManager->getStateValue(StateKey_View)));
		}

		if (checkCode("KILLMENOW")) {
			_scriptManager->changeLocation('g', 'j', 'd', 'e', 0);
			_scriptManager->setStateValue(2201, 35);
		}

		if (checkCode("MIKESPANTS")) {
			_scriptManager->changeLocation('g', 'j', 't', 'm', 0);
		}

		// There are 3 more cheats in script files:
		// - "WHOAMI": gjcr.scr
		// - "HUISOK": hp1e.scr
		// - "EAT ME": uh1f.scr
	} else if (getGameId() == GID_NEMESIS) {
		if (checkCode("CHLOE")) {
			_scriptManager->changeLocation('t', 'm', '2', 'g', 0);
			_scriptManager->setStateValue(224, 1);
		}

		if (checkCode("77MASSAVE")) {
			_renderManager->showDebugMsg(Common::String::format("Current location: %c%c%c%c",
			                                    _scriptManager->getStateValue(StateKey_World),
			                                    _scriptManager->getStateValue(StateKey_Room),
			                                    _scriptManager->getStateValue(StateKey_Node),
			                                    _scriptManager->getStateValue(StateKey_View)));
		}

		if (checkCode("IDKFA")) {
			_scriptManager->changeLocation('t', 'w', '3', 'f', 0);
			_scriptManager->setStateValue(249, 1);
		}

		if (checkCode("309NEWDORMA")) {
			_scriptManager->changeLocation('g', 'j', 'g', 'j', 0);
		}

		if (checkCode("HELLOSAILOR")) {
			Audio::AudioStream *soundStream;
			if (loc == "vb10") {
				soundStream = makeRawZorkStream("v000hpta.raw", this);
			} else {
				soundStream = makeRawZorkStream("v000hnta.raw", this);
			}
			Audio::SoundHandle handle;
			_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream);
		}
	}

	if (checkCode("FRAME")) {
		Common::String fpsStr = Common::String::format("FPS: %d", getFPS());
		_renderManager->showDebugMsg(fpsStr);
	}

	if (checkCode("COMPUTERARCH"))
		_renderManager->showDebugMsg("COMPUTERARCH: var-viewer not implemented");

	// This cheat essentially toggles the GOxxxx cheat below
	if (checkCode("XYZZY"))
		_scriptManager->setStateValue(StateKey_DebugCheats, 1 - _scriptManager->getStateValue(StateKey_DebugCheats));

	if (_scriptManager->getStateValue(StateKey_DebugCheats) == 1)
		if (checkCode("GO????"))
			_scriptManager->changeLocation(getBufferedKey(3),
			                               getBufferedKey(2),
			                               getBufferedKey(1),
			                               getBufferedKey(0), 0);

	// Show the Venus screen when "?" or "/" is pressed while inside the temple world
	if (_scriptManager->getStateValue(StateKey_VenusEnable) == 1)
		if (getBufferedKey(0) == 0xBF && _scriptManager->getStateValue(StateKey_World) == 't')
			_scriptManager->changeLocation('g', 'j', 'h', 'e', 0);
}
Exemple #30
0
void ZVision::processEvents() {
	while (_eventMan->pollEvent(_event)) {
		switch (_event.type) {
		case Common::EVENT_LBUTTONDOWN:
			_cursorManager->cursorDown(true);
			_scriptManager->setStateValue(StateKey_LMouse, 1);
			_menu->onMouseDown(_event.mouse);
			_scriptManager->addEvent(_event);
			break;

		case Common::EVENT_LBUTTONUP:
			_cursorManager->cursorDown(false);
			_scriptManager->setStateValue(StateKey_LMouse, 0);
			_menu->onMouseUp(_event.mouse);
			_scriptManager->addEvent(_event);
			break;

		case Common::EVENT_RBUTTONDOWN:
			_cursorManager->cursorDown(true);
			_scriptManager->setStateValue(StateKey_RMouse, 1);

			if (getGameId() == GID_NEMESIS)
				_scriptManager->inventoryCycle();
			break;

		case Common::EVENT_RBUTTONUP:
			_cursorManager->cursorDown(false);
			_scriptManager->setStateValue(StateKey_RMouse, 0);
			break;

		case Common::EVENT_MOUSEMOVE:
			onMouseMove(_event.mouse);
			break;

		case Common::EVENT_KEYDOWN: {
			switch (_event.kbd.keycode) {
			case Common::KEYCODE_d:
				if (_event.kbd.hasFlags(Common::KBD_CTRL)) {
					// Start the debugger
					_console->attach();
					_console->onFrame();
				}
				break;

			case Common::KEYCODE_LEFT:
			case Common::KEYCODE_RIGHT:
				if (_renderManager->getRenderTable()->getRenderState() == RenderTable::PANORAMA)
					_keyboardVelocity = (_event.kbd.keycode == Common::KEYCODE_LEFT ?
					                     -_scriptManager->getStateValue(StateKey_KbdRotateSpeed) :
					                     _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2;
				break;

			case Common::KEYCODE_UP:
			case Common::KEYCODE_DOWN:
				if (_renderManager->getRenderTable()->getRenderState() == RenderTable::TILT)
					_keyboardVelocity = (_event.kbd.keycode == Common::KEYCODE_UP ?
					                     -_scriptManager->getStateValue(StateKey_KbdRotateSpeed) :
					                     _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2;
				break;

			case Common::KEYCODE_F10: {
				Common::String fpsStr = Common::String::format("FPS: %d", getFPS());
				_renderManager->showDebugMsg(fpsStr);
				}
				break;
			default:
				break;
			}

			uint8 vkKey = getZvisionKey(_event.kbd.keycode);

			_scriptManager->setStateValue(StateKey_KeyPress, vkKey);

			_scriptManager->addEvent(_event);
			shortKeys(_event);
			cheatCodes(vkKey);
		}
		break;
		case Common::EVENT_KEYUP:
			_scriptManager->addEvent(_event);
			switch (_event.kbd.keycode) {
			case Common::KEYCODE_LEFT:
			case Common::KEYCODE_RIGHT:
				if (_renderManager->getRenderTable()->getRenderState() == RenderTable::PANORAMA)
					_keyboardVelocity = 0;
				break;
			case Common::KEYCODE_UP:
			case Common::KEYCODE_DOWN:
				if (_renderManager->getRenderTable()->getRenderState() == RenderTable::TILT)
					_keyboardVelocity = 0;
				break;
			default:
				break;
			}
			break;
		default:
			break;
		}
	}
}