the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 519 lines 14 kB view raw
1#include "stdafx.h" 2#include "..\..\Minecraft.h" 3#include "..\..\ScreenSizeCalculator.h" 4#include "..\..\EntityRenderDispatcher.h" 5#include "..\..\PlayerRenderer.h" 6#include "..\..\HumanoidModel.h" 7#include "..\..\Lighting.h" 8#include "..\..\ModelPart.h" 9#include "..\..\Options.h" 10#include "..\..\..\Minecraft.World\net.minecraft.world.entity.player.h" 11#include "UIControl_PlayerSkinPreview.h" 12 13//#define SKIN_PREVIEW_BOB_ANIM 14#define SKIN_PREVIEW_WALKING_ANIM 15 16UIControl_PlayerSkinPreview::UIControl_PlayerSkinPreview() 17{ 18 UIControl::setControlType(UIControl::ePlayerSkinPreview); 19 m_bDirty = FALSE; 20 m_fScale = 1.0f; 21 m_fAlpha = 1.0f; 22 23 Minecraft *pMinecraft=Minecraft::GetInstance(); 24 25 ScreenSizeCalculator ssc(pMinecraft->options, pMinecraft->width_phys, pMinecraft->height_phys); 26 m_fScreenWidth=(float)pMinecraft->width_phys; 27 m_fRawWidth=(float)ssc.rawWidth; 28 m_fScreenHeight=(float)pMinecraft->height_phys; 29 m_fRawHeight=(float)ssc.rawHeight; 30 31 m_customTextureUrl = L"default"; 32 m_backupTexture = TN_MOB_CHAR; 33 m_capeTextureUrl = L""; 34 35 m_yRot = 0; 36 m_xRot = 0; 37 38 m_swingTime = 0.0f; 39 m_bobTick = 0.0f; 40 m_walkAnimSpeedO = 0.0f; 41 m_walkAnimSpeed = 0.0f; 42 m_walkAnimPos = 0.0f; 43 44 m_bAutoRotate = false; 45 m_bRotatingLeft = false; 46 47 m_incXRot = false; 48 m_decXRot = false; 49 m_incYRot = false; 50 m_decYRot = false; 51 52 m_currentAnimation = e_SkinPreviewAnimation_Walking; 53 54 m_fTargetRotation = 0.0f; 55 m_fOriginalRotation = 0.0f; 56 m_framesAnimatingRotation = 0; 57 m_bAnimatingToFacing = false; 58 m_pvAdditionalModelParts=NULL; 59 m_uiAnimOverrideBitmask=0L; 60} 61 62void UIControl_PlayerSkinPreview::tick() 63{ 64 UIControl::tick(); 65 66 if( m_bAnimatingToFacing ) 67 { 68 ++m_framesAnimatingRotation; 69 m_yRot = m_fOriginalRotation + m_framesAnimatingRotation * ( (m_fTargetRotation - m_fOriginalRotation) / CHANGING_SKIN_FRAMES ); 70 71 //if(m_framesAnimatingRotation == CHANGING_SKIN_FRAMES) m_bAnimatingToFacing = false; 72 } 73 else 74 { 75 if( m_incXRot ) IncrementXRotation(); 76 if( m_decXRot ) DecrementXRotation(); 77 if( m_incYRot ) IncrementYRotation(); 78 if( m_decYRot ) DecrementYRotation(); 79 80 if(m_bAutoRotate) 81 { 82 ++m_rotateTick; 83 84 if(m_rotateTick%4==0) 85 { 86 if(m_yRot >= LOOK_LEFT_EXTENT) 87 { 88 m_bRotatingLeft = false; 89 } 90 else if(m_yRot <= LOOK_RIGHT_EXTENT) 91 { 92 m_bRotatingLeft = true; 93 } 94 95 if(m_bRotatingLeft) 96 { 97 IncrementYRotation(); 98 } 99 else 100 { 101 DecrementYRotation(); 102 } 103 } 104 } 105 } 106} 107 108void UIControl_PlayerSkinPreview::SetTexture(const wstring &url, TEXTURE_NAME backupTexture) 109{ 110 m_customTextureUrl = url; 111 m_backupTexture = backupTexture; 112 113 unsigned int uiAnimOverrideBitmask = Player::getSkinAnimOverrideBitmask( app.getSkinIdFromPath(m_customTextureUrl) ); 114 115 if(app.GetGameSettings(eGameSetting_CustomSkinAnim)==0 ) 116 { 117 // We have a force animation for some skins (claptrap) 118 // 4J-PB - treat all the eAnim_Disable flags as a force anim 119 120 if((uiAnimOverrideBitmask & HumanoidModel::m_staticBitmaskIgnorePlayerCustomAnimSetting)!=0) 121 { 122 m_uiAnimOverrideBitmask=uiAnimOverrideBitmask; 123 } 124 else 125 { 126 m_uiAnimOverrideBitmask=0; 127 } 128 } 129 else 130 { 131 m_uiAnimOverrideBitmask = uiAnimOverrideBitmask; 132 } 133 134 m_pvAdditionalModelParts=app.GetAdditionalModelParts(app.getSkinIdFromPath(m_customTextureUrl)); 135} 136 137void UIControl_PlayerSkinPreview::SetFacing(ESkinPreviewFacing facing, bool bAnimate /*= false*/) 138{ 139 switch(facing) 140 { 141 case e_SkinPreviewFacing_Forward: 142 m_fTargetRotation = 0; 143 m_bRotatingLeft = true; 144 break; 145 case e_SkinPreviewFacing_Left: 146 m_fTargetRotation = LOOK_LEFT_EXTENT; 147 m_bRotatingLeft = false; 148 break; 149 case e_SkinPreviewFacing_Right: 150 m_fTargetRotation = LOOK_RIGHT_EXTENT; 151 m_bRotatingLeft = true; 152 break; 153 } 154 155 if(!bAnimate) 156 { 157 m_yRot = m_fTargetRotation; 158 m_bAnimatingToFacing = false; 159 } 160 else 161 { 162 m_fOriginalRotation = m_yRot; 163 m_bAnimatingToFacing = true; 164 m_framesAnimatingRotation = 0; 165 } 166} 167 168void UIControl_PlayerSkinPreview::CycleNextAnimation() 169{ 170 m_currentAnimation = (ESkinPreviewAnimations)(m_currentAnimation + 1); 171 if(m_currentAnimation >= e_SkinPreviewAnimation_Count) m_currentAnimation = e_SkinPreviewAnimation_Walking; 172 173 m_swingTime = 0.0f; 174} 175 176void UIControl_PlayerSkinPreview::CyclePreviousAnimation() 177{ 178 m_currentAnimation = (ESkinPreviewAnimations)(m_currentAnimation - 1); 179 if(m_currentAnimation < e_SkinPreviewAnimation_Walking) m_currentAnimation = (ESkinPreviewAnimations)(e_SkinPreviewAnimation_Count - 1); 180 181 m_swingTime = 0.0f; 182} 183 184void UIControl_PlayerSkinPreview::render(IggyCustomDrawCallbackRegion *region) 185{ 186 Minecraft *pMinecraft=Minecraft::GetInstance(); 187 188 glEnable(GL_RESCALE_NORMAL); 189 glEnable(GL_COLOR_MATERIAL); 190 glPushMatrix(); 191 192 float width = region->x1 - region->x0; 193 float height = region->y1 - region->y0; 194 float xo = width/2; 195 float yo = height; 196 197 glTranslatef(xo, yo - 3.5f, 50.0f); 198 //glTranslatef(120.0f, 294, 0.0f); 199 200 float ss; 201 202 // Base scale on height of this control 203 // Potentially we might want separate x & y scales here 204 ss = width / (m_fScreenWidth / m_fScreenHeight); 205 206 glScalef(-ss, ss, ss); 207 glRotatef(180, 0, 0, 1); 208 209 //glRotatef(45 + 90, 0, 1, 0); 210 Lighting::turnOn(); 211 //glRotatef(-45 - 90, 0, 1, 0); 212 213 glRotatef(-(float)m_xRot, 1, 0, 0); 214 215 // 4J Stu - Turning on hideGui while we do this stops the name rendering in split-screen 216 bool wasHidingGui = pMinecraft->options->hideGui; 217 pMinecraft->options->hideGui = true; 218 219 //EntityRenderDispatcher::instance->render(pMinecraft->localplayers[0], 0, 0, 0, 0, 1); 220 EntityRenderer *renderer = EntityRenderDispatcher::instance->getRenderer(eTYPE_LOCALPLAYER); 221 if (renderer != NULL) 222 { 223 // 4J-PB - any additional parts to turn on for this player (skin dependent) 224 //vector<ModelPart *> *pAdditionalModelParts=mob->GetAdditionalModelParts(); 225 226 if(m_pvAdditionalModelParts && m_pvAdditionalModelParts->size()!=0) 227 { 228 for(AUTO_VAR(it, m_pvAdditionalModelParts->begin()); it != m_pvAdditionalModelParts->end(); ++it) 229 { 230 ModelPart *pModelPart=*it; 231 232 pModelPart->visible=true; 233 } 234 } 235 236 render(renderer,0,0,0,0,1); 237 //renderer->postRender(entity, x, y, z, rot, a); 238 239 // hide the additional parts 240 if(m_pvAdditionalModelParts && m_pvAdditionalModelParts->size()!=0) 241 { 242 for(AUTO_VAR(it, m_pvAdditionalModelParts->begin()); it != m_pvAdditionalModelParts->end(); ++it) 243 { 244 ModelPart *pModelPart=*it; 245 246 pModelPart->visible=false; 247 } 248 } 249 } 250 251 pMinecraft->options->hideGui = wasHidingGui; 252 253 glPopMatrix(); 254 Lighting::turnOff(); 255 glDisable(GL_RESCALE_NORMAL); 256} 257 258// 4J Stu - Modified version of MobRenderer::render that does not require an actual entity 259void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, double y, double z, float rot, float a) 260{ 261 glPushMatrix(); 262 glDisable(GL_CULL_FACE); 263 264 HumanoidModel *model = (HumanoidModel *)renderer->getModel(); 265 266 //getAttackAnim(mob, a); 267 //if (armor != NULL) armor->attackTime = model->attackTime; 268 //model->riding = mob->isRiding(); 269 //if (armor != NULL) armor->riding = model->riding; 270 271 // 4J Stu - Remember to reset these values once the rendering is done if you add another one 272 model->attackTime = 0; 273 model->sneaking = false; 274 model->holdingRightHand = false; 275 model->holdingLeftHand = false; 276 model->idle = false; 277 model->eating = false; 278 model->eating_swing = 0; 279 model->eating_t = 0; 280 model->young = false; 281 model->riding = false; 282 283 model->m_uiAnimOverrideBitmask = m_uiAnimOverrideBitmask; 284 285 if( !m_bAnimatingToFacing ) 286 { 287 switch( m_currentAnimation ) 288 { 289 case e_SkinPreviewAnimation_Sneaking: 290 model->sneaking = true; 291 break; 292 case e_SkinPreviewAnimation_Attacking: 293 model->holdingRightHand = true; 294 m_swingTime++; 295 if (m_swingTime >= (Player::SWING_DURATION * 3) ) 296 { 297 m_swingTime = 0; 298 } 299 model->attackTime = m_swingTime / (float) (Player::SWING_DURATION * 3); 300 break; 301 default: 302 break; 303 }; 304 } 305 306 307 float bodyRot = m_yRot; //(mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a); 308 float headRot = m_yRot; //(mob->yRotO + (mob->yRot - mob->yRotO) * a); 309 float headRotx = 0; //(mob->xRotO + (mob->xRot - mob->xRotO) * a); 310 311 //setupPosition(mob, x, y, z); 312 // is equivalent to 313 glTranslatef((float) x, (float) y, (float) z); 314 315 //float bob = getBob(mob, a); 316#ifdef SKIN_PREVIEW_BOB_ANIM 317 float bob = (m_bobTick + a)/2; 318 319 ++m_bobTick; 320 if(m_bobTick>=360*2) m_bobTick = 0; 321#else 322 float bob = 0.0f; 323#endif 324 325 //setupRotations(mob, bob, bodyRot, a); 326 // is equivalent to 327 glRotatef(180 - bodyRot, 0, 1, 0); 328 329 float _scale = 1 / 16.0f; 330 glEnable(GL_RESCALE_NORMAL); 331 glScalef(-1, -1, 1); 332 333 //scale(mob, a); 334 // is equivalent to 335 float s = 15 / 16.0f; 336 glScalef(s, s, s); 337 338 // 4J - TomK - pull up character a bit more to make sure extra geo around feet doesn't cause rendering problems on PSVita 339#ifdef __PSVITA__ 340 glTranslatef(0, -24 * _scale - 1.0f / 16.0f, 0); 341#else 342 glTranslatef(0, -24 * _scale - 0.125f / 16.0f, 0); 343#endif 344 345#ifdef SKIN_PREVIEW_WALKING_ANIM 346 m_walkAnimSpeedO = m_walkAnimSpeed; 347 m_walkAnimSpeed += (0.1f - m_walkAnimSpeed) * 0.4f; 348 m_walkAnimPos += m_walkAnimSpeed; 349 float ws = m_walkAnimSpeedO + (m_walkAnimSpeed - m_walkAnimSpeedO) * a; 350 float wp = m_walkAnimPos - m_walkAnimSpeed * (1 - a); 351#else 352 float ws = 0; 353 float wp = 0; 354#endif 355 356 if (ws > 1) ws = 1; 357 358 MemSect(31); 359 bindTexture(m_customTextureUrl, m_backupTexture); 360 MemSect(0); 361 glEnable(GL_ALPHA_TEST); 362 363 //model->prepareMobModel(mob, wp, ws, a); 364 model->render(nullptr, wp, ws, bob, headRot - bodyRot, headRotx, _scale, true); 365 /*for (int i = 0; i < MAX_ARMOR_LAYERS; i++) 366 { 367 if (prepareArmor(mob, i, a)) 368 { 369 armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, true); 370 glDisable(GL_BLEND); 371 glEnable(GL_ALPHA_TEST); 372 } 373 }*/ 374 375 //additionalRendering(mob, a); 376 if (bindTexture(m_capeTextureUrl, L"" )) 377 { 378 glPushMatrix(); 379 glTranslatef(0, 0, 2 / 16.0f); 380 381 double xd = 0;//(mob->xCloakO + (mob->xCloak - mob->xCloakO) * a) - (mob->xo + (mob->x - mob->xo) * a); 382 double yd = 0;//(mob->yCloakO + (mob->yCloak - mob->yCloakO) * a) - (mob->yo + (mob->y - mob->yo) * a); 383 double zd = 0;//(mob->zCloakO + (mob->zCloak - mob->zCloakO) * a) - (mob->zo + (mob->z - mob->zo) * a); 384 385 float yr = 1;//mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a; 386 387 double xa = sin(yr * PI / 180); 388 double za = -cos(yr * PI / 180); 389 390 float flap = (float) yd * 10; 391 if (flap < -6) flap = -6; 392 if (flap > 32) flap = 32; 393 float lean = (float) (xd * xa + zd * za) * 100; 394 float lean2 = (float) (xd * za - zd * xa) * 100; 395 if (lean < 0) lean = 0; 396 397 //float pow = 1;//mob->oBob + (bob - mob->oBob) * a; 398 399 flap += 1;//sin((mob->walkDistO + (mob->walkDist - mob->walkDistO) * a) * 6) * 32 * pow; 400 if (model->sneaking) 401 { 402 flap += 25; 403 } 404 405 glRotatef(6.0f + lean / 2 + flap, 1, 0, 0); 406 glRotatef(lean2 / 2, 0, 0, 1); 407 glRotatef(-lean2 / 2, 0, 1, 0); 408 glRotatef(180, 0, 1, 0); 409 model->renderCloak(1 / 16.0f,true); 410 glPopMatrix(); 411 } 412 /* 413 float br = mob->getBrightness(a); 414 int overlayColor = getOverlayColor(mob, br, a); 415 416 if (((overlayColor >> 24) & 0xff) > 0 || mob->hurtTime > 0 || mob->deathTime > 0) 417 { 418 glDisable(GL_TEXTURE_2D); 419 glDisable(GL_ALPHA_TEST); 420 glEnable(GL_BLEND); 421 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 422 glDepthFunc(GL_EQUAL); 423 424 // 4J - changed these renders to not use the compiled version of their models, because otherwise the render states set 425 // about (in particular the depth & alpha test) don't work with our command buffer versions 426 if (mob->hurtTime > 0 || mob->deathTime > 0) 427 { 428 glColor4f(br, 0, 0, 0.4f); 429 model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); 430 for (int i = 0; i < MAX_ARMOR_LAYERS; i++) 431 { 432 if (prepareArmorOverlay(mob, i, a)) 433 { 434 glColor4f(br, 0, 0, 0.4f); 435 armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); 436 } 437 } 438 } 439 440 if (((overlayColor >> 24) & 0xff) > 0) 441 { 442 float r = ((overlayColor >> 16) & 0xff) / 255.0f; 443 float g = ((overlayColor >> 8) & 0xff) / 255.0f; 444 float b = ((overlayColor) & 0xff) / 255.0f; 445 float aa = ((overlayColor >> 24) & 0xff) / 255.0f; 446 glColor4f(r, g, b, aa); 447 model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); 448 for (int i = 0; i < MAX_ARMOR_LAYERS; i++) 449 { 450 if (prepareArmorOverlay(mob, i, a)) 451 { 452 glColor4f(r, g, b, aa); 453 armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); 454 } 455 } 456 } 457 458 glDepthFunc(GL_LEQUAL); 459 glDisable(GL_BLEND); 460 glEnable(GL_ALPHA_TEST); 461 glEnable(GL_TEXTURE_2D); 462 } 463 */ 464 glDisable(GL_RESCALE_NORMAL); 465 466 glEnable(GL_CULL_FACE); 467 468 glPopMatrix(); 469 470 MemSect(31); 471 //renderName(mob, x, y, z); 472 MemSect(0); 473 474 // Reset the model values to stop the changes we made here affecting anything in game (like the player hand render) 475 model->attackTime = 0; 476 model->sneaking = false; 477 model->holdingRightHand = false; 478 model->holdingLeftHand = false; 479} 480 481bool UIControl_PlayerSkinPreview::bindTexture(const wstring& urlTexture, int backupTexture) 482{ 483 Textures *t = Minecraft::GetInstance()->textures; 484 485 // 4J-PB - no http textures on the xbox, mem textures instead 486 487 //int id = t->loadHttpTexture(urlTexture, backupTexture); 488 int id = t->loadMemTexture(urlTexture, backupTexture); 489 490 if (id >= 0) 491 { 492 t->bind(id); 493 return true; 494 } 495 else 496 { 497 return false; 498 } 499} 500 501bool UIControl_PlayerSkinPreview::bindTexture(const wstring& urlTexture, const wstring& backupTexture) 502{ 503 Textures *t = Minecraft::GetInstance()->textures; 504 505 // 4J-PB - no http textures on the xbox, mem textures instead 506 507 //int id = t->loadHttpTexture(urlTexture, backupTexture); 508 int id = t->loadMemTexture(urlTexture, backupTexture); 509 510 if (id >= 0) 511 { 512 t->bind(id); 513 return true; 514 } 515 else 516 { 517 return false; 518 } 519}