Esempio n. 1
0
/*
==================
CL_DeltaFrame

A valid frame has been parsed.
==================
*/
void CL_DeltaFrame(void)
{
    centity_t           *ent;
    entity_state_t      *state;
    int                 i, j;
    int                 framenum;

    // getting a valid frame message ends the connection process
    if (cls.state == ca_precached)
        set_active_state();

    // set server time
    framenum = cl.frame.number - cl.serverdelta;
    cl.servertime = framenum * CL_FRAMETIME;
#if USE_FPS
    cl.keyservertime = (framenum / cl.framediv) * BASE_FRAMETIME;
#endif

    // rebuild the list of solid entities for this frame
    cl.numSolidEntities = 0;

    // initialize position of the player's own entity from playerstate.
    // this is needed in situations when player entity is invisible, but
    // server sends an effect referencing it's origin (such as MZ_LOGIN, etc)
    ent = &cl_entities[cl.frame.clientNum + 1];
    Com_PlayerToEntityState(&cl.frame.ps, &ent->current);

    for (i = 0; i < cl.frame.numEntities; i++) {
        j = (cl.frame.firstEntity + i) & PARSE_ENTITIES_MASK;
        state = &cl.entityStates[j];

        // set current and prev
        entity_update(state);

        // fire events
        entity_event(state->number);
    }

    if (cls.demo.recording && !cls.demo.paused && !cls.demo.seeking && CL_FRAMESYNC) {
        CL_EmitDemoFrame();
    }

    if (cls.demo.playback) {
        // this delta has nothing to do with local viewangles,
        // clear it to avoid interfering with demo freelook hack
        VectorClear(cl.frame.ps.pmove.delta_angles);
    }

    if (cl.oldframe.ps.pmove.pm_type != cl.frame.ps.pmove.pm_type) {
        IN_Activate();
    }

    player_update(&cl.oldframe, &cl.frame, 1);

#if USE_FPS
    if (CL_FRAMESYNC)
        player_update(&cl.oldkeyframe, &cl.keyframe, cl.framediv);
#endif

    CL_CheckPredictionError();

    SCR_SetCrosshairColor();
}
Esempio n. 2
0
static void
input()
{
	SDL_PumpEvents();

	vec3_t inputvec = {0,0,0};

	const uint8_t *keyboard = SDL_GetKeyboardState(0);

	if(takeinput)
	{
		if(state_has_controller() && usecontroller)
		{
			inputvec.x = leftstick.x;
			inputvec.z = leftstick.y;
			rotx += JOYSTICK_SENSITIVITY_LOOK*rightstick.x*dt/1000.0;
			roty -= JOYSTICK_SENSITIVITY_LOOK*rightstick.y*dt/1000.0;
		} else {
			if(keyboard[SDL_SCANCODE_W])
				inputvec.z -= 1;
			if(keyboard[SDL_SCANCODE_A])
				inputvec.x -= 1;
			if(keyboard[SDL_SCANCODE_S])
				inputvec.z += 1;
			if(keyboard[SDL_SCANCODE_D])
				inputvec.x += 1;
			if(keyboard[SDL_SCANCODE_LSHIFT])
				inputvec.y -= 1;
			if(keyboard[SDL_SCANCODE_SPACE])
				inputvec.y += 1;

			int mousex, mousey;
			SDL_GetMouseState(&mousex, &mousey);
			state_mouse_center();
			double deltamousex = mousex - windoww/2;
			double deltamousey = mousey - windowh/2;

			rotx += MOUSE_SENSITIVITY*deltamousex;
			roty -= MOUSE_SENSITIVITY*deltamousey;

			roty = roty > M_PI/2-.005 ? M_PI/2-.005 : roty;
			roty = roty < -M_PI/2+.005 ? -M_PI/2+.005 : roty;

			rotx = rotx > M_PI*2 ? rotx - M_PI*2: rotx;
			rotx = rotx < -M_PI*2 ? rotx + M_PI*2: rotx;
		}
	}

	forwardcamera.x = sin(rotx) * cos(roty);
	forwardcamera.y = sin(roty);
	forwardcamera.z = -cos(rotx) * cos(roty);

	vec3_t rotatevec;
	rotatevec.x = cos(rotx)*inputvec.x - sin(rotx)*inputvec.z;
	rotatevec.z = sin(rotx)*inputvec.x + cos(rotx)*inputvec.z;
	rotatevec.y = inputvec.y;

	if(dt < 500)
	{
		if(flying)
		{
			rotatevec.x *= PLAYER_FLY_SPEED * dt / 1000.0;
			rotatevec.y *= PLAYER_FLY_SPEED * dt / 1000.0;
			rotatevec.z *= PLAYER_FLY_SPEED * dt / 1000.0;
			entity_move(pos, &rotatevec);
		} else {
			rotatevec.x *= PLAYER_WALK_MAX_FORCE;
			rotatevec.y = 0;
			rotatevec.z *= PLAYER_WALK_MAX_FORCE;
			entity_update(pos, &rotatevec, dt/1000.0);
		}
	}

	if(keyboard[SDL_SCANCODE_R])
	{
		block_t b;
		b.id = SAND;
		b.metadata.number = SIM_WATER_LEVELS;
		world_ray_set(&headpos, &forwardcamera, b, 1, 1, 1000);
	}
	if(keyboard[SDL_SCANCODE_E])
	{
		world_ray_del(&headpos, &forwardcamera, 1, 1000);
	}
	if(keyboard[SDL_SCANCODE_X])
	{
		vec3_t dir;
		for(dir.x = -1; dir.x < 1; dir.x += .3)
		for(dir.y = -1; dir.y < 0; dir.y += .3)
		for(dir.z = -1; dir.z < 1; dir.z += .3)
			world_ray_del(&headpos, &dir, 1, 50);
	}

	headpos = *posptr;
	headpos.y += PLAYER_EYEHEIGHT;
}