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