the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "Minecraft.h"
3#include "Minimap.h"
4#include "Font.h"
5#include "Options.h"
6#include "Textures.h"
7#include "Tesselator.h"
8#include "..\Minecraft.World\net.minecraft.world.level.saveddata.h"
9#include "..\Minecraft.World\net.minecraft.world.level.material.h"
10
11#ifdef __ORBIS__
12short Minimap::LUT[256]; // 4J added
13#else
14int Minimap::LUT[256]; // 4J added
15#endif
16bool Minimap::genLUT = true; // 4J added
17
18Minimap::Minimap(Font *font, Options *options, Textures *textures, bool optimised)
19{
20#ifdef __PS3__
21 // we're using the RSX now to upload textures to vram, so we need the main ram textures allocated from io space
22 this->pixels = intArray((int*)RenderManager.allocIOMem(w*h*sizeof(int)), 16*16);
23
24#elif defined __ORBIS__
25 this->pixels = shortArray(w*h);
26#else
27 this->pixels = intArray(w*h);
28#endif
29 this->options = options;
30 this->font = font;
31 BufferedImage *img = new BufferedImage(w, h, BufferedImage::TYPE_INT_ARGB);
32#ifdef __ORBIS__
33 mapTexture = textures->getTexture(img, C4JRender::TEXTURE_FORMAT_RxGyBzAw5551, false ); // 4J - make sure we aren't mipmapping as we never set the data for mipmaps
34#else
35 mapTexture = textures->getTexture(img, C4JRender::TEXTURE_FORMAT_RxGyBzAw, false ); // 4J - make sure we aren't mipmapping as we never set the data for mipmaps
36#endif
37 delete img;
38 for (int i = 0; i < w * h; i++)
39 {
40 pixels[i] = 0x00000000;
41 }
42
43 // 4J added - generate the colour mapping that we'll be needing as a LUT to minimise processing we actually need to do during normal rendering
44 if( genLUT )
45 {
46 reloadColours();
47 }
48 renderCount = 0; // 4J added
49 m_optimised = optimised;
50}
51
52void Minimap::reloadColours()
53{
54 ColourTable *colourTable = Minecraft::GetInstance()->getColourTable();
55 // 4J note that this code has been extracted pretty much as it was in Minimap::render, although with some byte order changes
56 for( int i = 0; i < (14 * 4); i++ ) // 14 material colours currently, 4 brightnesses of each
57 {
58 if (i / 4 == 0)
59 {
60 // 4J - changed byte order to save having to reorder later
61#ifdef __ORBIS__
62 LUT[i] = 0;
63#else
64 LUT[i] = (((i + i / w) & 1) * 8 + 16);
65#endif
66 //pixels[i] = (((i + i / w) & 1) * 8 + 16) << 24;
67 }
68 else
69 {
70 int color = colourTable->getColor( MaterialColor::colors[i / 4]->col );
71 int brightness = i & 3;
72
73 int br = 220;
74 if (brightness == 2) br = 255;
75 if (brightness == 0) br = 180;
76
77 int r = ((color >> 16) & 0xff) * br / 255;
78 int g = ((color >> 8) & 0xff) * br / 255;
79 int b = ((color) & 0xff) * br / 255;
80
81 // 4J - changed byte order to save having to reorder later
82#if ( defined _DURANGO || defined _WIN64 || __PSVITA__ )
83 LUT[i] = 255 << 24 | b << 16 | g << 8 | r;
84#elif defined _XBOX
85 LUT[i] = 255 << 24 | r << 16 | g << 8 | b;
86#elif defined __ORBIS__
87 r >>= 3; g >>= 3; b >>= 3;
88 LUT[i] = 1 << 15 | ( r << 10 ) | ( g << 5 ) | b;
89#else
90 LUT[i] = r << 24 | g << 16 | b << 8 | 255;
91#endif
92
93 //pixels[i] = (255) << 24 | r << 16 | g << 8 | b;
94 }
95
96 }
97 genLUT = false;
98}
99
100// 4J added entityId
101void Minimap::render(shared_ptr<Player> player, Textures *textures, shared_ptr<MapItemSavedData> data, int entityId)
102{
103 // 4J - only update every 8 renders, as an optimisation
104 // We don't want to use this for ItemFrame renders of maps, as then we can't have different maps together
105 if( !m_optimised || ( renderCount & 7 ) == 0 )
106 {
107 for (int i = 0; i < w * h; i++)
108 {
109 int val = data->colors[i];
110 // 4J - moved the code that used to run here into a LUT that is generated once in the ctor above
111 pixels[i] = LUT[val];
112 }
113 }
114 renderCount++;
115
116 // 4J - changed - have changed texture generation here to put the bytes in the right order already, so we don't have to do any copying round etc. in the texture replacement itself
117 textures->replaceTextureDirect(pixels, w, h, mapTexture);
118
119 int x = 0;
120 int y = 0;
121 Tesselator *t = Tesselator::getInstance();
122
123 float vo = 0;
124
125 glBindTexture(GL_TEXTURE_2D, mapTexture);
126 glEnable(GL_BLEND);
127 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
128 glDisable(GL_ALPHA_TEST);
129 t->begin();
130 // 4J - moved to -0.02 to stop z fighting ( was -0.01)
131 // AP - Vita still has issues so push it a bit more
132 float Offset = -0.02f;
133#ifdef __PSVITA__
134 Offset = -0.03f;
135#endif
136 t->vertexUV((float)(x + 0 + vo), (float)( y + h - vo), (float)( Offset), (float)( 0), (float)( 1));
137 t->vertexUV((float)(x + w - vo), (float)( y + h - vo), (float)( Offset), (float)( 1), (float)( 1));
138 t->vertexUV((float)(x + w - vo), (float)( y + 0 + vo), (float)( Offset), (float)( 1), (float)( 0));
139 t->vertexUV((float)(x + 0 + vo), (float)( y + 0 + vo), (float)( Offset), (float)( 0), (float)( 0));
140 t->end();
141 glEnable(GL_ALPHA_TEST);
142 glDisable(GL_BLEND);
143
144
145 textures->bind(textures->loadTexture(TN_MISC_MAPICONS));//L"/misc/mapicons.png"));
146
147 AUTO_VAR(itEnd, data->decorations.end());
148
149#ifdef _LARGE_WORLDS
150 vector<MapItemSavedData::MapDecoration *> m_edgeIcons;
151#endif
152
153 // 4J-PB - stack the map icons
154 float fIconZ=-0.04f;// 4J - moved to -0.04 (was -0.02) to stop z fighting
155 for( vector<MapItemSavedData::MapDecoration *>::iterator it = data->decorations.begin(); it != itEnd; it++ )
156 {
157 MapItemSavedData::MapDecoration *dec = *it;
158
159 if(!dec->visible) continue;
160
161 char imgIndex = dec->img;
162
163#ifdef _LARGE_WORLDS
164 // For edge icons, use a different texture
165 if(imgIndex >= 16)
166 {
167 m_edgeIcons.push_back(dec);
168 continue;
169 }
170#endif
171
172 // 4J Stu - For item frame renders, the player is NULL. We do not want to show player icons on the frames.
173 if(player == NULL && (imgIndex != 12)) continue;
174 else if (player != NULL && imgIndex == 12) continue;
175 else if( imgIndex == 12 && dec->entityId != entityId) continue;
176
177 glPushMatrix();
178 glTranslatef(x + dec->x / 2.0f + w / 2, y + dec->y / 2.0f + h / 2, fIconZ);
179 glRotatef(dec->rot * 360 / 16.0f, 0, 0, 1);
180 glScalef(4, 4, 3);
181 glTranslatef(-1.0f / 8.0f, +1.0f / 8.0f, 0);
182
183 float u0 = (imgIndex % 4 + 0) / 4.0f;
184 float v0 = (imgIndex / 4 + 0) / 4.0f;
185 float u1 = (imgIndex % 4 + 1) / 4.0f;
186 float v1 = (imgIndex / 4 + 1) / 4.0f;
187
188 t->begin();
189 t->vertexUV((float)(-1), (float)( +1), (float)( 0), (float)( u0), (float)( v0));
190 t->vertexUV((float)(+1), (float)( +1), (float)( 0), (float)( u1), (float)( v0));
191 t->vertexUV((float)(+1), (float)( -1), (float)( 0), (float)( u1), (float)( v1));
192 t->vertexUV((float)(-1), (float)( -1), (float)( 0), (float)( u0), (float)( v1));
193 t->end();
194 glPopMatrix();
195 fIconZ-=0.01f;
196 }
197
198#ifdef _LARGE_WORLDS
199 // For players on the edge of the world
200 textures->bind(textures->loadTexture(TN_MISC_ADDITIONALMAPICONS));
201
202 fIconZ=-0.04f;// 4J - moved to -0.04 (was -0.02) to stop z fighting
203 for( AUTO_VAR(it,m_edgeIcons.begin()); it != m_edgeIcons.end(); it++ )
204 {
205 MapItemSavedData::MapDecoration *dec = *it;
206
207 char imgIndex = dec->img;
208 imgIndex -= 16;
209
210 // 4J Stu - For item frame renders, the player is NULL. We do not want to show player icons on the frames.
211 if(player == NULL && (imgIndex != 12)) continue;
212 else if (player != NULL && imgIndex == 12) continue;
213 else if( imgIndex == 12 && dec->entityId != entityId) continue;
214
215 glPushMatrix();
216 glTranslatef(x + dec->x / 2.0f + w / 2, y + dec->y / 2.0f + h / 2, fIconZ);
217 glRotatef(dec->rot * 360 / 16.0f, 0, 0, 1);
218 glScalef(4, 4, 3);
219 glTranslatef(-1.0f / 8.0f, +1.0f / 8.0f, 0);
220
221 float u0 = (imgIndex % 4 + 0) / 4.0f;
222 float v0 = (imgIndex / 4 + 0) / 4.0f;
223 float u1 = (imgIndex % 4 + 1) / 4.0f;
224 float v1 = (imgIndex / 4 + 1) / 4.0f;
225
226 t->begin();
227 t->vertexUV((float)(-1), (float)( +1), (float)( 0), (float)( u0), (float)( v0));
228 t->vertexUV((float)(+1), (float)( +1), (float)( 0), (float)( u1), (float)( v0));
229 t->vertexUV((float)(+1), (float)( -1), (float)( 0), (float)( u1), (float)( v1));
230 t->vertexUV((float)(-1), (float)( -1), (float)( 0), (float)( u0), (float)( v1));
231 t->end();
232 glPopMatrix();
233 fIconZ-=0.01f;
234 }
235#endif
236
237 glPushMatrix();
238// glRotatef(0, 1, 0, 0);
239 glTranslatef(0, 0, -0.06f);
240 glScalef(1, 1, 1);
241// 4J Stu - Don't render the text name, except in debug
242//#if 1
243//#ifdef _DEBUG
244// font->draw(data->id, x, y, 0xff000000);
245//#else
246 // 4J Stu - TU-1 hotfix
247 // DCR: Render the players current position here instead
248 if(player != NULL)
249 {
250 wchar_t playerPosText[32];
251 ZeroMemory(&playerPosText, sizeof(wchar_t) * 32);
252 int posx = floor(player->x);
253 int posy = floor(player->y);
254 int posz = floor(player->z);
255 swprintf(playerPosText, 32, L"X: %d, Y: %d, Z: %d", posx, posy, posz);
256
257 font->draw(playerPosText, x, y, Minecraft::GetInstance()->getColourTable()->getColour(eMinecraftColour_Map_Text));
258 }
259//#endif
260 glPopMatrix();
261
262}