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 "PS3_UIController.h"
3#include "Common/UI/UIController.h"
4#include <cell/gcm.h>
5
6// Temp
7#include "..\Minecraft.h"
8#include "..\Textures.h"
9
10#define _ENABLEIGGY
11
12ConsoleUIController ui;
13
14void ConsoleUIController::init(S32 w, S32 h)
15{
16#ifdef _ENABLEIGGY
17
18 // Shared init
19 preInit(w,h);
20
21
22
23
24 /* Now that Iggy is ready, we need to create a set of draw
25 callbacks for it to use to draw things with the platform
26 hardware (in this case, via GCM). To do this, we're building
27 this tutorial with the GCM GDraw implementaton that's included
28 with the Iggy SDK. To get it set up, we first need to set up
29 its memory configuration, then we create a context, and finally
30 we pass that context to Iggy so it will use it to render Flash
31 content.
32 First, we need to set up the GDraw memory configuration. GDraw
33 needs memory areas for various types of resources (such as textures,
34 and vertex buffers). Some of them, such as render targets, need to be
35 allocated in special types of memory to get optimal performance. In this
36 example, we allocate everything except for the dynamic vertex buffer
37 memory in local video memory.
38 Rendertargets deserve a special mention: They need to be allocated in a
39 tile region for optimum performance, which places some requirements on
40 their alignment and size. The size you specify here must be big enough to
41 cover the largest rendertarget you'll ever need for one Iggy rendering
42 call. In our case, we render the whole screen at once, so that's the
43 size we pass. */
44
45// // Set up rendertarget memory.
46 S32 rt_mem_size = 16*1024*1024; // 16MB of render target memory.
47 void *rt_mem = RenderManager.allocVRAM(rt_mem_size, CELL_GCM_TILE_ALIGN_OFFSET);
48 S32 rt_pitch = cellGcmGetTiledPitchSize(w * 4);
49 gdraw_GCM_SetRendertargetMemory(rt_mem, rt_mem_size, w, h, rt_pitch);
50
51 // Also configure a tile region for it.
52 RenderManager.setTileInfo(rt_mem, rt_pitch, CELL_GCM_COMPMODE_C32_2X1);
53
54 // Texture and vertex buffer memory work in a similar fashion.
55 S32 tex_mem_size = 24*1024*1024;
56 S32 vert_mem_size = 2*1024*1024;
57
58 gdraw_GCM_SetResourceMemory(GDRAW_GCM_RESOURCE_texture, 200, RenderManager.allocVRAM(tex_mem_size, 128), tex_mem_size);
59 gdraw_GCM_SetResourceMemory(GDRAW_GCM_RESOURCE_vertexbuffer, 1000, RenderManager.allocVRAM(vert_mem_size, 128), vert_mem_size);
60
61 // In this example, we allocate dynamic vertex buffer memory from main memory,
62 // which is generally faster.
63 S32 dyn_vert_size = 128*1024;
64 gdraw_GCM_SetResourceMemory(GDRAW_GCM_RESOURCE_dyn_vertexbuffer, 0, RenderManager.allocIOMem(dyn_vert_size, 128), dyn_vert_size);
65
66// Whew! Now that the GDraw memory configuration is set up, we need to initialize
67// GDraw. But first, we need to allocate yet another block of video memory for
68// GDraw to store its shaders etc. in (this is the last alloc!). Unlike the
69// rest of the memory configuration, the work area is reserved to GDraw and can't
70// be freed or relocated afterwards without shutting GDraw and all attached Iggys
71// down completely. But it's fairly small (64k as of this writing) so this shouldn't
72// be much of a problem.
73 void *gdraw_work_mem = RenderManager.allocVRAM(GDRAW_GCM_LOCAL_WORKMEM_SIZE, 128);
74
75 /* Finally, we can actually create the GDraw GCM driver and pass it to Iggy. */
76 gdraw_funcs = gdraw_GCM_CreateContext(
77 gCellGcmCurrentContext, // The default GCM context provided by libgcm.
78 gdraw_work_mem, // The work area in local memory
79 64); // RSX Label index to use for fences
80 IggySetGDraw(gdraw_funcs);
81
82 // Initialize audio
83 // TODO: 4J Stu - Currently Iggy crashes if I have audio enabled. Disabling for now.
84 //IggyAudioUseDefault();
85
86 // Shared init
87 postInit();
88#endif
89}
90
91void ConsoleUIController::render()
92{
93#ifdef _ENABLEIGGY
94// We need to tell GDraw which surface to render to.
95// This tutorial just uses the backbuffer, but for in-game
96// UI usage, you might want to use another rendertarget (like
97// a texture) instead.
98 gdraw_GCM_SetTileOrigin(RenderManager.getCurrentBackBufferSurface(), 0, 0);
99 renderScenes();
100
101// Finally we're ready to display the frame. First we
102// call GDraw to let it know we're done rendering, so
103// it can do any finalization it needs to do. Then we
104// initiate the GCM buffer-flip procedure.
105 gdraw_GCM_NoMoreGDrawThisFrame();
106#endif
107}
108
109CustomDrawData *ConsoleUIController::setupCustomDraw(UIScene *scene, IggyCustomDrawCallbackRegion *region)
110{
111 CustomDrawData *customDrawRegion = new CustomDrawData();
112 customDrawRegion->x0 = region->x0;
113 customDrawRegion->x1 = region->x1;
114 customDrawRegion->y0 = region->y0;
115 customDrawRegion->y1 = region->y1;
116
117 // get the correct object-to-world matrix from GDraw, and set the render state to a normal state
118 gdraw_GCM_BeginCustomDraw(region, customDrawRegion->mat);
119
120 setupCustomDrawGameStateAndMatrices(scene, customDrawRegion);
121
122 return customDrawRegion;
123}
124
125CustomDrawData *ConsoleUIController::calculateCustomDraw(IggyCustomDrawCallbackRegion *region)
126{
127 CustomDrawData *customDrawRegion = new CustomDrawData();
128 customDrawRegion->x0 = region->x0;
129 customDrawRegion->x1 = region->x1;
130 customDrawRegion->y0 = region->y0;
131 customDrawRegion->y1 = region->y1;
132
133 gdraw_GCM_CalculateCustomDraw_4J(region, customDrawRegion->mat);
134
135 return customDrawRegion;
136}
137
138void ConsoleUIController::endCustomDraw(IggyCustomDrawCallbackRegion *region)
139{
140 endCustomDrawGameStateAndMatrices();
141
142 gdraw_GCM_EndCustomDraw(region);
143}
144
145void ConsoleUIController::setTileOrigin(S32 xPos, S32 yPos)
146{
147 gdraw_GCM_SetTileOrigin(RenderManager.getCurrentBackBufferSurface(), xPos, yPos);
148}
149
150GDrawTexture *ConsoleUIController::getSubstitutionTexture(int textureId)
151{
152 /* Create a wrapped texture from a shader resource view.
153 A wrapped texture can be used to let Iggy draw using the contents of a texture
154 you create and manage on your own. For example, you might render to this texture,
155 or stream video into it. Wrapped textures take up a handle. They will never be
156 freed or otherwise modified by GDraw; nor will GDraw change any reference counts.
157 All this is up to the application. */
158 CellGcmTexture *tex = RenderManager.TextureGetTexture(textureId);
159 GDrawTexture *gdrawTex = gdraw_GCM_WrappedTextureCreate(tex);
160 return gdrawTex;
161}
162
163void ConsoleUIController::destroySubstitutionTexture(void *destroyCallBackData, GDrawTexture *handle)
164{
165 /* Destroys the GDraw wrapper for a wrapped texture object. This will free up
166 a GDraw texture handle but not release the associated D3D texture; that is
167 up to you. */
168 gdraw_GCM_WrappedTextureDestroy(handle);
169}
170
171void ConsoleUIController::shutdown()
172{
173#ifdef _ENABLEIGGY
174 /* Destroy the GDraw context. This frees all resources, shaders etc.
175 allocated by GDraw. Note this is only safe to call after all
176 active Iggy player have been destroyed! */
177 gdraw_GCM_DestroyContext();
178#endif
179}
180
181void ConsoleUIController::beginIggyCustomDraw4J(IggyCustomDrawCallbackRegion *region, CustomDrawData *customDrawRegion)
182{
183 PIXBeginNamedEvent(0,"Starting Iggy custom draw\n");
184
185 PIXBeginNamedEvent(0,"Gdraw setup");
186 // get the correct object-to-world matrix from GDraw, and set the render state to a normal state
187 gdraw_GCM_BeginCustomDraw(region, customDrawRegion->mat);
188 PIXEndNamedEvent();
189}
190
191
192void ConsoleUIController::handleUnlockFullVersionCallback()
193{
194 for(unsigned int i = 0; i < eUIGroup_COUNT; ++i)
195 {
196 ui.m_groups[i]->handleUnlockFullVersion();
197 }
198}
199