the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 195 lines 6.7 kB view raw
1#include "stdafx.h" 2#include "Durango_UIController.h" 3 4#define _ENABLEIGGY 5 6ConsoleUIController ui; 7 8void ConsoleUIController::init(Microsoft::WRL::ComPtr<ID3D11Device> dev, Microsoft::WRL::ComPtr<ID3D11DeviceContext> ctx, Microsoft::WRL::ComPtr<ID3D11RenderTargetView> pRenderTargetView, Microsoft::WRL::ComPtr<ID3D11DepthStencilView> pDepthStencilView, S32 w, S32 h) 9{ 10#ifdef _ENABLEIGGY 11 m_pRenderTargetView = pRenderTargetView; 12 m_pDepthStencilView = pDepthStencilView; 13 14 // Shared init 15 preInit(w,h); 16 17 gdraw_funcs = gdraw_D3D11_CreateContext(dev.Get(), ctx.Get(), w, h); 18 19 if(!gdraw_funcs) 20 { 21 app.DebugPrintf("Failed to initialise GDraw!\n"); 22#ifndef _CONTENT_PACKAGE 23 __debugbreak(); 24#endif 25 app.FatalLoadError(); 26 } 27 28 /* For each of the resource types, we specify the size of the cache that 29 GDraw will use. We specify both the number of possible objects 30 (the number of "handles") of each type, and the maximum memory 31 to use for each one. 32 33 For some platforms, we would actually pass 34 in the memory to use, and the GDraw will strictly obey the resource 35 request. For D3D, storage is managed by D3D, and GDraw only 36 approximates the requested storage amount. In fact, you don't 37 even have to set these at all for D3D, which has some "reasonable" defaults, 38 but we'll set it here for clarity. 39 (The storage required for 40 the handles is separate, and always allocated through the global allocator 41 specified in IggyInit.) 42 43 The size that's actually needed here depends on the content of your 44 Flash file. There's more info in the documentation about how to 45 determine how big they should be. But for now, we'll just set them 46 really big so if you substitute a different file it should work. */ 47 gdraw_D3D11_SetResourceLimits(GDRAW_D3D11_RESOURCE_vertexbuffer, 5000, 16 * 1024 * 1024); 48 gdraw_D3D11_SetResourceLimits(GDRAW_D3D11_RESOURCE_texture , 5000, 128 * 1024 * 1024); 49 gdraw_D3D11_SetResourceLimits(GDRAW_D3D11_RESOURCE_rendertarget, 10, 32 * 1024 * 1024); 50 gdraw_D3D11_SetResourceLimits(GDRAW_D3D11_RESOURCE_dynbuffer , 1, 2 * 1024 * 1024); 51 52 /* GDraw is all set, so we'll point Iggy at it. */ 53 IggySetGDraw(gdraw_funcs); 54 55 // Initialize audio 56 // TODO: 4J Stu - Currently Iggy crashes if I have audio enabled. Disabling for now. 57 //IggyAudioUseDefault(); 58 59 // Shared init 60 postInit(); 61#endif 62} 63 64void ConsoleUIController::render() 65{ 66#ifdef _ENABLEIGGY 67 /* Now that we've cleared, we need to tell GDraw which 68 render target to use, what depth/stencil buffer to use, 69 and where the origin should be. 70 71 If we were using multisampling, we'd also need to give 72 GDraw a render target view for a non-multisampled texture 73 the size of main_rtv as a resolve target (this is the third 74 parameter). But since we're not using multisampling in this 75 example, no resolve targets are required. */ 76 gdraw_D3D11_SetTileOrigin( m_pRenderTargetView.Get(), 77 m_pDepthStencilView.Get(), 78 NULL, 79 0, 80 0 ); 81 82 renderScenes(); 83 84 /* Finally we're ready to display the frame. We call GDraw to 85 let it know we're done rendering, so it can do any finalization 86 it needs to do. */ 87 gdraw_D3D11_NoMoreGDrawThisFrame(); 88#endif 89} 90 91void ConsoleUIController::beginIggyCustomDraw4J(IggyCustomDrawCallbackRegion *region, CustomDrawData *customDrawRegion) 92{ 93 PIXBeginNamedEvent(0,"Starting Iggy custom draw\n"); 94 95 PIXBeginNamedEvent(0,"Gdraw setup"); 96 // get the correct object-to-world matrix from GDraw, and set the render state to a normal state 97 gdraw_D3D11_BeginCustomDraw_4J(region, customDrawRegion->mat); 98 PIXEndNamedEvent(); 99} 100 101CustomDrawData *ConsoleUIController::setupCustomDraw(UIScene *scene, IggyCustomDrawCallbackRegion *region) 102{ 103 CustomDrawData *customDrawRegion = new CustomDrawData(); 104 customDrawRegion->x0 = region->x0; 105 customDrawRegion->x1 = region->x1; 106 customDrawRegion->y0 = region->y0; 107 customDrawRegion->y1 = region->y1; 108 109 PIXBeginNamedEvent(0,"Starting Iggy custom draw\n"); 110 PIXBeginNamedEvent(0,"Setup"); 111 112 PIXBeginNamedEvent(0,"Gdraw setup"); 113 // get the correct object-to-world matrix from GDraw, and set the render state to a normal state 114 gdraw_D3D11_BeginCustomDraw_4J(region, customDrawRegion->mat); 115 PIXEndNamedEvent(); 116 117 PIXBeginNamedEvent(0,"Our setup"); 118 setupCustomDrawGameStateAndMatrices(scene, customDrawRegion); 119 PIXEndNamedEvent(); 120 PIXEndNamedEvent(); 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_D3D11_CalculateCustomDraw_4J(region, customDrawRegion->mat); 134 135 return customDrawRegion; 136} 137 138void ConsoleUIController::endCustomDraw(IggyCustomDrawCallbackRegion *region) 139{ 140 PIXBeginNamedEvent(0,"Teardown"); 141 PIXBeginNamedEvent(0,"Our teardown"); 142 endCustomDrawGameStateAndMatrices(); 143 PIXEndNamedEvent(); 144 145 PIXBeginNamedEvent(0,"Gdraw teardown"); 146 gdraw_D3D11_EndCustomDraw(region); 147 PIXEndNamedEvent(); 148 PIXEndNamedEvent(); 149 PIXEndNamedEvent(); 150} 151 152void ConsoleUIController::setTileOrigin(S32 xPos, S32 yPos) 153{ 154 gdraw_D3D11_SetTileOrigin( m_pRenderTargetView.Get(), 155 m_pDepthStencilView.Get(), 156 NULL, 157 xPos, 158 yPos ); 159} 160 161GDrawTexture *ConsoleUIController::getSubstitutionTexture(int textureId) 162{ 163 /* Create a wrapped texture from a shader resource view. 164 A wrapped texture can be used to let Iggy draw using the contents of a texture 165 you create and manage on your own. For example, you might render to this texture, 166 or stream video into it. Wrapped textures take up a handle. They will never be 167 freed or otherwise modified by GDraw; nor will GDraw change any reference counts. 168 All this is up to the application. */ 169 ID3D11ShaderResourceView *tex = RenderManager.TextureGetTexture(textureId); 170 ID3D11Resource *resource; 171 tex->GetResource(&resource); 172 ID3D11Texture2D *tex2d = (ID3D11Texture2D *)resource; 173 D3D11_TEXTURE2D_DESC desc; 174 tex2d->GetDesc(&desc); 175 GDrawTexture *gdrawTex = gdraw_D3D11_WrappedTextureCreate(tex); 176 return gdrawTex; 177} 178 179void ConsoleUIController::destroySubstitutionTexture(void *destroyCallBackData, GDrawTexture *handle) 180{ 181 /* Destroys the GDraw wrapper for a wrapped texture object. This will free up 182 a GDraw texture handle but not release the associated D3D texture; that is 183 up to you. */ 184 gdraw_D3D11_WrappedTextureDestroy(handle); 185} 186 187void ConsoleUIController::shutdown() 188{ 189#ifdef _ENABLEIGGY 190 /* Destroy the GDraw context. This frees all resources, shaders etc. 191 allocated by GDraw. Note this is only safe to call after all 192 active Iggy player have been destroyed! */ 193 gdraw_D3D11_DestroyContext(); 194#endif 195}