the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 143 lines 3.6 kB view raw
1/* SCE CONFIDENTIAL 2PlayStation(R)3 Programmer Tool Runtime Library 430.001 3* Copyright (C) 2007 Sony Computer Entertainment Inc. 4* All Rights Reserved. 5*/ 6 7/* common headers */ 8#include <stdint.h> 9#include <stdlib.h> 10#include <string.h> 11#include <spu_intrinsics.h> 12#include <cell/spurs.h> 13#include <spu_printf.h> 14#include <cell/dma.h> 15#include <cell/spurs/job_queue.h> 16 17#include "..\Common\DmaData.h" 18 19#include "GameRenderer_updateLightTexture.h" 20 21static const bool sc_verbose = false; 22 23CellSpursJobContext2* g_pSpursJobContext; 24 25 26 27 28void updateLightTexture(GameRenderer_updateLightTexture_dataIn& dataIn) 29{ 30 // 4J - we've added separate light textures for all dimensions, and this loop to update them all here 31 for(int j = 0; j < 3; j++ ) 32 { 33 int lightPixels[16*16]; 34 GameRenderer_updateLightTexture_dataIn::LevelData& levelDataIn = dataIn.m_levelData[j]; 35 if (levelDataIn.m_valid == false) continue; 36 for (int i = 0; i < 256; i++) 37 { 38 float darken = levelDataIn.m_skyDarken * 0.95f + 0.05f; 39 float sky = levelDataIn.m_brightnessRamp[i / 16] * darken; 40 float block = levelDataIn.m_brightnessRamp[i % 16] * (dataIn.blr * 0.1f + 1.5f); 41 42 if (levelDataIn.m_lightningBoltTime > 0) 43 { 44 sky = levelDataIn.m_brightnessRamp[i / 16]; 45 } 46 47 float rs = sky * (levelDataIn.m_skyDarken * 0.65f + 0.35f); 48 float gs = sky * (levelDataIn.m_skyDarken * 0.65f + 0.35f); 49 float bs = sky; 50 51 /* 52 * float dr = darken; dr = dr - dr * dr; System.out.println(dr); if (dr > 0) { 53 * gs += dr * 0.5f; rs += dr; } 54 */ 55 56 // rs = gs = bs; 57 58 float rb = block; 59 float gb = block * ((block * 0.6f + 0.4f) * 0.6f + 0.4f); 60 float bb = block * ((block * block) * 0.6f + 0.4f); 61 62 float _r = (rs + rb); 63 float _g = (gs + gb); 64 float _b = (bs + bb); 65 66 _r = _r * 0.96f + 0.03f; 67 _g = _g * 0.96f + 0.03f; 68 _b = _b * 0.96f + 0.03f; 69 70 if (levelDataIn.m_dimensionID == 1) 71 { 72 _r = (0.22f + rb * 0.75f); 73 _g = (0.28f + gb * 0.75f); 74 _b = (0.25f + bb * 0.75f); 75 } 76 77 float brightness = 0.0f; // 4J - TODO - was mc->options->gamma; 78 if (_r > 1) _r = 1; 79 if (_g > 1) _g = 1; 80 if (_b > 1) _b = 1; 81 82 float ir = 1 - _r; 83 float ig = 1 - _g; 84 float ib = 1 - _b; 85 ir = 1 - (ir * ir * ir * ir); 86 ig = 1 - (ig * ig * ig * ig); 87 ib = 1 - (ib * ib * ib * ib); 88 _r = _r * (1 - brightness) + ir * brightness; 89 _g = _g * (1 - brightness) + ig * brightness; 90 _b = _b * (1 - brightness) + ib * brightness; 91 92 93 _r = _r * 0.96f + 0.03f; 94 _g = _g * 0.96f + 0.03f; 95 _b = _b * 0.96f + 0.03f; 96 97 98 if (_r > 1) _r = 1; 99 if (_g > 1) _g = 1; 100 if (_b > 1) _b = 1; 101 if (_r < 0) _r = 0; 102 if (_g < 0) _g = 0; 103 if (_b < 0) _b = 0; 104 105 int a = 255; 106 int r = (int) (_r * 255); 107 int g = (int) (_g * 255); 108 int b = (int) (_b * 255); 109 110 lightPixels[i] = r << 24 | g << 16 | b << 8 | a; 111 } 112 DmaData_SPU::putAndWait(lightPixels, (uintptr_t)levelDataIn.m_lightPixelsOutput, 16*16*sizeof(int)); 113 } 114} 115 116 117 118 119 120 121 122 123 124void cellSpursJobQueueMain(CellSpursJobContext2 *pContext, CellSpursJob256 *pJob) 125{ 126// CellSpursTaskId idTask = cellSpursGetTaskId(); 127 unsigned int idSpu = cellSpursGetCurrentSpuId(); 128 129 if(sc_verbose) 130 spu_printf("GameRenderer_updateLightTexture [SPU#%u] start\n", idSpu); 131 132 g_pSpursJobContext = pContext; 133 134 uint32_t eaDataIn = pJob->workArea.userData[0]; 135 136 GameRenderer_updateLightTexture_dataIn dataIn; 137 DmaData_SPU::getAndWait(&dataIn, eaDataIn, sizeof(GameRenderer_updateLightTexture_dataIn)); 138 updateLightTexture(dataIn); 139 140 if(sc_verbose) 141 spu_printf("GameRenderer_updateLightTexture [SPU#%u] exit\n", idSpu); 142} 143