remove Windows64 app

This commit is contained in:
Tropical 2026-04-09 23:36:49 -05:00
parent daf56bc296
commit 8c6effdabf
24 changed files with 7 additions and 22223 deletions

View file

@ -38,10 +38,6 @@ if get_option('buildtype') in ['debug', 'debugoptimized']
]
endif
if host_machine.system() == 'linux'
global_cpp_defs += ['-Dlinux', '-D__linux', '-D__linux__']
endif
if get_option('renderer') == 'gles'
global_cpp_defs += ['-DGLES']
gl_dep = dependency('glesv2', required: true)

File diff suppressed because it is too large Load diff

View file

@ -1,158 +0,0 @@
#include "minecraft/stdafx.h" // 4J
// gdraw_d3d11.cpp - author: Fabian Giesen - copyright 2011 RAD Game Tools
//
// This implements the Iggy graphics driver layer for D3D 11.
// GDraw consists of several components that interact fairly loosely with each
// other; e.g. the resource management, drawing and filtering parts are all
// fairly independent of each other. If you want to modify some aspect of GDraw
// - say the texture allocation logic - your best bet is usually to just look
// for one of the related entry points, e.g. MakeTextureBegin, and take it from
// there. There's a bunch of code in this file, but none of it is really
// complicated.
//
// The one bit you might want to change that's not that localized is to
// integrate GDraw with an existing state caching system. The following bits all
// modify D3D state in some way:
// - The rendering helpers (set_viewport_raw, set_projection_raw,
// set_*_renderstate)
// - RenderTile*/TextureDrawBuffer* may change the active rendertarget and
// depth/stencil surface,
// as do D3D1X_(NoMoreGDrawThisFrame) and set_render_target
// - set_texture
// - set_renderstate and set_renderstate_full. These are the main places where
// render state changes occur;
// you should probably start here.
// - DrawIndexedTriangles sets the active vertex/index buffers and vertex
// declaration
// - Most of the functions in the "filter effects" section modify D3D state,
// mostly
// pixel shader constants and textures
#define GDRAW_ASSERTS
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
// We temporarily disable this warning for the shared interface portions
#pragma warning(push)
#pragma warning( \
disable : 4201) // nonstandard extension used : nameless struct/union
#include <d3d11.h>
#include <math.h>
#include <string.h>
#include <windows.h>
#include "../include/gdraw.h"
#include "../include/iggy.h"
#include "gdraw_d3d11.h"
#pragma warning(pop)
// Some macros to allow as much sharing between D3D10 and D3D11 code as
// possible.
#define D3D1X_(id) D3D11_##id
#define ID3D1X(id) ID3D11##id
#define gdraw_D3D1X_(id) gdraw_D3D11_##id
#define GDRAW_D3D1X_(id) GDRAW_D3D11_##id
typedef ID3D11Device ID3D1XDevice;
typedef ID3D11DeviceContext ID3D1XContext;
typedef F32 ViewCoord;
typedef gdraw_d3d11_resourcetype gdraw_resourcetype;
static void report_d3d_error(HRESULT hr, char* call, char* context);
static void* map_buffer(ID3D1XContext* ctx, ID3D11Buffer* buf, bool discard) {
D3D11_MAPPED_SUBRESOURCE msr;
HRESULT hr = ctx->Map(
buf, 0,
discard ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, 0,
&msr);
if (FAILED(hr)) {
report_d3d_error(hr, "Map", "of buffer");
return NULL;
} else
return msr.pData;
}
static void unmap_buffer(ID3D1XContext* ctx, ID3D11Buffer* buf) {
ctx->Unmap(buf, 0);
}
static RADINLINE void set_pixel_shader(ID3D11DeviceContext* ctx,
ID3D11PixelShader* shader) {
ctx->PSSetShader(shader, NULL, 0);
}
static RADINLINE void set_vertex_shader(ID3D11DeviceContext* ctx,
ID3D11VertexShader* shader) {
ctx->VSSetShader(shader, NULL, 0);
}
static ID3D11BlendState* create_blend_state(ID3D11Device* dev, BOOL blend,
D3D11_BLEND src, D3D11_BLEND dst) {
D3D11_BLEND_DESC desc = {};
desc.RenderTarget[0].BlendEnable = blend;
desc.RenderTarget[0].SrcBlend = src;
desc.RenderTarget[0].DestBlend = dst;
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].SrcBlendAlpha =
(src == D3D11_BLEND_DEST_COLOR) ? D3D11_BLEND_DEST_ALPHA : src;
desc.RenderTarget[0].DestBlendAlpha = dst;
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
ID3D11BlendState* res;
HRESULT hr = dev->CreateBlendState(&desc, &res);
if (FAILED(hr)) {
report_d3d_error(hr, "CreateBlendState", "");
res = NULL;
}
return res;
}
#define GDRAW_SHADER_FILE "gdraw_d3d10_shaders.inl"
#include "gdraw_d3d1x_shared.inl"
static void create_pixel_shader(ProgramWithCachedVariableLocations* p,
ProgramWithCachedVariableLocations* src) {
*p = *src;
if (p->bytecode) {
HRESULT hr = gdraw->d3d_device->CreatePixelShader(p->bytecode, p->size,
NULL, &p->pshader);
if (FAILED(hr)) {
report_d3d_error(hr, "CreatePixelShader", "");
p->pshader = NULL;
return;
}
}
}
static void create_vertex_shader(ProgramWithCachedVariableLocations* p,
ProgramWithCachedVariableLocations* src) {
*p = *src;
if (p->bytecode) {
HRESULT hr = gdraw->d3d_device->CreateVertexShader(p->bytecode, p->size,
NULL, &p->vshader);
if (FAILED(hr)) {
report_d3d_error(hr, "CreateVertexShader", "");
p->vshader = NULL;
return;
}
}
}
GDrawFunctions* gdraw_D3D11_CreateContext(ID3D11Device* dev,
ID3D11DeviceContext* ctx, S32 w,
S32 h) {
return create_context(dev, ctx, w, h);
}
// 4J added - interface so we can set the viewport back to the one that Iggy
// last set up
void gdraw_D3D11_setViewport_4J() { set_viewport(); }

View file

@ -1,162 +0,0 @@
#pragma once // 4J
// gdraw_d3d11.h - author: Fabian Giesen - copyright 2011 RAD Game Tools
//
// Interface for creating a D3D11 GDraw driver.
#define IDOC
// idoc(parent,GDraw_d3d11)
typedef enum gdraw_d3d11_resourcetype {
GDRAW_D3D11_RESOURCE_rendertarget,
GDRAW_D3D11_RESOURCE_texture,
GDRAW_D3D11_RESOURCE_vertexbuffer,
GDRAW_D3D11_RESOURCE_dynbuffer, // Streaming buffer for dynamic
// vertex/index data (handle count ignored)
GDRAW_D3D11_RESOURCE__count,
} gdraw_d3d11_resourcetype;
IDOC extern int gdraw_D3D11_SetResourceLimits(gdraw_d3d11_resourcetype type,
S32 num_handles, S32 num_bytes);
/* This sets how large the memory pool for a given resource types is, and how
many handles GDraw should allocate for it. GDraw keeps track of allocations
in each pool, and will free old resources in a LRU manner to make space if
one of the limits is about to be exceeded.
Returns 1 if value successfully changed, 0 on error.
You need to call IggyPlayerFlushAll on all active Iggys before you do this to
make them flush their resources since changing the resource limits
invalidates all handles. You also need to call IggyFlushInstalledFonts if you
have any installed fonts.
*/
IDOC extern GDrawFunctions* gdraw_D3D11_CreateContext(ID3D11Device* dev,
ID3D11DeviceContext* ctx,
S32 w, S32 h);
/* Creates a GDraw context for rendering using D3D. You need to pass in the D3D
device, the device context to use for rendering, and the width/height of
render target textures.
The width/height is used solely for sizing internal rendertargets. They will
be allocated to the larger of this size and the size of any rendered tiles
(with padding). In other words, you can pass in (0,0) and the rendertargets
will be allocated to the right size. However, if you draw multiple Iggy files
or tiles of different sizes, they might first be allocated too small; it's
best to pass in the correct size initially to avoid unnecessary
allocation/deallocation of too-small rendertargets.
There can only be one D3D GDraw context active at any one time.
If initialization fails for some reason (the main reason would be an out of
memory condition), NULL is returned. Otherwise, you can pass the return value
to IggySetGDraw. */
IDOC extern void gdraw_D3D11_DestroyContext(void);
/* Destroys the current GDraw context, if any. */
IDOC extern void gdraw_D3D11_SetErrorHandler(
void(__cdecl* error_handler)(HRESULT hr));
/* Sets the GDraw D3D error handler.
This will get called with the respective D3D error code if GDraw encounters
an error that it can't handle by itself (e.g. running out of state objects).
*/
IDOC extern void gdraw_D3D11_SetRendertargetSize(S32 w, S32 h);
/* Changes the current render target size (and recreates all rendertargets if
necessary). This allows you to shrink the rendertargets if the new needed
size is smaller than it was previously. As with $gdraw_D3D11_CreateContext,
the width and height specified here are only minimums; GDraw will reallocate
larger rendertargets as needed. */
IDOC extern void gdraw_D3D11_SetTileOrigin(
ID3D11RenderTargetView* main_rt, ID3D11DepthStencilView* main_ds,
ID3D11ShaderResourceView* non_msaa_rt, S32 x, S32 y);
/* This sets the main rendertarget and matching depth/stencil buffer that GDraw
should render to and the x/y position of the output location of the top-left
of the current tile (allowing you to finely-position content, or to do tiled
rendering).
If your rendertarget uses multisampling, you also need to specify a shader
resource view for a non-MSAA rendertarget texture (identically sized to
main_rt) in non_msaa_rt. This is only used if the Flash content includes
non-standard blend modes which have to use a special blend shader, so you can
leave it NULL if you forbid such content.
You need to call this before Iggy calls any rendering functions. */
IDOC extern void gdraw_D3D11_NoMoreGDrawThisFrame(void);
/* Tells GDraw that no more rendering operations will occur this frame. This
triggers some end-of-frame processing; most importantly, GDraw uses this call
as a marker to detect thrashing (and react accordingly), so please do not
forget to call this every frame! (As long as Iggy does any rendering, that
is) */
IDOC extern void gdraw_D3D11_PreReset(void);
/* Call this before D3D device Reset(); it will free all default pool resources
allocated by GDraw. */
IDOC extern void gdraw_D3D11_PostReset(void);
/* Call after D3D device Reset(). */
IDOC extern void RADLINK gdraw_D3D11_BeginCustomDraw_4J(
IggyCustomDrawCallbackRegion* Region, F32 mat[16]);
IDOC extern void RADLINK gdraw_D3D11_CalculateCustomDraw_4J(
IggyCustomDrawCallbackRegion* Region, F32 mat[16]);
IDOC extern void RADLINK gdraw_D3D11_BeginCustomDraw(
IggyCustomDrawCallbackRegion* Region, F32 mat[4][4]);
/* Call at the beginning of Iggy custom draw callback to clear any odd render
states GDraw has set on the D3D device, and to get the current 2D
object-to-world transformation. */
IDOC extern void RADLINK
gdraw_D3D11_EndCustomDraw(IggyCustomDrawCallbackRegion* Region);
/* Call at the end of Iggy custom draw callback so GDraw can restore its render
* states. */
IDOC extern void RADLINK gdraw_D3D11_GetResourceUsageStats(
gdraw_d3d11_resourcetype type, S32* handles_used, S32* bytes_used);
/* D3D only: Get resource usage stats for last frame.
This can be used to get an estimate of how much graphics memory got used by
GDraw during the last frame.
For the dynbuffer, this always returns 0 in handles_used and the *size of the
largest single allocation* in bytes_used. It needs to be sized so that this
allocation fits; make it smaller and it won't work, but if you make it much
larger (say more than 2x as big), it's just a waste of memory. That said, we
still recommend to make it no smaller than 64k, and the default is 256k.
Caveat: This counts the number of bytes that GDraw knows about. 3D hardware
usually has its own management overhead, alignment requirements, allocation
granularity and so on. In short, this is not an accurate estimate of how much
memory is actually used by the GPU - it is a lower bound, though, and makes
for a useful ballpark estimate. */
IDOC extern GDrawTexture* gdraw_D3D11_WrappedTextureCreate(
ID3D11ShaderResourceView* tex_view);
/* Create a wrapped texture from a shader resource view.
A wrapped texture can be used to let Iggy draw using the contents of a
texture you create and manage on your own. For example, you might render to
this texture, or stream video into it. Wrapped textures take up a handle.
They will never be freed or otherwise modified by GDraw; nor will GDraw
change any reference counts. All this is up to the application. */
IDOC extern void gdraw_D3D11_WrappedTextureChange(
GDrawTexture* tex, ID3D11ShaderResourceView* tex_view);
/* Switch an existing GDrawTexture * that represents a wrapped texture to use
a new underlying D3D view. For example, you might internally double-buffer
a dynamically updated texture. As above, GDraw will leave this texture alone
and not touch any reference counts. */
IDOC extern void gdraw_D3D11_WrappedTextureDestroy(GDrawTexture* tex);
/* Destroys the GDraw wrapper for a wrapped texture object. This will free up
a GDraw texture handle but not release the associated D3D texture; that is
up to you. */
GDrawTexture* RADLINK gdraw_D3D11_MakeTextureFromResource(
U8* resource_file, S32 length, IggyFileTextureRaw* texture);
void RADLINK gdraw_D3D11_DestroyTextureFromResource(GDrawTexture* tex);
// 4J added
extern void RADLINK gdraw_D3D11_setViewport_4J();

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,841 +0,0 @@
// gdraw.h - author: Sean Barrett - copyright 2009 RAD Game Tools
//
// This is the graphics rendering abstraction that Iggy is implemented
// on top of.
#ifndef __RAD_INCLUDE_GDRAW_H__
#define __RAD_INCLUDE_GDRAW_H__
#include "rrCore.h"
#define IDOC
RADDEFSTART
// idoc(parent,GDrawAPI_Buffers)
#ifndef IGGY_GDRAW_SHARED_TYPEDEF
#define IGGY_GDRAW_SHARED_TYPEDEF
typedef struct GDrawFunctions GDrawFunctions;
typedef struct GDrawTexture GDrawTexture;
#endif // IGGY_GDRAW_SHARED_TYPEDEF
IDOC typedef struct GDrawVertexBuffer GDrawVertexBuffer;
/* An opaque handle to an internal GDraw vertex buffer. */
// idoc(parent,GDrawAPI_Base)
IDOC typedef struct gswf_recti {
S32 x0, y0; // Minimum corner of the rectangle
S32 x1, y1; // Maximum corner of the rectangle
} gswf_recti;
/* A 2D rectangle with integer coordinates specifying its minimum and maximum
* corners. */
IDOC typedef struct gswf_rectf {
F32 x0, y0; // Minimum corner of the rectangle
F32 x1, y1; // Maximum corner of the rectangle
} gswf_rectf;
/* A 2D rectangle with floating-point coordinates specifying its minimum and
* maximum corners. */
IDOC typedef struct gswf_matrix {
union {
F32 m[2][2]; // 2x2 transform matrix
struct {
F32 m00; // Alternate name for m[0][0], for coding convenience
F32 m01; // Alternate name for m[0][1], for coding convenience
F32 m10; // Alternate name for m[1][0], for coding convenience
F32 m11; // Alternate name for m[1][1], for coding convenience
};
};
F32 trans[2]; // 2D translation vector (the affine component of the matrix)
} gswf_matrix;
/* A 2D transform matrix plus a translation offset. */
#define GDRAW_STATS_batches 1
#define GDRAW_STATS_blits 2
#define GDRAW_STATS_alloc_tex 4
#define GDRAW_STATS_frees 8
#define GDRAW_STATS_defrag 16
#define GDRAW_STATS_rendtarg 32
#define GDRAW_STATS_clears 64
IDOC typedef struct GDrawStats {
S16 nonzero_flags; // which of the fields below are non-zero
U16 num_batches; // number of batches, e.g. DrawPrim, DrawPrimUP
U16 num_blits; // number of blit operations (resolve, msaa resolve, blend
// readback)
U16 freed_objects; // number of cached objects freed
U16 defrag_objects; // number of cached objects defragmented
U16 alloc_tex; // number of textures/buffers allocated
U16 rendertarget_changes; // number of rendertarget changes
U16 num_clears;
// 0 mod 8
U32 drawn_indices; // number of indices drawn (3 times number of triangles)
U32 drawn_vertices; // number of unique vertices referenced
U32 num_blit_pixels; // number of pixels in blit operations
U32 alloc_tex_bytes; // number of bytes in textures/buffers allocated
U32 freed_bytes; // number of bytes in freed cached objects
U32 defrag_bytes; // number of bytes in defragmented cached objects
U32 cleared_pixels; // number of pixels cleared by clear operation
U32 reserved;
// 0 mod 8
} GDrawStats;
/* A structure with statistics information to show in resource browser/Telemetry
*/
////////////////////////////////////////////////////////////
//
// Queries
//
// idoc(parent,GDrawAPI_Queries)
IDOC typedef enum gdraw_bformat {
GDRAW_BFORMAT_vbib, // Platform uses vertex and index buffers
GDRAW_BFORMAT_wii_dlist, // Platform uses Wii-style display lists
GDRAW_BFORMAT_vbib_single_format, // Platform uses vertex and index
// buffers, but doesn't support multiple
// vertex formats in a single VB
GDRAW_BFORMAT__count,
} gdraw_bformat;
/* Specifies what data format GDraw expects in MakeVertexBuffer_* and
DrawIndexedTriangles.
Most supported platforms prefer Vertex and Index buffers so that's what we
use, but this format turns out to be somewhat awkward for Wii, so we use the
native graphics processor display list format on that platform. */
IDOC typedef struct GDrawInfo {
S32 num_stencil_bits; // number of (possibly emulated) stencil buffer bits
U32 max_id; // number of unique values that can be easily encoded in
// zbuffer
U32 max_texture_size; // edge length of largest square texture supported by
// hardware
U32 buffer_format; // one of $gdraw_bformat
rrbool shared_depth_stencil; // does 0'th framebuffer share depth & stencil
// with others? (on GL it can't?)
rrbool always_mipmap; // if GDraw can generate mipmaps nearly for free,
// then set this flag
rrbool conditional_nonpow2; // non-pow2 textures supported, but only using
// clamp and without mipmaps
rrbool has_rendertargets; // if true, then there is no rendertarget stack
// support
rrbool no_nonpow2; // non-pow2 textures aren't supported at all
} GDrawInfo; // must be a multiple of 8
/* $GDrawInfo contains the information that Iggy needs to know about
what a GDraw implementation supports and what limits it places on
certain important values. */
IDOC typedef void RADLINK gdraw_get_info(GDrawInfo* d);
/* Iggy queries this at the beginning of rendering to get information
about the viewport and the device capabilities. */
////////////////////////////////////////////////////////////
//
// Drawing State
//
// idoc(parent,GDrawAPI_DrawingState)
IDOC typedef enum gdraw_blend {
GDRAW_BLEND_none, // Directly copy
GDRAW_BLEND_alpha, // Use the source alpha channel to modulate its
// contribution
GDRAW_BLEND_multiply, // Multiply colors componentwise
GDRAW_BLEND_add, // Add the source and destination together
GDRAW_BLEND_filter, // Uses a secondary $gdraw_filter specification to
// determine how to blend
GDRAW_BLEND_special, // Uses a secondary $gdraw_blendspecial specification
// to determine how to blend
GDRAW_BLEND__count,
} gdraw_blend;
/* Identifier indicating the type of blending operation to use when rendering.*/
IDOC typedef enum gdraw_blendspecial {
GDRAW_BLENDSPECIAL_layer, // s
GDRAW_BLENDSPECIAL_multiply, // s*d
GDRAW_BLENDSPECIAL_screen, // sa*da - (da-d)*(sa-s)
GDRAW_BLENDSPECIAL_lighten, // max(sa*d,s*da)
GDRAW_BLENDSPECIAL_darken, // min(sa*d,s*da)
GDRAW_BLENDSPECIAL_add, // min(d+s,1.0)
GDRAW_BLENDSPECIAL_subtract, // max(d-s,0.0)
GDRAW_BLENDSPECIAL_difference, // abs(sa*d-s*da)
GDRAW_BLENDSPECIAL_invert, // sa*(da-d)
GDRAW_BLENDSPECIAL_overlay, // d < da/2.0 ? (2.0*s*d) : (sa*da
// - 2.0*(da-d)*(sa-s))
GDRAW_BLENDSPECIAL_hardlight, // s < sa/2.0 ? (2.0*s*d) : (sa*da
// - 2.0*(da-d)*(sa-s))
// these do extra-special math on the output alpha
GDRAW_BLENDSPECIAL_erase, // d*(1.0-sa)
GDRAW_BLENDSPECIAL_alpha_special, // d*sa
GDRAW_BLENDSPECIAL__count,
} gdraw_blendspecial;
/* Specifies a type of "special" blend mode, which is defined as one
that has to read from the framebuffer to compute its effect.
These modes are only used with a 1-to-1 textured quad containing
the exact output data in premultiplied alpha. They all need to
read from the framebuffer to compute their effect, so a GDraw
implementation will usually need a custom path to handle that.
Users will not warn in advance whether you're going to need this
operation, so implementations either need to always render to a
texture in case it happens, or copy the framebuffer to a texture
when it does.
Note that $(gdraw_blendspecial::GDRAW_BLENDSPECIAL_erase) and
$(gdraw_blendspecial::GDRAW_BLENDSPECIAL_alpha_special) are unique
among $gdraw_blendspecial modes in that they may not actually need
to be implemented with the destination input as a texture if
the destination buffer doesn't have an alpha channel. */
// (@OPTIMIZE: the last filter in each chain could be combined with
// the final blend, although only worth doing if the final blend is
// ALPHA/ADD/MULTIPLY--it's usually ALPHA though so worth doing!)
IDOC typedef enum gdraw_filter {
GDRAW_FILTER_blur, // Blurs the source image
GDRAW_FILTER_colormatrix, // Transform RGB pixel values by a matrix
GDRAW_FILTER_bevel, // Bevels the source image
GDRAW_FILTER_dropshadow, // Adds a dropshadow underneath the source image
GDRAW_FILTER__count,
} gdraw_filter;
/* Specifies a type of post-processing graphics filter.
These modes are only used to implement filter effects, and will
always be blending from a temporary buffer to another temporary
buffer with no blending, so in general they should not require
any additional input.
*/
IDOC typedef enum gdraw_texture {
GDRAW_TEXTURE_none, // No texture applied
GDRAW_TEXTURE_normal, // Texture is bitmap or linear gradient
GDRAW_TEXTURE_alpha, // Texture is an alpha-only font bitmap
GDRAW_TEXTURE_radial, // Texture is a radial gradient
GDRAW_TEXTURE_focal_gradient, // Texture is a "focal" radial gradient
GDRAW_TEXTURE_alpha_test, // Texture is an alpha-only font bitmap, alpha
// test for alpha >= 0.5
GDRAW_TEXTURE__count,
} gdraw_texture;
/* Specifies how to apply a texture while rendering. */
IDOC typedef enum gdraw_wrap {
GDRAW_WRAP_clamp, // Texture coordinates clamped to edges
GDRAW_WRAP_repeat, // Texture repeats periodically
GDRAW_WRAP_mirror, // Repeat periodically, mirror on odd repetititions
GDRAW_WRAP_clamp_to_border, // only used internally by some GDraws
GDRAW_WRAP__count,
} gdraw_wrap;
/* Specifies what to do with texture coordinates outside [0,1]. */
typedef struct GDrawRenderState {
S32 id; // Object "identifier" used for high-quality AA mode
U32 test_id : 1; // Whether to test zbuffer == id
U32 set_id : 1; // Whether to set zbuffer == id
U32 use_world_space : 1; // Whether primitive is defined in object space or
// world space
U32 scissor : 1; // Whether rendering will be clipped to
// $(GDrawRenderState::scissor_rect)
U32 identical_state : 1; // Whether state is identical to the one used for
// the previous draw call
U32 unused : 27;
// aligned 0 mod 8
U8 texgen0_enabled; // Whether to use texgen for tex0
U8 tex0_mode; // One of $gdraw_texture
U8 wrap0; // One of $gdraw_wrap
U8 nearest0; // Whether to sample texture 0 nearest neighbor
U8 blend_mode; // One of $gdraw_blend
U8 special_blend; // One of $gdraw_blendspecial (used only if
// $(GDrawRenderState::blend_mode) ==
// $(gdraw_blend::GDRAW_BLEND_special)
U8 filter; // One of $gdraw_filter (used only if
// $(GDrawRenderState::blend_mode) ==
// $(gdraw_blend::GDRAW_BLEND_filter)
U8 filter_mode; // Used to select the right compositing operation for the
// $(gdraw_filter::GDRAW_FILTER_bevel) and
// $(gdraw_filter::GDRAW_FILTER_dropshadow) modes
// aligned 0 mod 8
U8 stencil_test; // Only draw if these stencil bits are "set"
U8 stencil_set; // "Set" these stencil bits (note that actual
// implementation initializes stencil to 1, and "set" makes
// them 0)
U8 reserved[2]; // Currently unused (used to make padding to 4/8-byte
// boundary for following pointer explicit)
S32 blur_passes; // For filters that include blurring, this is the number
// of box filter passes to run
// align 0 mod 8
S16* cxf_add; // Color transform addition (discourage additive alpha!)
GDrawTexture* tex[3]; // One or more textures to apply -- need 3 for
// gradient dropshadow.
// 0 mod 8
F32* edge_matrix; // Screen to object space matrix (for edge antialiasing)
gswf_matrix* o2w; // Object-to-world matrix
// --- Everything below this point must be manually initialized
// 0 mod 8
F32 color[4]; // Color of the object
// 0 mod 8
gswf_recti scissor_rect; // The rectangle to which rendering will be
// clipped if $(GDrawRenderState::scissor) is set
// 0 mod 8
// --- Everything below this point might be uninitialized if it's not used
// for this particular render state
F32 s0_texgen[4]; // "s" (x) row of texgen matrix
F32 t0_texgen[4]; // "t" (y) row of texgen matrix
// 0 mod 8
F32 focal_point[4]; // Data used for
// $(gdraw_texgen_mode::GDRAW_TEXTURE_focal_gradient)
// 0 mod 8
F32 blur_x, blur_y; // The size of the box filter, where '1' is the
// identity and 2 adds half a pixel on each side
// 0 mod 8
F32 shader_data[20]; // Various data that depends on filter (e.g. drop
// shadow direction, color)
} GDrawRenderState;
/* Encapsulation of the entire drawing state that affects a rendering command.
*/
IDOC typedef void RADLINK gdraw_set_view_size_and_world_scale(
S32 w, S32 h, F32 x_world_to_pixel, F32 y_world_to_pixel);
/* Sets the size of the rendering viewport and the world to pixel scaling.
Iggy calls this function with the full size that the viewport would
be if it were rendered untiled, even if it will eventually be
rendered as a collection of smaller tiles.
The world scale is used to compensate non-square pixel aspect ratios
when rendering wide lines. Both scale factors are 1 unless Iggy is
running on a display with non-square pixels. */
typedef void RADLINK gdraw_set_3d_transform(F32* mat); /* mat[3][4] */
IDOC typedef void RADLINK gdraw_render_tile_begin(S32 tx0, S32 ty0, S32 tx1,
S32 ty1, S32 pad,
GDrawStats* stats);
/* Begins rendering of a sub-region of the rendered image. */
IDOC typedef void RADLINK gdraw_render_tile_end(GDrawStats* stats);
/* Ends rendering of a sub-region of the rendered image. */
IDOC typedef void RADLINK gdraw_rendering_begin(void);
/* Begins rendering; takes control of the graphics API. */
IDOC typedef void RADLINK gdraw_rendering_end(void);
/* Ends rendering; gives up control of the graphics API. */
////////////////////////////////////////////////////////////
//
// Drawing
//
// idoc(parent,GDrawAPI_Drawing)
IDOC typedef void RADLINK gdraw_clear_stencil_bits(U32 bits);
/* Clears the 'bits' parts of the stencil value in the entire framebuffer to the
* default value. */
IDOC typedef void RADLINK gdraw_clear_id(void);
/* Clears the 'id' buffer, which is typically the z-buffer but can also be the
* stencil buffer. */
IDOC typedef void RADLINK gdraw_filter_quad(GDrawRenderState* r, S32 x0, S32 y0,
S32 x1, S32 y1, GDrawStats* stats);
/* Draws a special quad in viewport-relative pixel space.
May be normal, may be displaced by filters, etc. and require multiple passes,
may apply special blending (and require extra resolves/rendertargets)
for filter/blend.,
The x0,y0,x1,y1 always describes the "input" box. */
IDOC typedef struct GDrawPrimitive {
F32* vertices; // Pointer to an array of $gswf_vertex_xy,
// $gswf_vertex_xyst, or $gswf_vertex_xyoffs
U16* indices; // Pointer to an array of 16-bit indices into
// $(GDrawPrimitive::vertices)
S32 num_vertices; // Count of elements in $(GDrawPrimitive::vertices)
S32 num_indices; // Count of elements in $(GDrawPrimitive::indices)
S32 vertex_format; // One of $gdraw_vformat, specifying the type of element
// in $(GDrawPrimitive::vertices)
U32 uniform_count;
F32* uniforms;
U8 drawprim_mode;
} GDrawPrimitive;
/* Specifies the vertex and index data necessary to draw a batch of graphics
* primitives. */
IDOC typedef void RADLINK gdraw_draw_indexed_triangles(GDrawRenderState* r,
GDrawPrimitive* prim,
GDrawVertexBuffer* buf,
GDrawStats* stats);
/* Draws a collection of indexed triangles, ignoring special filters or blend
modes.
If buf is NULL, then the pointers in 'prim' are machine pointers, and
you need to make a copy of the data (note currently all triangles
implementing strokes (wide lines) go this path).
If buf is non-NULL, then use the appropriate vertex buffer, and the
pointers in prim are actually offsets from the beginning of the
vertex buffer -- i.e. offset = (char*) prim->whatever - (char*) NULL;
(note there are separate spaces for vertices and indices; e.g. the
first mesh in a given vertex buffer will normally have a 0 offset
for the vertices and a 0 offset for the indices)
*/
IDOC typedef void RADLINK gdraw_set_antialias_texture(S32 width, U8* rgba);
/* Specifies the 1D texture data to be used for the antialiasing gradients.
'rgba' specifies the pixel values in rgba byte order. This will only be
called once during initialization. */
////////////////////////////////////////////////////////////
//
// Texture and Vertex Buffers
//
// idoc(parent,GDrawAPI_Buffers)
IDOC typedef enum gdraw_texture_format {
// Platform-independent formats
GDRAW_TEXTURE_FORMAT_rgba32, // 32bpp RGBA data in platform-preferred byte
// order (returned by
// $gdraw_make_texture_begin as
// $gdraw_texture_type)
GDRAW_TEXTURE_FORMAT_font, // Alpha-only data with at least 4 bits/pixel.
// Data is submitted as 8 bits/pixel, conversion
// (if necessary) done by GDraw.
// First platform-specific format index (for reference)
GDRAW_TEXTURE_FORMAT__platform = 16,
// In the future, we will support platform-specific formats and add them to
// this list.
} gdraw_texture_format;
/* Describes the format of a texture submitted to GDraw. */
IDOC typedef enum gdraw_texture_type {
GDRAW_TEXTURE_TYPE_rgba, // Raw 4-channel packed texels, in OpenGL-standard
// order
GDRAW_TEXTURE_TYPE_bgra, // Raw 4-channel packed texels, in
// Direct3D-standard order
GDRAW_TEXTURE_TYPE_argb, // Raw 4-channel packed texels, in Flash native
// order
GDRAW_TEXTURE_TYPE__count,
} gdraw_texture_type;
/* Describes the channel layout of a RGBA texture submitted to GDraw. */
IDOC typedef struct GDraw_MakeTexture_ProcessingInfo {
U8* texture_data; // Pointer to the texture image bits
S32 num_rows; // Number of rows to upload in the current chunk
S32 stride_in_bytes; // Distance between a given pixel and the first pixel
// in the next row
S32 texture_type; // One of $gdraw_texture_type
U32 temp_buffer_bytes; // Size of temp buffer in bytes
U8* temp_buffer; // Temp buffer for GDraw to work in (used during mipmap
// creation)
void *p0, *p1, *p2, *p3, *p4, *p5, *p6,
*p7; // Pointers for GDraw to store data across "passes" (never touched
// by Iggy)
U32 i0, i1, i2, i3, i4, i5, i6,
i7; // Integers for GDraw to store data across "passes" (never touched
// by Iggy)
} GDraw_MakeTexture_ProcessingInfo;
/* $GDraw_MakeTexture_ProcessingInfo is used when building a texture. */
IDOC typedef struct GDraw_Texture_Description {
S32 width; // Width of the texture in pixels
S32 height; // Height of the texture in pixels
U32 size_in_bytes; // Size of the texture in bytes
} GDraw_Texture_Description;
/* $GDraw_Texture_Description contains information about a texture. */
IDOC typedef U32 gdraw_maketexture_flags;
#define GDRAW_MAKETEXTURE_FLAGS_mipmap \
1 IDOC // Generates mip-maps for the texture
#define GDRAW_MAKETEXTURE_FLAGS_updatable \
2 IDOC // Set if the texture might be updated subsequent to its initial
// submission
#define GDRAW_MAKETEXTURE_FLAGS_never_flush \
4 IDOC // Set to request that the texture never be flushed from the GDraw
// cache
/* Flags that control the submission and management of GDraw textures. */
IDOC typedef void RADLINK gdraw_set_texture_unique_id(GDrawTexture* tex,
void* old_unique_id,
void* new_unique_id);
/* Changes unique id of a texture, only used for TextureSubstitution */
IDOC typedef rrbool RADLINK gdraw_make_texture_begin(
void* unique_id, S32 width, S32 height, gdraw_texture_format format,
gdraw_maketexture_flags flags,
GDraw_MakeTexture_ProcessingInfo* output_info, GDrawStats* stats);
/* Begins specifying a new texture.
$:unique_id Unique value specified by Iggy that you can use to identify a
reference to the same texture even if its handle has been discarded
$:return Error code if there was a problem, IGGY_RESULT_OK otherwise
*/
IDOC typedef rrbool RADLINK
gdraw_make_texture_more(GDraw_MakeTexture_ProcessingInfo* info);
/* Continues specifying a new texture.
$:info The same handle initially passed to $gdraw_make_texture_begin
$:return True if specification can continue, false if specification must be
aborted
*/
IDOC typedef GDrawTexture* RADLINK gdraw_make_texture_end(
GDraw_MakeTexture_ProcessingInfo* info, GDrawStats* stats);
/* Ends specification of a new texture.
$:info The same handle initially passed to $gdraw_make_texture_begin
$:return Handle for the newly created texture, or NULL if an error occured
*/
IDOC typedef rrbool RADLINK gdraw_update_texture_begin(GDrawTexture* tex,
void* unique_id,
GDrawStats* stats);
/* Begins updating a previously submitted texture.
$:unique_id Must be the same value initially passed to
$gdraw_make_texture_begin
$:return True on success, false otherwise and the texture must be recreated
*/
IDOC typedef void RADLINK gdraw_update_texture_rect(
GDrawTexture* tex, void* unique_id, S32 x, S32 y, S32 stride, S32 w, S32 h,
U8* data, gdraw_texture_format format);
/* Updates a rectangle in a previously submitted texture.
$:format Must be the $gdraw_texture_format that was originally passed to
$gdraw_make_texture_begin for this texture.
*/
IDOC typedef void RADLINK gdraw_update_texture_end(GDrawTexture* tex,
void* unique_id,
GDrawStats* stats);
/* Ends an update to a previously submitted texture.
$:unique_id Must be the same value initially passed to
$gdraw_make_texture_begin (and hence $gdraw_update_texture_begin)
*/
IDOC typedef void RADLINK
gdraw_describe_texture(GDrawTexture* tex, GDraw_Texture_Description* desc);
/* Returns a texture description for a given GDraw texture. */
IDOC typedef GDrawTexture* RADLINK gdraw_make_texture_from_resource(
U8* resource_file, S32 file_len, void* texture);
/* Loads a texture from a resource file and returns a wrapped pointer. */
IDOC typedef void RADLINK gdraw_free_texture_from_resource(GDrawTexture* tex);
/* Frees a texture created with gdraw_make_texture_from_resource. */
IDOC typedef struct gswf_vertex_xy {
F32 x, y; // Position of the vertex
} gswf_vertex_xy;
/* A 2D point with floating-point position. */
IDOC typedef struct gswf_vertex_xyoffs {
F32 x, y; // Position of the vertex
S16 aa; // Stroke/aa texcoord
S16 dx, dy; // Vector offset from the position, used for anti-aliasing
// (signed 11.5 fixed point)
S16 unused;
} gswf_vertex_xyoffs;
/* A 2D point with floating-point position, additional integer parameter, and
* integer anti-aliasing offset vector. */
IDOC typedef struct gswf_vertex_xyst {
F32 x, y; // Position of the vertex
F32 s, t; // Explicit texture coordinates for rectangles
} gswf_vertex_xyst;
/* A 2D point with floating-point position and texture coordinates. */
typedef int gdraw_verify_size_xy[sizeof(gswf_vertex_xy) == 8 ? 1 : -1];
typedef int gdraw_verify_size_xyoffs[sizeof(gswf_vertex_xyoffs) == 16 ? 1 : -1];
typedef int gdraw_verify_size_xyst[sizeof(gswf_vertex_xyst) == 16 ? 1 : -1];
IDOC typedef enum gdraw_vformat {
GDRAW_vformat_v2, // Indicates vertices of type $gswf_vertex_xy (8 bytes
// per vertex)
GDRAW_vformat_v2aa, // Indicates vertices of type $gswf_vertex_xyoffs (16
// bytes per vertex)
GDRAW_vformat_v2tc2, // Indicates vertices of type $gswf_vertex_xyst (16
// bytes per vertex)
GDRAW_vformat__basic_count,
GDRAW_vformat_ihud1 =
GDRAW_vformat__basic_count, // primary format for ihud, currently
// v2tc2mat4 (20 bytes per vertex)
GDRAW_vformat__count,
GDRAW_vformat_mixed, // Special value that denotes a VB containing data in
// multiple vertex formats. Never used when drawing!
} gdraw_vformat;
/* Identifies one of the vertex data types. */
IDOC typedef struct GDraw_MakeVertexBuffer_ProcessingInfo {
U8* vertex_data; // location to write vertex data
U8* index_data; // location to write index data
S32 vertex_data_length; // size of buffer to write vertex data
S32 index_data_length; // size of buffer to write index data
void *p0, *p1, *p2, *p3, *p4, *p5, *p6,
*p7; // Pointers for GDraw to store data across "passes" (never touched
// by Iggy)
U32 i0, i1, i2, i3, i4, i5, i6,
i7; // Integers for GDraw to store data across "passes" (never touched
// by Iggy)
} GDraw_MakeVertexBuffer_ProcessingInfo;
/* $GDraw_MakeVertexBuffer_ProcessingInfo is used when building a vertex buffer.
*/
IDOC typedef struct GDraw_VertexBuffer_Description {
S32 size_in_bytes; // Size of the vertex buffer in bytes
} GDraw_VertexBuffer_Description;
/* $GDraw_VertexBuffer_Description contains information about a vertex buffer.
*/
IDOC typedef rrbool RADLINK gdraw_make_vertex_buffer_begin(
void* unique_id, gdraw_vformat vformat, S32 vdata_len_in_bytes,
S32 idata_len_in_bytes, GDraw_MakeVertexBuffer_ProcessingInfo* info,
GDrawStats* stats);
/* Begins specifying a new vertex buffer.
$:unique_id Unique value that identifies this texture, across potentially
multiple flushes and re-creations of its $GDrawTexture handle in GDraw
$:vformat One of $gdraw_vformat, denoting the format of the vertex data
submitted
$:return false if there was a problem, true if ok
*/
IDOC typedef rrbool RADLINK
gdraw_make_vertex_buffer_more(GDraw_MakeVertexBuffer_ProcessingInfo* info);
/* Continues specifying a new vertex buffer.
$:info The same handle initially passed to $gdraw_make_vertex_buffer_begin
$:return True if specification can continue, false if specification must be
aborted
*/
IDOC typedef GDrawVertexBuffer* RADLINK gdraw_make_vertex_buffer_end(
GDraw_MakeVertexBuffer_ProcessingInfo* info, GDrawStats* stats);
/* Ends specification of a new vertex buffer.
$:info The same handle initially passed to $gdraw_make_texture_begin
$:return Handle for the newly created vertex buffer
*/
IDOC typedef void RADLINK gdraw_describe_vertex_buffer(
GDrawVertexBuffer* buffer, GDraw_VertexBuffer_Description* desc);
/* Returns a description for a given GDrawVertexBuffer */
IDOC typedef rrbool RADLINK gdraw_try_to_lock_texture(GDrawTexture* tex,
void* unique_id,
GDrawStats* stats);
/* Tells GDraw that a $GDrawTexture is going to be referenced.
$:unique_id Must be the same value initially passed to
$gdraw_make_texture_begin
*/
IDOC typedef rrbool RADLINK gdraw_try_to_lock_vertex_buffer(
GDrawVertexBuffer* vb, void* unique_id, GDrawStats* stats);
/* Tells GDraw that a $GDrawVertexBuffer is going to be referenced.
$:unique_id Must be the same value initially passed to
$gdraw_make_vertex_buffer_begin
*/
IDOC typedef void RADLINK gdraw_unlock_handles(GDrawStats* stats);
/* Indicates that the user of GDraw will not try to reference anything without
locking it again.
Note that although a call to $gdraw_unlock_handles indicates that
all $GDrawTexture and $GDrawVertexBuffer handles that have had a
"unique_id" specified will no longer be referenced by the user of
GDraw, it does not affect those $GDrawTexture handles that were
created by $gdraw_start_texture_draw_buffer with a unique_id of 0.
*/
IDOC typedef void RADLINK gdraw_free_vertex_buffer(GDrawVertexBuffer* vb,
void* unique_id,
GDrawStats* stats);
/* Free a vertex buffer and invalidate the handle
$:unique_id Must be the same value initially passed to
$gdraw_make_vertex_buffer_begin
*/
IDOC typedef void RADLINK gdraw_free_texture(GDrawTexture* t, void* unique_id,
GDrawStats* stats);
/* Free a texture and invalidate the handle.
$:unique_id Must be the same value initially passed to
$gdraw_make_texture_begin, or 0 for a texture created by
$gdraw_end_texture_draw_buffer
*/
////////////////////////////////////////////////////////////
//
// Render targets
//
// idoc(parent,GDrawAPI_Targets)
IDOC typedef U32 gdraw_texturedrawbuffer_flags;
#define GDRAW_TEXTUREDRAWBUFFER_FLAGS_needs_color \
1 IDOC // Tells GDraw that you will need the color channel when rendering a
// texture
#define GDRAW_TEXTUREDRAWBUFFER_FLAGS_needs_alpha \
2 IDOC // Tells GDraw that you will need the alpha channel when rendering a
// texture
#define GDRAW_TEXTUREDRAWBUFFER_FLAGS_needs_stencil \
4 IDOC // Tells GDraw that you will need the stencil channel when rendering
// a texture
#define GDRAW_TEXTUREDRAWBUFFER_FLAGS_needs_id \
8 IDOC // Tells GDraw that you will need the id channel when rendering a
// texture
/* Flags that control rendering to a texture. */
IDOC typedef rrbool RADLINK gdraw_texture_draw_buffer_begin(
gswf_recti* region, gdraw_texture_format format,
gdraw_texturedrawbuffer_flags flags, void* unique_id, GDrawStats* stats);
/* Starts rendering all GDraw commands to a new texture.
Creates a rendertarget with destination alpha, initializes to all 0s and
prepares to render into it
*/
IDOC typedef GDrawTexture* RADLINK
gdraw_texture_draw_buffer_end(GDrawStats* stats);
/* Ends rendering GDraw commands to a texture, and returns the texture created.
You can get the size of the resulting texture with $gdraw_query_texture_size.
*/
////////////////////////////////////////////////////////////
//
// Masking
//
// idoc(parent,GDrawAPI_Masking)
IDOC typedef void RADLINK gdraw_draw_mask_begin(gswf_recti* region,
S32 mask_bit,
GDrawStats* stats);
/* Start a masking operation on the given region for the specified mask bit.
For most drivers, no special preparation is necessary to start masking, so
this is a no-op.
*/
IDOC typedef void RADLINK gdraw_draw_mask_end(gswf_recti* region, S32 mask_bit,
GDrawStats* stats);
/* End a masking operation on the given region for the specified mask bit.
For most drivers, no special preparation is necessary to end masking, so this
is a no-op.
*/
////////////////////////////////////////////////////////////
//
// GDraw API Function table
//
// idoc(parent,GDrawAPI_Base)
IDOC struct GDrawFunctions {
// queries
gdraw_get_info* GetInfo;
// drawing state
gdraw_set_view_size_and_world_scale* SetViewSizeAndWorldScale;
gdraw_render_tile_begin* RenderTileBegin;
gdraw_render_tile_end* RenderTileEnd;
gdraw_set_antialias_texture* SetAntialiasTexture;
// drawing
gdraw_clear_stencil_bits* ClearStencilBits;
gdraw_clear_id* ClearID;
gdraw_filter_quad* FilterQuad;
gdraw_draw_indexed_triangles* DrawIndexedTriangles;
gdraw_make_texture_begin* MakeTextureBegin;
gdraw_make_texture_more* MakeTextureMore;
gdraw_make_texture_end* MakeTextureEnd;
gdraw_make_vertex_buffer_begin* MakeVertexBufferBegin;
gdraw_make_vertex_buffer_more* MakeVertexBufferMore;
gdraw_make_vertex_buffer_end* MakeVertexBufferEnd;
gdraw_try_to_lock_texture* TryToLockTexture;
gdraw_try_to_lock_vertex_buffer* TryToLockVertexBuffer;
gdraw_unlock_handles* UnlockHandles;
gdraw_free_texture* FreeTexture;
gdraw_free_vertex_buffer* FreeVertexBuffer;
gdraw_update_texture_begin* UpdateTextureBegin;
gdraw_update_texture_rect* UpdateTextureRect;
gdraw_update_texture_end* UpdateTextureEnd;
// rendertargets
gdraw_texture_draw_buffer_begin* TextureDrawBufferBegin;
gdraw_texture_draw_buffer_end* TextureDrawBufferEnd;
gdraw_describe_texture* DescribeTexture;
gdraw_describe_vertex_buffer* DescribeVertexBuffer;
// new functions are always added at the end, so these have no structure
gdraw_set_texture_unique_id* SetTextureUniqueID;
gdraw_draw_mask_begin* DrawMaskBegin;
gdraw_draw_mask_end* DrawMaskEnd;
gdraw_rendering_begin* RenderingBegin;
gdraw_rendering_end* RenderingEnd;
gdraw_make_texture_from_resource* MakeTextureFromResource;
gdraw_free_texture_from_resource* FreeTextureFromResource;
gdraw_set_3d_transform* Set3DTransform;
};
/* The function interface called by Iggy to render graphics on all
platforms.
So that Iggy can integrate with the widest possible variety of
rendering scenarios, all of its renderer-specific drawing calls
go through this table of function pointers. This allows you
to dynamically configure which of RAD's supplied drawing layers
you wish to use, or to integrate it directly into your own
renderer by implementing your own versions of the drawing
functions Iggy requires.
*/
RADDEFEND
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,55 +0,0 @@
#ifndef __RAD_INCLUDE_IGGYEXPRUNTIME_H__
#define __RAD_INCLUDE_IGGYEXPRUNTIME_H__
#include "rrCore.h"
#define IDOC
RADDEFSTART
#ifndef __RAD_HIGGYEXP_
#define __RAD_HIGGYEXP_
typedef void* HIGGYEXP;
#endif
// idoc(parent,IggyExpRuntime_API)
#define IGGYEXP_MIN_STORAGE 1024 IDOC
/* The minimum-sized block you must provide to $IggyExpCreate */
IDOC RADEXPFUNC HIGGYEXP RADEXPLINK IggyExpCreate(char* ip_address, S32 port,
void* storage,
S32 storage_size_in_bytes);
/* Opens a connection to $IggyExplorer and returns an $HIGGYEXP wrapping the
connection.
$:ip_address The address of the machine running Iggy Explorer (can be numeric
with dots, or textual, including "localhost")
$:port The port number on which Iggy Explorer is listening for a network
connection (the default is 9190)
$:storage A small block of storage that needed to store the $HIGGYEXP, must
be at least $IGGYEXP_MIN_STORAGE
$:storage_size_in_bytes The size of the block pointer to by <tt>storage</tt>
Returns a NULL HIGGYEXP if the IP address/hostname can't be resolved, or no Iggy
Explorer can be contacted at the specified address/port. Otherwise returns a
non-NULL $HIGGYEXP which you can pass to $IggyUseExplorer. */
IDOC RADEXPFUNC void RADEXPLINK IggyExpDestroy(HIGGYEXP p);
/* Closes and destroys a connection to $IggyExplorer */
IDOC RADEXPFUNC rrbool RADEXPLINK IggyExpCheckValidity(HIGGYEXP p);
/* Checks if the connection represented by an $HIGGYEXP is still valid, i.e.
still connected to $IggyExplorer.
Returns true if the connection is still valid; returns false if it is not valid.
This might happen if someone closes Iggy Explorer, Iggy Explorer crashes, or
the network fails. You can this to poll and detect these conditions and do
something in response, such as trying to open a new connection.
An invalid $HIGGYEXP must still be shutdown with $IggyExpDestroy. */
RADDEFEND
#endif //__RAD_INCLUDE_IGGYEXPRUNTIME_H__

View file

@ -1,106 +0,0 @@
// $$COPYRIGHT$$
#ifndef __RAD_INCLUDE_IGGYPERFMON_H__
#define __RAD_INCLUDE_IGGYPERFMON_H__
#include "rrCore.h"
#define IDOC
RADDEFSTART
#ifndef __RAD_HIGGYPERFMON_
#define __RAD_HIGGYPERFMON_
typedef void* HIGGYPERFMON;
#endif
// idoc(parent,IggyPerfmon_API)
typedef void* RADLINK iggyperfmon_malloc(void* handle, U32 size);
typedef void RADLINK iggyperfmon_free(void* handle, void* ptr);
IDOC RADEXPFUNC HIGGYPERFMON RADEXPLINK
IggyPerfmonCreate(iggyperfmon_malloc* perf_malloc, iggyperfmon_free* perf_free,
void* callback_handle);
/* Creates an IggyPerfmon.
You must supply allocator functions. The amount allocated depends on the
complexity of the Iggys being profiled. */
typedef struct Iggy Iggy;
typedef struct GDrawFunctions GDrawFunctions;
IDOC typedef union {
U32 bits;
struct {
U32 dpad_up : 1;
U32 dpad_down : 1;
U32 dpad_left : 1;
U32 dpad_right : 1;
U32 button_up : 1; // XBox Y, PS3 tri
U32 button_down : 1; // XBox A, PS3 X
U32 button_left : 1; // XBox X, PS3 square
U32 button_right : 1; // XBox B, PS3 circle
U32 shoulder_left_hi : 1; // LB/L1
U32 shoulder_right_hi : 1; // RB/R1
U32 trigger_left_low : 1;
U32 trigger_right_low : 1;
} field;
} IggyPerfmonPad;
#define IggyPerfmonPadFromXInputStatePointer(pad, xis) \
(pad).bits = 0, \
(pad).field.dpad_up = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP), \
(pad).field.dpad_down = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN), \
(pad).field.dpad_left = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT), \
(pad).field.dpad_right = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT), \
(pad).field.button_up = 0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_Y), \
(pad).field.button_down = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_A), \
(pad).field.button_left = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_X), \
(pad).field.button_right = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_B), \
(pad).field.shoulder_left_hi = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER), \
(pad).field.shoulder_right_hi = \
0 != ((xis)->Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER), \
(pad).field.trigger_left_low = 0 != ((xis)->Gamepad.bLeftTrigger >= \
XINPUT_GAMEPAD_TRIGGER_THRESHOLD), \
(pad).field.trigger_right_low = 0 != ((xis)->Gamepad.bRightTrigger >= \
XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
// All positions in window coords
IDOC RADEXPFUNC void RADEXPLINK IggyPerfmonTickAndDraw(
HIGGYPERFMON p, GDrawFunctions* gdraw_funcs, const IggyPerfmonPad* pad,
int pm_tile_ul_x, int pm_tile_ul_y, int pm_tile_lr_x, int pm_tile_lr_y);
/* Draw and tick an IggyPerfmon.
$:p A perfmon context previously created with IggyPerfmonCreate
$:gdraw_functions The same GDraw handle used for rendering Iggy
$:pad An abstracted gamepad state structure. iggyperfmon.h
includes an example that initializes the abstract gamepad from a 360 controller
as defined by XInput; this will work on both Windows and the Xbox 360.
$:pm_tile_ul_x The left coordinate of the rectangle where the perfmon display
should be drawn
$:pm_tile_ul_y The top coordinate of the rectangle where the perfmon display
should be drawn
$:pm_tile_lr_x The right coordinate of the rectangle where the perfmon display
should be drawn
$:pm_tile_lr_y The bottom coordinate of the rectangle where the perfmon display
should be drawn
You should only call this function when you want Iggy Perfmon to be visible.
See $IggyPerfmon for more information. */
IDOC RADEXPFUNC void RADEXPLINK IggyPerfmonDestroy(HIGGYPERFMON p,
GDrawFunctions* iggy_draw);
/* Closes and destroys an IggyPerfmon */
RADDEFEND
#endif //__RAD_INCLUDE_IGGYPERFMON_H__

File diff suppressed because it is too large Load diff

View file

@ -1,100 +0,0 @@

#include "WindowsGame.h"
#include "platform/game/game.h"
#include "app/common/Game.h"
#include "minecraft/client/Minecraft.h"
#include "minecraft/client/User.h"
#include "minecraft/server/MinecraftServer.h"
#include "minecraft/server/PlayerList.h"
#include "minecraft/server/level/ServerPlayer.h"
#include "minecraft/world/level/Level.h"
#include "minecraft/world/level/LevelSettings.h"
#include "minecraft/world/level/LevelType.h"
#include "minecraft/world/level/biome/BiomeSource.h"
WindowsGame app;
#define CONTEXT_GAME_STATE 0
WindowsGame::WindowsGame() : Game() {}
void WindowsGame::StoreLaunchData() {}
void WindowsGame::ExitGame() {}
void WindowsGame::FatalLoadError() {}
void WindowsGame::TemporaryCreateGameStart() {
//////////////////////////////////////////////////////////////////////////////////////////////
/// From CScene_Main::OnInit
app.setLevelGenerationOptions(nullptr);
// From CScene_Main::RunPlayGame
Minecraft* pMinecraft = Minecraft::GetInstance();
PlatformGame.ReleaseSaveThumbnail();
PlatformProfile.SetLockedProfile(0);
pMinecraft->user->name = "Windows";
app.ApplyGameSettingsChanged(0);
//////////////////////////////////////////////////////////////////////////////////////////////
/// From CScene_MultiGameJoinLoad::OnInit
MinecraftServer::resetFlags();
// From CScene_MultiGameJoinLoad::OnNotifyPressEx
app.SetTutorialMode(false);
app.SetCorruptSaveDeleted(false);
//////////////////////////////////////////////////////////////////////////////////////////////
/// From CScene_MultiGameCreate::CreateGame
app.ClearTerrainFeaturePosition();
std::string wWorldName = "TestWorld";
PlatformStorage.ResetSaveData();
PlatformStorage.SetSaveTitle(wWorldName.c_str());
bool isFlat = false;
int64_t seedValue =
0; // BiomeSource::findSeed(isFlat?LevelType::lvl_flat:LevelType::lvl_normal);
// // 4J - was (new Random())->nextLong() - now trying to actually
// find a seed to suit our requirements
NetworkGameInitData* param = new NetworkGameInitData();
param->seed = seedValue;
param->saveData = nullptr;
app.SetGameHostOption(eGameHostOption_Difficulty, 0);
app.SetGameHostOption(eGameHostOption_FriendsOfFriends, 0);
app.SetGameHostOption(eGameHostOption_Gamertags, 1);
app.SetGameHostOption(eGameHostOption_BedrockFog, 1);
app.SetGameHostOption(
eGameHostOption_GameType,
GameType::CREATIVE->getId()); // LevelSettings::GAMETYPE_SURVIVAL
app.SetGameHostOption(eGameHostOption_LevelType, 0);
app.SetGameHostOption(eGameHostOption_Structures, 1);
app.SetGameHostOption(eGameHostOption_BonusChest, 0);
app.SetGameHostOption(eGameHostOption_PvP, 1);
app.SetGameHostOption(eGameHostOption_TrustPlayers, 1);
app.SetGameHostOption(eGameHostOption_FireSpreads, 1);
app.SetGameHostOption(eGameHostOption_TNT, 1);
app.SetGameHostOption(eGameHostOption_HostCanFly, 1);
app.SetGameHostOption(eGameHostOption_HostCanChangeHunger, 1);
app.SetGameHostOption(eGameHostOption_HostCanBeInvisible, 1);
param->settings = app.GetGameHostOption(eGameHostOption_All);
g_NetworkManager.FakeLocalPlayerJoined();
LoadingInputParams* loadingParams = new LoadingInputParams();
loadingParams->func = &CGameNetworkManager::RunNetworkGameThreadProc;
loadingParams->lpParam = param;
// Reset the autosave time
app.SetAutosaveTimerTime();
C4JThread* thread = new C4JThread(loadingParams->func,
loadingParams->lpParam, "RunNetworkGame");
thread->run();
}

View file

@ -1,179 +0,0 @@
#include "Windows64_UIController.h"
// Temp
#include "minecraft/client/Minecraft.h"
#include "minecraft/client/renderer/Textures.h"
#define _ENABLEIGGY
ConsoleUIController ui;
void ConsoleUIController::init(ID3D11Device* dev, ID3D11DeviceContext* ctx,
ID3D11RenderTargetView* pRenderTargetView,
ID3D11DepthStencilView* pDepthStencilView, S32 w,
S32 h) {
#ifdef _ENABLEIGGY
m_pRenderTargetView = pRenderTargetView;
m_pDepthStencilView = pDepthStencilView;
// Shared init
preInit(w, h);
gdraw_funcs = gdraw_D3D11_CreateContext(dev, ctx, w, h);
if (!gdraw_funcs) {
app.DebugPrintf("Failed to initialise GDraw!\n");
#ifndef _CONTENT_PACKAGE
assert(0);
#endif
app.FatalLoadError();
}
/* For each of the resource types, we specify the size of the cache that
GDraw will use. We specify both the number of possible objects
(the number of "handles") of each type, and the maximum memory
to use for each one.
For some platforms, we would actually pass
in the memory to use, and the GDraw will strictly obey the resource
request. For D3D, storage is managed by D3D, and GDraw only
approximates the requested storage amount. In fact, you don't
even have to set these at all for D3D, which has some "reasonable" defaults,
but we'll set it here for clarity.
(The storage required for
the handles is separate, and always allocated through the global allocator
specified in IggyInit.)
The size that's actually needed here depends on the content of your
Flash file. There's more info in the documentation about how to
determine how big they should be. But for now, we'll just set them
really big so if you substitute a different file it should work. */
gdraw_D3D11_SetResourceLimits(GDRAW_D3D11_RESOURCE_vertexbuffer, 5000,
16 * 1024 * 1024);
gdraw_D3D11_SetResourceLimits(GDRAW_D3D11_RESOURCE_texture, 5000,
128 * 1024 * 1024);
gdraw_D3D11_SetResourceLimits(GDRAW_D3D11_RESOURCE_rendertarget, 10,
32 * 1024 * 1024);
/* GDraw is all set, so we'll point Iggy at it. */
IggySetGDraw(gdraw_funcs);
/* Flash content can have audio embedded. We'd like to be able
to play back any audio there is in the Flash that we load,
but in this tutorial we don't care about processing the sound
ourselves. So we call $IggyAudioUseDirectSound to tell Iggy
to go ahead and send any sound from the Flash movie directly
to Win32's default DirectSound device. */
IggyAudioUseDirectSound();
// Shared init
postInit();
#endif
}
void ConsoleUIController::render() {
#ifdef _ENABLEIGGY
/* Now that we've cleared, we need to tell GDraw which
render target to use, what depth/stencil buffer to use,
and where the origin should be.
If we were using multisampling, we'd also need to give
GDraw a render target view for a non-multisampled texture
the size of main_rtv as a resolve target (this is the third
parameter). But since we're not using multisampling in this
example, no resolve targets are required. */
gdraw_D3D11_SetTileOrigin(m_pRenderTargetView, m_pDepthStencilView, nullptr,
0, 0);
renderScenes();
/* Finally we're ready to display the frame. We call GDraw to
let it know we're done rendering, so it can do any finalization
it needs to do. */
gdraw_D3D11_NoMoreGDrawThisFrame();
#endif
}
void ConsoleUIController::beginIggyCustomDraw4J(
IggyCustomDrawCallbackRegion* region, CustomDrawData* customDrawRegion) {
// get the correct object-to-world matrix from GDraw, and set the render
// state to a normal state
gdraw_D3D11_BeginCustomDraw_4J(region, customDrawRegion->mat);
}
CustomDrawData* ConsoleUIController::setupCustomDraw(
UIScene* scene, IggyCustomDrawCallbackRegion* region) {
CustomDrawData* customDrawRegion = new CustomDrawData();
customDrawRegion->x0 = region->x0;
customDrawRegion->x1 = region->x1;
customDrawRegion->y0 = region->y0;
customDrawRegion->y1 = region->y1;
// get the correct object-to-world matrix from GDraw, and set the render
// state to a normal state
gdraw_D3D11_BeginCustomDraw_4J(region, customDrawRegion->mat);
setupCustomDrawGameStateAndMatrices(scene, customDrawRegion);
return customDrawRegion;
}
CustomDrawData* ConsoleUIController::calculateCustomDraw(
IggyCustomDrawCallbackRegion* region) {
CustomDrawData* customDrawRegion = new CustomDrawData();
customDrawRegion->x0 = region->x0;
customDrawRegion->x1 = region->x1;
customDrawRegion->y0 = region->y0;
customDrawRegion->y1 = region->y1;
gdraw_D3D11_CalculateCustomDraw_4J(region, customDrawRegion->mat);
return customDrawRegion;
}
void ConsoleUIController::endCustomDraw(IggyCustomDrawCallbackRegion* region) {
endCustomDrawGameStateAndMatrices();
gdraw_D3D11_EndCustomDraw(region);
}
void ConsoleUIController::setTileOrigin(S32 xPos, S32 yPos) {
gdraw_D3D11_SetTileOrigin(m_pRenderTargetView, m_pDepthStencilView, nullptr,
xPos, yPos);
}
GDrawTexture* ConsoleUIController::getSubstitutionTexture(int textureId) {
/* Create a wrapped texture from a shader resource view.
A wrapped texture can be used to let Iggy draw using the contents of a
texture you create and manage on your own. For example, you might render to
this texture, or stream video into it. Wrapped textures take up a handle.
They will never be freed or otherwise modified by GDraw; nor will GDraw
change any reference counts. All this is up to the application. */
ID3D11ShaderResourceView* tex =
PlatformRenderer.TextureGetTexture(textureId);
ID3D11Resource* resource;
tex->GetResource(&resource);
ID3D11Texture2D* tex2d = (ID3D11Texture2D*)resource;
D3D11_TEXTURE2D_DESC desc;
tex2d->GetDesc(&desc);
GDrawTexture* gdrawTex = gdraw_D3D11_WrappedTextureCreate(tex);
return gdrawTex;
}
void ConsoleUIController::destroySubstitutionTexture(void* destroyCallBackData,
GDrawTexture* handle) {
/* Destroys the GDraw wrapper for a wrapped texture object. This will free
up a GDraw texture handle but not release the associated D3D texture; that
is up to you. */
gdraw_D3D11_WrappedTextureDestroy(handle);
}
void ConsoleUIController::shutdown() {
#ifdef _ENABLEIGGY
/* Destroy the GDraw context. This frees all resources, shaders etc.
allocated by GDraw. Note this is only safe to call after all
active Iggy player have been destroyed! */
gdraw_D3D11_DestroyContext();
#endif
}

View file

@ -1,36 +0,0 @@
#pragma once
#include "app/common/UI/UIController.h"
class ConsoleUIController : public UIController {
private:
ID3D11RenderTargetView* m_pRenderTargetView;
ID3D11DepthStencilView* m_pDepthStencilView;
public:
void init(ID3D11Device* dev, ID3D11DeviceContext* ctx,
ID3D11RenderTargetView* pRenderTargetView,
ID3D11DepthStencilView* pDepthStencilView, S32 w, S32 h);
void render();
void beginIggyCustomDraw4J(IggyCustomDrawCallbackRegion* region,
CustomDrawData* customDrawRegion);
virtual CustomDrawData* setupCustomDraw(
UIScene* scene, IggyCustomDrawCallbackRegion* region);
virtual CustomDrawData* calculateCustomDraw(
IggyCustomDrawCallbackRegion* region);
virtual void endCustomDraw(IggyCustomDrawCallbackRegion* region);
protected:
virtual void setTileOrigin(S32 xPos, S32 yPos);
public:
GDrawTexture* getSubstitutionTexture(int textureId);
void destroySubstitutionTexture(void* destroyCallBackData,
GDrawTexture* handle);
public:
void shutdown();
};
extern ConsoleUIController ui;

View file

@ -1,17 +0,0 @@
#pragma once
class WindowsGame : public Game {
public:
WindowsGame();
virtual void StoreLaunchData();
virtual void ExitGame();
virtual void FatalLoadError();
C4JStringTable* GetStringTable() { return nullptr; }
// original code
virtual void TemporaryCreateGameStart();
};
extern WindowsGame app;

View file

@ -1,821 +0,0 @@
// 4J-PB -
// The ATG Framework is a common set of C++ class libraries that is used by the
// samples in the XDK, and was developed by the Advanced Technology Group (ATG).
// The ATG Framework offers a clean and consistent format for the samples. These
// classes define functions used by all the samples. The ATG Framework together
// with the samples demonstrates best practices and innovative techniques for
// Xbox 360. There are many useful sections of code in the samples. You are
// encouraged to incorporate this code into your titles.
//-------------------------------------------------------------------------------------
// AtgXmlParser.cpp
//
// Simple callback non-validating XML parser implementation.
//
// Xbox Advanced Technology Group.
// Copyright (C) Microsoft Corporation. All rights reserved.
//-------------------------------------------------------------------------------------
#include "ATGXmlParser.h"
#include <cstring>
namespace ATG {
//-------------------------------------------------------------------------------------
// Name: XMLParser::XMLParser
//-------------------------------------------------------------------------------------
XMLParser::XMLParser() {
m_pWritePtr = m_pWriteBuf;
m_pReadPtr = m_pReadBuf;
m_pISAXCallback = nullptr;
m_hFile = INVALID_HANDLE_VALUE;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::~XMLParser
//-------------------------------------------------------------------------------------
XMLParser::~XMLParser() {}
//-------------------------------------------------------------------------------------
// Name: XMLParser::FillBuffer
// Desc: Reads a block from the current open file
//-------------------------------------------------------------------------------------
void XMLParser::FillBuffer() {
uint32_t NChars;
m_pReadPtr = m_pReadBuf;
if (m_hFile == nullptr) {
if (m_uInXMLBufferCharsLeft > XML_READ_BUFFER_SIZE)
NChars = XML_READ_BUFFER_SIZE;
else
NChars = m_uInXMLBufferCharsLeft;
std::memcpy(m_pReadBuf, m_pInXMLBuffer, NChars);
m_uInXMLBufferCharsLeft -= NChars;
m_pInXMLBuffer += NChars;
} else {
if (!ReadFile(m_hFile, m_pReadBuf, XML_READ_BUFFER_SIZE, &NChars,
nullptr)) {
return;
}
}
m_dwCharsConsumed += NChars;
int64_t iProgress =
m_dwCharsTotal
? (((int64_t)m_dwCharsConsumed * 1000) / (int64_t)m_dwCharsTotal)
: 0;
m_pISAXCallback->SetParseProgress((uint32_t)iProgress);
m_pReadBuf[NChars] = '\0';
m_pReadBuf[NChars + 1] = '\0';
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::SkipNextAdvance
// Desc: Puts the last character read back on the input stream
//-------------------------------------------------------------------------------------
void XMLParser::SkipNextAdvance() { m_bSkipNextAdvance = true; }
//-------------------------------------------------------------------------------------
// Name: XMLParser::ConsumeSpace
// Desc: Skips spaces in the current stream
//-------------------------------------------------------------------------------------
int32_t XMLParser::ConsumeSpace() {
int32_t hr;
// Skip spaces
if (FAILED(hr = AdvanceCharacter())) return hr;
while ((m_Ch == ' ') || (m_Ch == '\t') || (m_Ch == '\n') ||
(m_Ch == '\r')) {
if (FAILED(hr = AdvanceCharacter())) return hr;
}
SkipNextAdvance();
return 0;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::ConvertEscape
// Desc: Copies and converts an escape sequence into m_pWriteBuf
//-------------------------------------------------------------------------------------
int32_t XMLParser::ConvertEscape() {
int32_t hr;
char wVal = 0;
if (FAILED(hr = AdvanceCharacter())) return hr;
// all escape sequences start with &, so ignore the first character
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch == '#') // character as hex or decimal
{
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch == 'x') // hex number
{
if (FAILED(hr = AdvanceCharacter())) return hr;
while (m_Ch != ';') {
wVal *= 16;
if ((m_Ch >= '0') && (m_Ch <= '9')) {
wVal += m_Ch - '0';
} else if ((m_Ch >= 'a') && (m_Ch <= 'f')) {
wVal += m_Ch - 'a' + 10;
} else if ((m_Ch >= 'A') && (m_Ch <= 'F')) {
wVal += m_Ch - 'A' + 10;
} else {
Error(E_INVALID_XML_SYNTAX,
"Expected hex digit as part of &#x escape sequence");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCharacter())) return hr;
}
} else // decimal number
{
while (m_Ch != ';') {
wVal *= 10;
if ((m_Ch >= '0') && (m_Ch <= '9')) {
wVal += m_Ch - '0';
} else {
Error(
E_INVALID_XML_SYNTAX,
"Expected decimal digit as part of &# escape sequence");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCharacter())) return hr;
}
}
// copy character into the buffer
m_Ch = wVal;
return 0;
}
// must be an entity reference
char* pEntityRefVal = m_pWritePtr;
uint32_t EntityRefLen;
SkipNextAdvance();
if (FAILED(hr = AdvanceName())) return hr;
EntityRefLen = (uint32_t)(m_pWritePtr - pEntityRefVal);
m_pWritePtr = pEntityRefVal;
if (EntityRefLen == 0) {
Error(E_INVALID_XML_SYNTAX, "Expecting entity name after &");
return E_INVALID_XML_SYNTAX;
}
if (!strncmp(pEntityRefVal, "lt", EntityRefLen))
wVal = '<';
else if (!strncmp(pEntityRefVal, "gt", EntityRefLen))
wVal = '>';
else if (!strncmp(pEntityRefVal, "amp", EntityRefLen))
wVal = '&';
else if (!strncmp(pEntityRefVal, "apos", EntityRefLen))
wVal = '\'';
else if (!strncmp(pEntityRefVal, "quot", EntityRefLen))
wVal = '"';
else {
Error(E_INVALID_XML_SYNTAX,
"Unrecognized entity name after & - (should be lt, gt, amp, "
"apos, or quot)");
return E_INVALID_XML_SYNTAX; // return false if unrecognized token
// sequence
}
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != ';') {
Error(E_INVALID_XML_SYNTAX,
"Expected terminating ; for entity reference");
return E_INVALID_XML_SYNTAX; // malformed reference - needs terminating
// ;
}
m_Ch = wVal;
return 0;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::AdvanceAttrVal
// Desc: Copies an attribute value into m_pWrite buf, skipping surrounding
// quotes
//-------------------------------------------------------------------------------------
int32_t XMLParser::AdvanceAttrVal() {
int32_t hr;
char wQuoteChar;
if (FAILED(hr = AdvanceCharacter())) return hr;
if ((m_Ch != '"') && (m_Ch != '\'')) {
Error(E_INVALID_XML_SYNTAX,
"Attribute values must be enclosed in quotes");
return E_INVALID_XML_SYNTAX;
}
wQuoteChar = m_Ch;
for (;;) {
if (FAILED(hr = AdvanceCharacter()))
return hr;
else if (m_Ch == wQuoteChar)
break;
else if (m_Ch == '&') {
SkipNextAdvance();
if (FAILED(hr = ConvertEscape())) return hr;
} else if (m_Ch == '<') {
Error(E_INVALID_XML_SYNTAX, "Illegal character '<' in element tag");
return E_INVALID_XML_SYNTAX;
}
// copy character into the buffer
if (m_pWritePtr - m_pWriteBuf >= XML_WRITE_BUFFER_SIZE) {
Error(E_INVALID_XML_SYNTAX,
"Total element tag size may not be more than %d characters",
XML_WRITE_BUFFER_SIZE);
return E_INVALID_XML_SYNTAX;
}
*m_pWritePtr = m_Ch;
m_pWritePtr++;
}
return 0;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::AdvanceName
// Desc: Copies a name into the m_pWriteBuf - returns true on success, false on
// failure
// Ignores leading whitespace. Currently does not support unicode names
//-------------------------------------------------------------------------------------
int32_t XMLParser::AdvanceName() {
int32_t hr;
if (FAILED(hr = AdvanceCharacter())) return hr;
if (((m_Ch < 'A') || (m_Ch > 'Z')) && ((m_Ch < 'a') || (m_Ch > 'z')) &&
(m_Ch != '_') && (m_Ch != ':')) {
Error(E_INVALID_XML_SYNTAX,
"Names must start with an alphabetic character or _ or :");
return E_INVALID_XML_SYNTAX;
}
while (((m_Ch >= 'A') && (m_Ch <= 'Z')) ||
((m_Ch >= 'a') && (m_Ch <= 'z')) ||
((m_Ch >= '0') && (m_Ch <= '9')) || (m_Ch == '_') || (m_Ch == ':') ||
(m_Ch == '-') || (m_Ch == '.')) {
if (m_pWritePtr - m_pWriteBuf >= XML_WRITE_BUFFER_SIZE) {
Error(E_INVALID_XML_SYNTAX,
"Total element tag size may not be more than %d characters",
XML_WRITE_BUFFER_SIZE);
return E_INVALID_XML_SYNTAX;
}
*m_pWritePtr = m_Ch;
m_pWritePtr++;
if (FAILED(hr = AdvanceCharacter())) return hr;
}
SkipNextAdvance();
return 0;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::AdvanceCharacter
// Desc: Copies the character at *m_pReadPtr to m_Ch
// handling difference in UTF16 / UTF8, and big/little endian
// and getting another chunk of the file if needed
// Returns S_OK if there are more characters, E_ABORT for no characters to
// read
//-------------------------------------------------------------------------------------
int32_t XMLParser::AdvanceCharacter(bool bOkToFail) {
if (m_bSkipNextAdvance) {
m_bSkipNextAdvance = false;
return 0;
}
// If we hit EOF in the middle of a character,
// it's ok-- we'll just have a corrupt last character
// (the buffer is padded with double NULLs )
if ((m_pReadPtr[0] == '\0') && (m_pReadPtr[1] == '\0')) {
// Read more from the file
FillBuffer();
// We are at EOF if it is still nullptr
if ((m_pReadPtr[0] == '\0') && (m_pReadPtr[1] == '\0')) {
if (!bOkToFail) {
Error(E_INVALID_XML_SYNTAX,
"Unexpected EOF while parsing XML file");
return E_INVALID_XML_SYNTAX;
} else {
return E_FAIL;
}
}
}
if (m_bUnicode == false) {
m_Ch = *((char*)m_pReadPtr);
m_pReadPtr++;
} else // if( m_bUnicode == true )
{
m_Ch = *((char*)m_pReadPtr);
if (m_bReverseBytes) {
m_Ch = (m_Ch << 8) + (m_Ch >> 8);
}
m_pReadPtr += 2;
}
if (m_Ch == '\n') {
m_pISAXCallback->m_LineNum++;
m_pISAXCallback->m_LinePos = 0;
} else if (m_Ch != '\r')
m_pISAXCallback->m_LinePos++;
return 0;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::AdvanceElement
// Desc: Builds <element> data, calls callback
//-------------------------------------------------------------------------------------
int32_t XMLParser::AdvanceElement() {
int32_t hr;
// write ptr at the beginning of the buffer
m_pWritePtr = m_pWriteBuf;
if (FAILED(hr = AdvanceCharacter())) return hr;
// if first character wasn't '<', we wouldn't be here
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch == '!') {
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch == '-') {
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != '-') {
Error(E_INVALID_XML_SYNTAX, "Expecting '-' after '<!-'");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceComment())) return hr;
return 0;
}
if (m_Ch != '[') {
Error(E_INVALID_XML_SYNTAX, "Expecting '<![CDATA['");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != 'C') {
Error(E_INVALID_XML_SYNTAX, "Expecting '<![CDATA['");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != 'D') {
Error(E_INVALID_XML_SYNTAX, "Expecting '<![CDATA['");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != 'A') {
Error(E_INVALID_XML_SYNTAX, "Expecting '<![CDATA['");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != 'T') {
Error(E_INVALID_XML_SYNTAX, "Expecting '<![CDATA['");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != 'A') {
Error(E_INVALID_XML_SYNTAX, "Expecting '<![CDATA['");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != '[') {
Error(E_INVALID_XML_SYNTAX, "Expecting '<![CDATA['");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = AdvanceCDATA())) return hr;
} else if (m_Ch == '/') {
char* pEntityRefVal = m_pWritePtr;
if (FAILED(hr = AdvanceName())) return hr;
if (FAILED(m_pISAXCallback->ElementEnd(
pEntityRefVal, (uint32_t)(m_pWritePtr - pEntityRefVal))))
return E_ABORT;
if (FAILED(hr = ConsumeSpace())) return hr;
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != '>') {
Error(E_INVALID_XML_SYNTAX,
"Expecting '>' after name for closing entity reference");
return E_INVALID_XML_SYNTAX;
}
} else if (m_Ch == '?') {
// just skip any xml header tag since not really important after
// identifying character set
for (;;) {
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch == '>') return 0;
}
} else {
XMLAttribute Attributes[XML_MAX_ATTRIBUTES_PER_ELEMENT];
uint32_t NumAttrs;
char* pEntityRefVal = m_pWritePtr;
uint32_t EntityRefLen;
NumAttrs = 0;
SkipNextAdvance();
// Entity tag
if (FAILED(hr = AdvanceName())) return hr;
EntityRefLen = (uint32_t)(m_pWritePtr - pEntityRefVal);
if (FAILED(hr = ConsumeSpace())) return hr;
if (FAILED(hr = AdvanceCharacter())) return hr;
// read attributes
while ((m_Ch != '>') && (m_Ch != '/')) {
SkipNextAdvance();
if (NumAttrs >= XML_MAX_ATTRIBUTES_PER_ELEMENT) {
Error(E_INVALID_XML_SYNTAX,
"Elements may not have more than %d attributes",
XML_MAX_ATTRIBUTES_PER_ELEMENT);
return E_INVALID_XML_SYNTAX;
}
Attributes[NumAttrs].strName = m_pWritePtr;
// Attribute name
if (FAILED(hr = AdvanceName())) return hr;
Attributes[NumAttrs].NameLen =
(uint32_t)(m_pWritePtr - Attributes[NumAttrs].strName);
if (FAILED(hr = ConsumeSpace())) return hr;
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != '=') {
Error(E_INVALID_XML_SYNTAX,
"Expecting '=' character after attribute name");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(hr = ConsumeSpace())) return hr;
Attributes[NumAttrs].strValue = m_pWritePtr;
if (FAILED(hr = AdvanceAttrVal())) return hr;
Attributes[NumAttrs].ValueLen =
(uint32_t)(m_pWritePtr - Attributes[NumAttrs].strValue);
++NumAttrs;
if (FAILED(hr = ConsumeSpace())) return hr;
if (FAILED(hr = AdvanceCharacter())) return hr;
}
if (m_Ch == '/') {
if (FAILED(hr = AdvanceCharacter())) return hr;
if (m_Ch != '>') {
Error(E_INVALID_XML_SYNTAX,
"Expecting '>' after '/' in element tag");
return E_INVALID_XML_SYNTAX;
}
if (FAILED(m_pISAXCallback->ElementBegin(
pEntityRefVal, EntityRefLen, Attributes, NumAttrs)))
return E_ABORT;
if (FAILED(
m_pISAXCallback->ElementEnd(pEntityRefVal, EntityRefLen)))
return E_ABORT;
} else {
if (FAILED(m_pISAXCallback->ElementBegin(
pEntityRefVal, EntityRefLen, Attributes, NumAttrs)))
return E_ABORT;
}
}
return 0;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::AdvanceCDATA
// Desc: Read a CDATA section
//-------------------------------------------------------------------------------------
int32_t XMLParser::AdvanceCDATA() {
int32_t hr;
uint16_t wStage = 0;
if (FAILED(m_pISAXCallback->CDATABegin())) return E_ABORT;
for (;;) {
if (FAILED(hr = AdvanceCharacter())) return hr;
*m_pWritePtr = m_Ch;
m_pWritePtr++;
if ((m_Ch == ']') && (wStage == 0))
wStage = 1;
else if ((m_Ch == ']') && (wStage == 1))
wStage = 2;
else if ((m_Ch == '>') && (wStage == 2)) {
m_pWritePtr -= 3;
break;
} else
wStage = 0;
if (m_pWritePtr - m_pWriteBuf >= XML_WRITE_BUFFER_SIZE) {
if (FAILED(m_pISAXCallback->CDATAData(
m_pWriteBuf, (uint32_t)(m_pWritePtr - m_pWriteBuf), true)))
return E_ABORT;
m_pWritePtr = m_pWriteBuf;
}
}
if (FAILED(m_pISAXCallback->CDATAData(
m_pWriteBuf, (uint32_t)(m_pWritePtr - m_pWriteBuf), false)))
return E_ABORT;
m_pWritePtr = m_pWriteBuf;
if (FAILED(m_pISAXCallback->CDATAEnd())) return E_ABORT;
return 0;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::AdvanceComment
// Desk: Skips over a comment
//-------------------------------------------------------------------------------------
int32_t XMLParser::AdvanceComment() {
int32_t hr;
uint16_t wStage;
wStage = 0;
for (;;) {
if (FAILED(hr = AdvanceCharacter())) return hr;
if ((m_Ch == '-') && (wStage == 0))
wStage = 1;
else if ((m_Ch == '-') && (wStage == 1))
wStage = 2;
else if ((m_Ch == '>') && (wStage == 2))
break;
else
wStage = 0;
}
return 0;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::RegisterSAXCallbackInterface
// Desc: Registers callback interface
//-------------------------------------------------------------------------------------
void XMLParser::RegisterSAXCallbackInterface(ISAXCallback* pISAXCallback) {
m_pISAXCallback = pISAXCallback;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::GetSAXCallbackInterface
// Desc: Returns current callback interface
//-------------------------------------------------------------------------------------
ISAXCallback* XMLParser::GetSAXCallbackInterface() { return m_pISAXCallback; }
//-------------------------------------------------------------------------------------
// Name: XMLParser::MainParseLoop
// Desc: Main Loop to Parse Data - source agnostic
//-------------------------------------------------------------------------------------
int32_t XMLParser::MainParseLoop() {
bool bWhiteSpaceOnly = true;
int32_t hr = 0;
if (FAILED(m_pISAXCallback->StartDocument())) return E_ABORT;
m_pWritePtr = m_pWriteBuf;
FillBuffer();
if (*((char*)m_pReadBuf) == 0xFEFF) {
m_bUnicode = true;
m_bReverseBytes = false;
m_pReadPtr += 2;
} else if (*((char*)m_pReadBuf) == 0xFFFE) {
m_bUnicode = true;
m_bReverseBytes = true;
m_pReadPtr += 2;
} else if (*((char*)m_pReadBuf) == 0x003C) {
m_bUnicode = true;
m_bReverseBytes = false;
} else if (*((char*)m_pReadBuf) == 0x3C00) {
m_bUnicode = true;
m_bReverseBytes = true;
} else if (m_pReadBuf[0] == 0x3C) {
m_bUnicode = false;
m_bReverseBytes = false;
} else {
Error(E_INVALID_XML_SYNTAX,
"Unrecognized encoding (parser does not support UTF-8 language "
"encodings)");
return E_INVALID_XML_SYNTAX;
}
for (;;) {
if (FAILED(AdvanceCharacter(true))) {
if (((uint32_t)(m_pWritePtr - m_pWriteBuf) != 0) &&
(!bWhiteSpaceOnly)) {
if (FAILED(m_pISAXCallback->ElementContent(
m_pWriteBuf, (uint32_t)(m_pWritePtr - m_pWriteBuf),
false)))
return E_ABORT;
bWhiteSpaceOnly = true;
}
if (FAILED(m_pISAXCallback->EndDocument())) return E_ABORT;
return 0;
}
if (m_Ch == '<') {
if (((uint32_t)(m_pWritePtr - m_pWriteBuf) != 0) &&
(!bWhiteSpaceOnly)) {
if (FAILED(m_pISAXCallback->ElementContent(
m_pWriteBuf, (uint32_t)(m_pWritePtr - m_pWriteBuf),
false)))
return E_ABORT;
bWhiteSpaceOnly = true;
}
SkipNextAdvance();
m_pWritePtr = m_pWriteBuf;
if (FAILED(hr = AdvanceElement())) return hr;
m_pWritePtr = m_pWriteBuf;
} else {
if (m_Ch == '&') {
SkipNextAdvance();
if (FAILED(hr = ConvertEscape())) return hr;
}
if (bWhiteSpaceOnly && (m_Ch != ' ') && (m_Ch != '\n') &&
(m_Ch != '\r') && (m_Ch != '\t')) {
bWhiteSpaceOnly = false;
}
*m_pWritePtr = m_Ch;
m_pWritePtr++;
if (m_pWritePtr - m_pWriteBuf >= XML_WRITE_BUFFER_SIZE) {
if (!bWhiteSpaceOnly) {
if (FAILED(m_pISAXCallback->ElementContent(
m_pWriteBuf, (uint32_t)(m_pWritePtr - m_pWriteBuf),
true))) {
return E_ABORT;
}
}
m_pWritePtr = m_pWriteBuf;
bWhiteSpaceOnly = true;
}
}
}
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::ParseXMLFile
// Desc: Builds element data
//-------------------------------------------------------------------------------------
int32_t XMLParser::ParseXMLFile(const char* strFilename) {
int32_t hr;
if (m_pISAXCallback == nullptr) return E_NOINTERFACE;
m_pISAXCallback->m_LineNum = 1;
m_pISAXCallback->m_LinePos = 0;
m_pISAXCallback->m_strFilename =
strFilename; // save this off only while we parse the file
m_bSkipNextAdvance = false;
m_pReadPtr = m_pReadBuf;
m_pReadBuf[0] = '\0';
m_pReadBuf[1] = '\0';
m_pInXMLBuffer = nullptr;
m_uInXMLBufferCharsLeft = 0;
m_hFile = CreateFile(strFilename, GENERIC_READ, FILE_SHARE_READ, nullptr,
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
if (m_hFile == INVALID_HANDLE_VALUE) {
Error(E_COULD_NOT_OPEN_FILE, "Error opening file");
hr = E_COULD_NOT_OPEN_FILE;
} else {
LARGE_INTEGER iFileSize;
GetFileSizeEx(m_hFile, &iFileSize);
m_dwCharsTotal = (uint32_t)iFileSize.QuadPart;
m_dwCharsConsumed = 0;
hr = MainParseLoop();
}
// Close the file
if (m_hFile != INVALID_HANDLE_VALUE) CloseHandle(m_hFile);
m_hFile = INVALID_HANDLE_VALUE;
// we no longer own strFilename, so un-set it
m_pISAXCallback->m_strFilename = nullptr;
return hr;
}
//-------------------------------------------------------------------------------------
// Name: XMLParser::ParseXMLFile
// Desc: Builds element data
//-------------------------------------------------------------------------------------
int32_t XMLParser::ParseXMLBuffer(const char* strBuffer, uint32_t uBufferSize) {
int32_t hr;
if (m_pISAXCallback == nullptr) return E_NOINTERFACE;
m_pISAXCallback->m_LineNum = 1;
m_pISAXCallback->m_LinePos = 0;
m_pISAXCallback->m_strFilename =
""; // save this off only while we parse the file
m_bSkipNextAdvance = false;
m_pReadPtr = m_pReadBuf;
m_pReadBuf[0] = '\0';
m_pReadBuf[1] = '\0';
m_hFile = nullptr;
m_pInXMLBuffer = strBuffer;
m_uInXMLBufferCharsLeft = uBufferSize;
m_dwCharsTotal = uBufferSize;
m_dwCharsConsumed = 0;
hr = MainParseLoop();
// we no longer own strFilename, so un-set it
m_pISAXCallback->m_strFilename = nullptr;
return hr;
}
//-------------------------------------------------------------------------------------
// XMLParser::Error()
// Logs an error through the callback interface
//-------------------------------------------------------------------------------------
#ifdef _Printf_format_string_ // VC++ 2008 and later support this annotation
void XMLParser::Error(int32_t hErr,
_In_z_ _Printf_format_string_ const char* strFormat, ...)
#else
void XMLParser::Error(int32_t hErr, const char* strFormat, ...)
#endif
{
const int32_t MAX_OUTPUT_STR = 160;
char strBuffer[MAX_OUTPUT_STR];
va_list pArglist;
va_start(pArglist, strFormat);
vsprintf(strBuffer, strFormat, pArglist);
m_pISAXCallback->Error(hErr, strBuffer);
va_end(pArglist);
}
} // namespace ATG

View file

@ -1,159 +0,0 @@
// 4J-PB -
// The ATG Framework is a common set of C++ class libraries that is used by the
// samples in the XDK, and was developed by the Advanced Technology Group (ATG).
// The ATG Framework offers a clean and consistent format for the samples. These
// classes define functions used by all the samples. The ATG Framework together
// with the samples demonstrates best practices and innovative techniques for
// Xbox 360. There are many useful sections of code in the samples. You are
// encouraged to incorporate this code into your titles.
//-------------------------------------------------------------------------------------
// AtgXmlParser.h
//
// XMLParser and SAX interface declaration
//
// Xbox Advanced Technology Group
// Copyright (C) Microsoft Corporation. All rights reserved.
//-------------------------------------------------------------------------------------
#pragma once
#ifndef ATGXMLPARSER_H
#define ATGXMLPARSER_H
namespace ATG {
//-----------------------------------------------------------------------------
// error returns from XMLParse
//-----------------------------------------------------------------------------
#define _ATGFAC 0x61B
#define E_COULD_NOT_OPEN_FILE MAKE_HRESULT(1, _ATGFAC, 0x0001)
#define E_INVALID_XML_SYNTAX MAKE_HRESULT(1, _ATGFAC, 0x0002)
const uint32_t XML_MAX_ATTRIBUTES_PER_ELEMENT = 32;
const uint32_t XML_MAX_NAME_LENGTH = 128;
const uint32_t XML_READ_BUFFER_SIZE = 2048;
const uint32_t XML_WRITE_BUFFER_SIZE = 2048;
// No tag can be longer than XML_WRITE_BUFFER_SIZE - an error will be returned
// if it is
//-------------------------------------------------------------------------------------
struct XMLAttribute {
char* strName;
uint32_t NameLen;
char* strValue;
uint32_t ValueLen;
};
//-------------------------------------------------------------------------------------
class ISAXCallback {
friend class XMLParser;
public:
ISAXCallback(){};
virtual ~ISAXCallback(){};
virtual int32_t StartDocument() = 0;
virtual int32_t EndDocument() = 0;
virtual int32_t ElementBegin(const char* strName, uint32_t NameLen,
const XMLAttribute* pAttributes,
uint32_t NumAttributes) = 0;
virtual int32_t ElementContent(const char* strData, uint32_t DataLen,
bool More) = 0;
virtual int32_t ElementEnd(const char* strName, uint32_t NameLen) = 0;
virtual int32_t CDATABegin() = 0;
virtual int32_t CDATAData(const char* strCDATA, uint32_t CDATALen,
bool bMore) = 0;
virtual int32_t CDATAEnd() = 0;
virtual void Error(int32_t hError, const char* strMessage) = 0;
virtual void SetParseProgress(uint32_t dwProgress) {}
const char* GetFilename() { return m_strFilename; }
uint32_t GetLineNumber() { return m_LineNum; }
uint32_t GetLinePosition() { return m_LinePos; }
private:
const char* m_strFilename;
uint32_t m_LineNum;
uint32_t m_LinePos;
};
//-------------------------------------------------------------------------------------
class XMLParser {
public:
XMLParser();
~XMLParser();
// Register an interface inheiriting from ISAXCallback
void RegisterSAXCallbackInterface(ISAXCallback* pISAXCallback);
// Get the registered interface
ISAXCallback* GetSAXCallbackInterface();
// ParseXMLFile returns one of the following:
// E_COULD_NOT_OPEN_FILE - couldn't open the file
// E_INVALID_XML_SYNTAX - bad XML syntax according to this parser
// E_NOINTERFACE - RegisterSAXCallbackInterface not called
// E_ABORT - callback returned a fail code
// S_OK - file parsed and completed
int32_t ParseXMLFile(const char* strFilename);
// Parses from a buffer- if you pass a char buffer (and cast it), it
// will
// correctly detect it and use unicode instead. Return codes are
// the same as for ParseXMLFile
int32_t ParseXMLBuffer(const char* strBuffer, uint32_t uBufferSize);
private:
int32_t MainParseLoop();
int32_t AdvanceCharacter(bool bOkToFail = false);
void SkipNextAdvance();
int32_t ConsumeSpace();
int32_t ConvertEscape();
int32_t AdvanceElement();
int32_t AdvanceName();
int32_t AdvanceAttrVal();
int32_t AdvanceCDATA();
int32_t AdvanceComment();
void FillBuffer();
#ifdef _Printf_format_string_ // VC++ 2008 and later support this annotation
void Error(int32_t hRet,
_In_z_ _Printf_format_string_ const char* strFormat, ...);
#else
void Error(int32_t hRet, const char* strFormat, ...);
#endif
ISAXCallback* m_pISAXCallback;
void* m_hFile;
const char* m_pInXMLBuffer;
uint32_t m_uInXMLBufferCharsLeft;
uint32_t m_dwCharsTotal;
uint32_t m_dwCharsConsumed;
uint8_t m_pReadBuf[XML_READ_BUFFER_SIZE + 2]; // room for a trailing NULL
char m_pWriteBuf[XML_WRITE_BUFFER_SIZE];
uint8_t* m_pReadPtr;
char* m_pWritePtr; // write pointer within m_pBuf
bool m_bUnicode; // true = 16-bits, false = 8-bits
bool m_bReverseBytes; // true = reverse bytes, false = don't reverse
bool m_bSkipNextAdvance;
char m_Ch; // Current character being parsed
};
} // namespace ATG
#endif

View file

@ -1,303 +0,0 @@
#pragma once
#if !defined(XMLMOJANGCALLBACK_H)
#define XMLMOJANGCALLBACK_H
// xml reading
using namespace ATG;
class xmlMojangCallback : public ATG::ISAXCallback {
public:
virtual int32_t StartDocument() { return 0; };
virtual int32_t EndDocument() { return 0; };
virtual int32_t ElementBegin(const char* strName, uint32_t NameLen,
const XMLAttribute* pAttributes,
uint32_t NumAttributes) {
char wTemp[35] = "";
char wAttName[32] = "";
char wNameXUID[32] = "";
char wNameSkin[32] = "";
char wNameCloak[32] = "";
PlayerUID xuid = 0LL;
if (NameLen > 31)
return 1;
else
strncpy(wAttName, strName, NameLen);
if (_wcsicmp(wAttName, "root") == 0) {
return 0;
} else if (_wcsicmp(wAttName, "data") == 0) {
for (uint32_t i = 0; i < NumAttributes; i++) {
wcsncpy_s(wAttName, pAttributes[i].strName,
pAttributes[i].NameLen);
if (_wcsicmp(wAttName, "name") == 0) {
if (pAttributes[i].ValueLen <= 32)
wcsncpy_s(wNameXUID, pAttributes[i].strValue,
pAttributes[i].ValueLen);
} else if (_wcsicmp(wAttName, "xuid") == 0) {
if (pAttributes[i].ValueLen <= 32) {
memset(wTemp, 0, sizeof(char) * 35);
wcsncpy_s(wTemp, pAttributes[i].strValue,
pAttributes[i].ValueLen);
xuid = _wcstoui64(wTemp, nullptr, 10);
}
} else if (_wcsicmp(wAttName, "cape") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wNameCloak, pAttributes[i].strValue,
pAttributes[i].ValueLen);
}
} else if (_wcsicmp(wAttName, "skin") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wNameSkin, pAttributes[i].strValue,
pAttributes[i].ValueLen);
}
}
}
// if the xuid hasn't been defined, then we can't use the data
if (xuid != 0LL) {
return Game::RegisterMojangData(wNameXUID, xuid, wNameSkin,
wNameCloak);
} else
return 1;
} else {
return 1;
}
};
virtual int32_t ElementContent(const char* strData, uint32_t DataLen,
bool More) {
return 0;
};
virtual int32_t ElementEnd(const char* strName, uint32_t NameLen) {
return 0;
};
virtual int32_t CDATABegin() { return 0; };
virtual int32_t CDATAData(const char* strCDATA, uint32_t CDATALen,
bool bMore) {
return 0;
};
virtual int32_t CDATAEnd() { return 0; };
virtual void Error(int32_t hError, const char* strMessage) {
app.DebugPrintf("Error when Parsing xuids.XML\n");
};
};
class xmlConfigCallback : public ATG::ISAXCallback {
public:
virtual int32_t StartDocument() { return 0; };
virtual int32_t EndDocument() { return 0; };
virtual int32_t ElementBegin(const char* strName, uint32_t NameLen,
const XMLAttribute* pAttributes,
uint32_t NumAttributes) {
char wTemp[35] = "";
char wType[32] = "";
char wAttName[32] = "";
char wValue[32] = "";
int iValue = -1;
if (NameLen > 31)
return 1;
else
wcsncpy_s(wAttName, strName, NameLen);
if (_wcsicmp(wAttName, "root") == 0) {
return 0;
} else if (_wcsicmp(wAttName, "data") == 0) {
for (uint32_t i = 0; i < NumAttributes; i++) {
wcsncpy_s(wAttName, pAttributes[i].strName,
pAttributes[i].NameLen);
if (_wcsicmp(wAttName, "Type") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wType, pAttributes[i].strValue,
pAttributes[i].ValueLen);
}
} else if (_wcsicmp(wAttName, "Value") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wValue, pAttributes[i].strValue,
pAttributes[i].ValueLen);
iValue = strtol(wValue, nullptr, 10);
}
}
}
// if the xuid hasn't been defined, then we can't use the data
if (iValue != -1) {
#if defined(_DEBUG)
printf("Type - %s, Value - %d, ", wType, iValue);
#endif
return Game::RegisterConfigValues(wType, iValue);
} else {
return 1;
}
} else {
return 1;
}
}
virtual int32_t ElementContent(const char* strData, uint32_t DataLen,
bool More) {
return 0;
};
virtual int32_t ElementEnd(const char* strName, uint32_t NameLen) {
return 0;
};
virtual int32_t CDATABegin() { return 0; };
virtual int32_t CDATAData(const char* strCDATA, uint32_t CDATALen,
bool bMore) {
return 0;
};
virtual int32_t CDATAEnd() { return 0; };
virtual void Error(int32_t hError, const char* strMessage) {
app.DebugPrintf("Error when Parsing xuids.XML\n");
};
};
class xmlDLCInfoCallback : public ATG::ISAXCallback {
public:
virtual int32_t StartDocument() { return 0; };
virtual int32_t EndDocument() { return 0; };
virtual int32_t ElementBegin(const char* strName, uint32_t NameLen,
const XMLAttribute* pAttributes,
uint32_t NumAttributes) {
char wTemp[35] = "";
char wAttName[32] = "";
char wNameBanner[32] = "";
char wDataFile[32] = "";
char wType[32] = "";
char wFirstSkin[32] = "";
char wConfig[32] = "";
uint64_t ullFull = 0ll;
uint64_t ullTrial = 0ll;
unsigned int uiSortIndex = 0L;
int iGender = 0;
int iConfig = 0;
if (NameLen > 31)
return 1;
else
wcsncpy_s(wAttName, strName, NameLen);
if (_wcsicmp(wAttName, "root") == 0) {
return 0;
} else if (_wcsicmp(wAttName, "data") == 0) {
for (uint32_t i = 0; i < NumAttributes; i++) {
wcsncpy_s(wAttName, pAttributes[i].strName,
pAttributes[i].NameLen);
if (_wcsicmp(wAttName, "SortIndex") == 0) {
if (pAttributes[i].ValueLen <= 32) {
memset(wTemp, 0, sizeof(char) * 35);
wcsncpy_s(wTemp, pAttributes[i].strValue,
pAttributes[i].ValueLen);
uiSortIndex = wcstoul(wTemp, nullptr, 16);
}
} else if (_wcsicmp(wAttName, "Banner") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wNameBanner, pAttributes[i].strValue,
pAttributes[i].ValueLen);
}
} else if (_wcsicmp(wAttName, "Full") == 0) {
if (pAttributes[i].ValueLen <= 32) {
memset(wTemp, 0, sizeof(char) * 35);
wcsncpy_s(wTemp, pAttributes[i].strValue,
pAttributes[i].ValueLen);
ullFull = _wcstoui64(wTemp, nullptr, 16);
}
} else if (_wcsicmp(wAttName, "Trial") == 0) {
if (pAttributes[i].ValueLen <= 32) {
memset(wTemp, 0, sizeof(char) * 35);
wcsncpy_s(wTemp, pAttributes[i].strValue,
pAttributes[i].ValueLen);
ullTrial = _wcstoui64(wTemp, nullptr, 16);
}
} else if (_wcsicmp(wAttName, "FirstSkin") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wFirstSkin, pAttributes[i].strValue,
pAttributes[i].ValueLen);
}
} else if (_wcsicmp(wAttName, "Type") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wType, pAttributes[i].strValue,
pAttributes[i].ValueLen);
}
} else if (_wcsicmp(wAttName, "Gender") == 0) {
if (_wcsicmp(wAttName, "Male") == 0) {
iGender = 1;
} else if (_wcsicmp(wAttName, "Female") == 0) {
iGender = 2;
} else {
iGender = 0;
}
} else if (_wcsicmp(wAttName, "Config") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wConfig, pAttributes[i].strValue,
pAttributes[i].ValueLen);
iConfig = strtol(wConfig, nullptr, 10);
}
} else if (_wcsicmp(wAttName, "DataFile") == 0) {
if (pAttributes[i].ValueLen <= 32) {
wcsncpy_s(wDataFile, pAttributes[i].strValue,
pAttributes[i].ValueLen);
}
}
}
// if the xuid hasn't been defined, then we can't use the data
if (ullFull != 0LL) {
#if defined(_DEBUG)
printf("Type - %s, Name - %s, ", wType, wNameBanner);
#endif
app.DebugPrintf("Full = %lld, Trial %lld\n", ullFull, ullTrial);
return Game::RegisterDLCData(wType, wNameBanner, iGender,
ullFull, ullTrial, wFirstSkin,
uiSortIndex, iConfig, wDataFile);
} else {
return 1;
}
} else {
return 1;
}
};
virtual int32_t ElementContent(const char* strData, uint32_t DataLen,
bool More) {
return 0;
};
virtual int32_t ElementEnd(const char* strName, uint32_t NameLen) {
return 0;
};
virtual int32_t CDATABegin() { return 0; };
virtual int32_t CDATAData(const char* strCDATA, uint32_t CDATALen,
bool bMore) {
return 0;
};
virtual int32_t CDATAEnd() { return 0; };
virtual void Error(int32_t hError, const char* strMessage) {
app.DebugPrintf("Error when Parsing DLC.XML\n");
};
};
#endif

View file

@ -1,849 +0,0 @@
// Minecraft.cpp : Defines the entry point for the application.
//
#include <assert.h>
#include <mutex>
#include "minecraft/network/Socket.h"
#include "minecraft/client/User.h"
#include "minecraft/client/multiplayer/ClientConnection.h"
#include "minecraft/client/multiplayer/ConnectScreen.h"
#include "minecraft/client/player/LocalPlayer.h"
#include "minecraft/locale/Language.h"
#include "minecraft/server/MinecraftServer.h"
#include "minecraft/stats/StatsCounter.h"
#include "minecraft/world/item/ItemInstance.h"
#include "minecraft/world/item/MapItem.h"
#include "minecraft/world/item/crafting/Recipes.h"
#include "minecraft/world/item/crafting/Recipy.h"
#include "minecraft/world/level/Level.h"
#include "minecraft/world/phys/AABB.h"
#include "minecraft/world/phys/Vec3.h"
#include "util/StringHelpers.h"
// #include "Social/SocialManager.h"
// #include "app/common/Leaderboards/LeaderboardManager.h"
// #include "../Common/XUI/XUI_Scene_Container.h"
// #include "NetworkManager.h"
#include "../Resource.h"
#include "Sentient/SentientManager.h"
#include "minecraft/client/Options.h"
#include "minecraft/client/renderer/Tesselator.h"
#include "minecraft/client/renderer/Textures.h"
#include "minecraft/world/level/chunk/storage/OldChunkStorage.h"
#include "minecraft/world/level/storage/ConsoleSaveFileIO/compression.h"
HINSTANCE hMyInst;
LRESULT CALLBACK DlgProc(HWND hWndDlg, uint32_t Msg, WPARAM wParam,
LPARAM lParam);
char chGlobalText[256];
uint16_t ui16GlobalText[256];
#define THEME_NAME "584111F70AAAAAAA"
#define THEME_FILESIZE 2797568
// #define THREE_MB 3145728 // minimum save size (checking for this on a
// selected device) #define FIVE_MB 5242880 // minimum save size (checking for
// this on a selected device) #define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR
// space required for a save (checking for this on a selected device)
#define FIFTY_ONE_MB \
(1000000 * 51) // Maximum TCR space required for a save is 52MB (checking
// for this on a selected device)
// #define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU
#define NUM_PROFILE_VALUES 5
#define NUM_PROFILE_SETTINGS 4
uint32_t dwProfileSettingsA[NUM_PROFILE_VALUES] = {0, 0, 0, 0, 0};
//-------------------------------------------------------------------------------------
// Time Since fAppTime is a float, we need to keep the quadword app
// time
// as a LARGE_INTEGER so that we don't lose precision after
// running for a long time.
//-------------------------------------------------------------------------------------
bool g_bWidescreen = true;
int g_iScreenWidth = 1920;
int g_iScreenHeight = 1080;
void DefineActions(void) {
// The app needs to define the actions required, and the possible mappings
// for these
// Split into Menu actions, and in-game actions
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_A,
_360_JOY_BUTTON_A);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_B,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_X,
_360_JOY_BUTTON_X);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_Y,
_360_JOY_BUTTON_Y);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OK,
_360_JOY_BUTTON_A);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_CANCEL,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_0, ACTION_MENU_UP,
_360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_0, ACTION_MENU_DOWN,
_360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_0, ACTION_MENU_LEFT,
_360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_0, ACTION_MENU_RIGHT,
_360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_PAGEUP,
_360_JOY_BUTTON_LT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_PAGEDOWN,
_360_JOY_BUTTON_RT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_RIGHT_SCROLL,
_360_JOY_BUTTON_RB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_LEFT_SCROLL,
_360_JOY_BUTTON_LB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_PAUSEMENU,
_360_JOY_BUTTON_START);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_STICK_PRESS,
_360_JOY_BUTTON_LTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_PRESS,
_360_JOY_BUTTON_RTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_UP,
_360_JOY_BUTTON_RSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_DOWN,
_360_JOY_BUTTON_RSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_LEFT,
_360_JOY_BUTTON_RSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_RIGHT,
_360_JOY_BUTTON_RSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_JUMP,
_360_JOY_BUTTON_A);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_FORWARD,
_360_JOY_BUTTON_LSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_BACKWARD,
_360_JOY_BUTTON_LSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LEFT,
_360_JOY_BUTTON_LSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_RIGHT,
_360_JOY_BUTTON_LSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LOOK_LEFT,
_360_JOY_BUTTON_RSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LOOK_RIGHT,
_360_JOY_BUTTON_RSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LOOK_UP,
_360_JOY_BUTTON_RSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LOOK_DOWN,
_360_JOY_BUTTON_RSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_USE,
_360_JOY_BUTTON_LT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_ACTION,
_360_JOY_BUTTON_RT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_RIGHT_SCROLL,
_360_JOY_BUTTON_RB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LEFT_SCROLL,
_360_JOY_BUTTON_LB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_INVENTORY,
_360_JOY_BUTTON_Y);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_PAUSEMENU,
_360_JOY_BUTTON_START);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DROP,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_SNEAK_TOGGLE,
_360_JOY_BUTTON_RTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_CRAFTING,
_360_JOY_BUTTON_X);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0,
MINECRAFT_ACTION_RENDER_THIRD_PERSON,
_360_JOY_BUTTON_LTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_GAME_INFO,
_360_JOY_BUTTON_BACK);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DPAD_LEFT,
_360_JOY_BUTTON_DPAD_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DPAD_RIGHT,
_360_JOY_BUTTON_DPAD_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DPAD_UP,
_360_JOY_BUTTON_DPAD_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DPAD_DOWN,
_360_JOY_BUTTON_DPAD_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_A,
_360_JOY_BUTTON_A);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_B,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_X,
_360_JOY_BUTTON_X);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_Y,
_360_JOY_BUTTON_Y);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OK,
_360_JOY_BUTTON_A);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_CANCEL,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_1, ACTION_MENU_UP,
_360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_1, ACTION_MENU_DOWN,
_360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_1, ACTION_MENU_LEFT,
_360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_1, ACTION_MENU_RIGHT,
_360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_PAGEUP,
_360_JOY_BUTTON_LB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_PAGEDOWN,
_360_JOY_BUTTON_RT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_RIGHT_SCROLL,
_360_JOY_BUTTON_RB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_LEFT_SCROLL,
_360_JOY_BUTTON_LB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_PAUSEMENU,
_360_JOY_BUTTON_START);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_STICK_PRESS,
_360_JOY_BUTTON_LTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_PRESS,
_360_JOY_BUTTON_RTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_UP,
_360_JOY_BUTTON_RSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_DOWN,
_360_JOY_BUTTON_RSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_LEFT,
_360_JOY_BUTTON_RSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_RIGHT,
_360_JOY_BUTTON_RSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_JUMP,
_360_JOY_BUTTON_RB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_FORWARD,
_360_JOY_BUTTON_LSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_BACKWARD,
_360_JOY_BUTTON_LSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LEFT,
_360_JOY_BUTTON_LSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_RIGHT,
_360_JOY_BUTTON_LSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LOOK_LEFT,
_360_JOY_BUTTON_RSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LOOK_RIGHT,
_360_JOY_BUTTON_RSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LOOK_UP,
_360_JOY_BUTTON_RSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LOOK_DOWN,
_360_JOY_BUTTON_RSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_USE,
_360_JOY_BUTTON_RT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_ACTION,
_360_JOY_BUTTON_LT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_RIGHT_SCROLL,
_360_JOY_BUTTON_DPAD_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LEFT_SCROLL,
_360_JOY_BUTTON_DPAD_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_INVENTORY,
_360_JOY_BUTTON_Y);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_PAUSEMENU,
_360_JOY_BUTTON_START);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DROP,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_SNEAK_TOGGLE,
_360_JOY_BUTTON_LTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_CRAFTING,
_360_JOY_BUTTON_X);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1,
MINECRAFT_ACTION_RENDER_THIRD_PERSON,
_360_JOY_BUTTON_RTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_GAME_INFO,
_360_JOY_BUTTON_BACK);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DPAD_LEFT,
_360_JOY_BUTTON_DPAD_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DPAD_RIGHT,
_360_JOY_BUTTON_DPAD_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DPAD_UP,
_360_JOY_BUTTON_DPAD_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DPAD_DOWN,
_360_JOY_BUTTON_DPAD_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_A,
_360_JOY_BUTTON_A);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_B,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_X,
_360_JOY_BUTTON_X);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_Y,
_360_JOY_BUTTON_Y);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OK,
_360_JOY_BUTTON_A);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_CANCEL,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_2, ACTION_MENU_UP,
_360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_2, ACTION_MENU_DOWN,
_360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_2, ACTION_MENU_LEFT,
_360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_2, ACTION_MENU_RIGHT,
_360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(
MAP_STYLE_2, ACTION_MENU_PAGEUP,
_360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_PAGEDOWN,
_360_JOY_BUTTON_RT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_RIGHT_SCROLL,
_360_JOY_BUTTON_RB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_LEFT_SCROLL,
_360_JOY_BUTTON_LB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_JUMP,
_360_JOY_BUTTON_LT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_FORWARD,
_360_JOY_BUTTON_LSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_BACKWARD,
_360_JOY_BUTTON_LSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LEFT,
_360_JOY_BUTTON_LSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_RIGHT,
_360_JOY_BUTTON_LSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LOOK_LEFT,
_360_JOY_BUTTON_RSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LOOK_RIGHT,
_360_JOY_BUTTON_RSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LOOK_UP,
_360_JOY_BUTTON_RSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LOOK_DOWN,
_360_JOY_BUTTON_RSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_USE,
_360_JOY_BUTTON_RT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_ACTION,
_360_JOY_BUTTON_A);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_RIGHT_SCROLL,
_360_JOY_BUTTON_DPAD_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LEFT_SCROLL,
_360_JOY_BUTTON_DPAD_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_INVENTORY,
_360_JOY_BUTTON_Y);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_PAUSEMENU,
_360_JOY_BUTTON_START);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DROP,
_360_JOY_BUTTON_B);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_SNEAK_TOGGLE,
_360_JOY_BUTTON_LB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_CRAFTING,
_360_JOY_BUTTON_X);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2,
MINECRAFT_ACTION_RENDER_THIRD_PERSON,
_360_JOY_BUTTON_LTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_GAME_INFO,
_360_JOY_BUTTON_BACK);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_PAUSEMENU,
_360_JOY_BUTTON_START);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_STICK_PRESS,
_360_JOY_BUTTON_LTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_PRESS,
_360_JOY_BUTTON_RTHUMB);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_UP,
_360_JOY_BUTTON_RSTICK_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_DOWN,
_360_JOY_BUTTON_RSTICK_DOWN);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_LEFT,
_360_JOY_BUTTON_RSTICK_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_RIGHT,
_360_JOY_BUTTON_RSTICK_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DPAD_LEFT,
_360_JOY_BUTTON_DPAD_LEFT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DPAD_RIGHT,
_360_JOY_BUTTON_DPAD_RIGHT);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DPAD_UP,
_360_JOY_BUTTON_DPAD_UP);
PlatformInput.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DPAD_DOWN,
_360_JOY_BUTTON_DPAD_DOWN);
}
HINSTANCE g_hInst = nullptr;
HWND g_hWnd = nullptr;
D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
ID3D11Device* g_pd3dDevice = nullptr;
ID3D11DeviceContext* g_pImmediateContext = nullptr;
IDXGISwapChain* g_pSwapChain = nullptr;
ID3D11RenderTargetView* g_pRenderTargetView = nullptr;
ID3D11DepthStencilView* g_pDepthStencilView = nullptr;
ID3D11Texture2D* g_pDepthStencilBuffer = nullptr;
//
// FUNCTION: WndProc(HWND, uint32_t, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, uint32_t message, WPARAM wParam,
LPARAM lParam) {
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message) {
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId) {
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance) {
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, "Minecraft");
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = "Minecraft";
wcex.lpszClassName = "MinecraftClass";
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
bool InitInstance(HINSTANCE hInstance, int nCmdShow) {
g_hInst = hInstance; // Store instance handle in our global variable
RECT wr = {0, 0, g_iScreenWidth,
g_iScreenHeight}; // set the size, but not the position
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, false); // adjust the size
g_hWnd = CreateWindow("MinecraftClass", "Minecraft", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0,
wr.right - wr.left, // width of the window
wr.bottom - wr.top, // height of the window
nullptr, nullptr, hInstance, nullptr);
if (!g_hWnd) {
return false;
}
ShowWindow(g_hWnd, nCmdShow);
UpdateWindow(g_hWnd);
return true;
}
// 4J Stu - These functions are referenced from the Windows Input library
void ClearGlobalText() {
// clear the global text
memset(chGlobalText, 0, 256);
memset(ui16GlobalText, 0, 512);
}
uint16_t* GetGlobalText() {
// copy the ch text to ui16
char* pchBuffer = (char*)ui16GlobalText;
for (int i = 0; i < 256; i++) {
pchBuffer[i * 2] = chGlobalText[i];
}
return ui16GlobalText;
}
void SeedEditBox() {
DialogBox(hMyInst, MAKEINTRESOURCE(IDD_SEED), g_hWnd,
reinterpret_cast<DLGPROC>(DlgProc));
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, uint32_t Msg, WPARAM wParam,
LPARAM lParam) {
switch (Msg) {
case WM_INITDIALOG:
return true;
case WM_COMMAND:
switch (wParam) {
case IDOK:
// Set the text
GetDlgItemText(hWndDlg, IDC_EDIT, chGlobalText, 256);
EndDialog(hWndDlg, 0);
return true;
}
break;
}
return false;
}
//--------------------------------------------------------------------------------------
// Create Direct3D device and swap chain
//--------------------------------------------------------------------------------------
int32_t InitDevice() {
int32_t hr = 0;
RECT rc;
GetClientRect(g_hWnd, &rc);
uint32_t width = rc.right - rc.left;
uint32_t height = rc.bottom - rc.top;
// app.DebugPrintf("width: %d, height: %d\n", width, height);
width = g_iScreenWidth;
height = g_iScreenHeight;
app.DebugPrintf("width: %d, height: %d\n", width, height);
uint32_t createDeviceFlags = 0;
#if defined(_DEBUG)
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] = {
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
uint32_t numDriverTypes = ARRAYSIZE(driverTypes);
D3D_FEATURE_LEVEL featureLevels[] = {
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
uint32_t numFeatureLevels = ARRAYSIZE(featureLevels);
DXGI_SWAP_CHAIN_DESC sd;
memset(&sd, 0, sizeof(sd));
sd.BufferCount = 1;
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = g_hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = true;
for (uint32_t driverTypeIndex = 0; driverTypeIndex < numDriverTypes;
driverTypeIndex++) {
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDeviceAndSwapChain(
nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels,
numFeatureLevels, D3D11_SDK_VERSION, &sd, &g_pSwapChain,
&g_pd3dDevice, &g_featureLevel, &g_pImmediateContext);
if (HRESULT_SUCCEEDED(hr)) break;
}
if (FAILED(hr)) return hr;
// Create a render target view
ID3D11Texture2D* pBackBuffer = nullptr;
hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D),
(void**)&pBackBuffer);
if (FAILED(hr)) return hr;
// Create a depth stencil buffer
D3D11_TEXTURE2D_DESC descDepth;
descDepth.Width = width;
descDepth.Height = height;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDepth.SampleDesc.Count = 1;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
hr = g_pd3dDevice->CreateTexture2D(&descDepth, nullptr,
&g_pDepthStencilBuffer);
D3D11_DEPTH_STENCIL_VIEW_DESC descDSView;
descDSView.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
descDSView.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
descDSView.Texture2D.MipSlice = 0;
hr = g_pd3dDevice->CreateDepthStencilView(
g_pDepthStencilBuffer, &descDSView, &g_pDepthStencilView);
hr = g_pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr,
&g_pRenderTargetView);
pBackBuffer->Release();
if (FAILED(hr)) return hr;
g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView,
g_pDepthStencilView);
// Setup the viewport
D3D11_VIEWPORT vp;
vp.Width = (float)width;
vp.Height = (float)height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
g_pImmediateContext->RSSetViewports(1, &vp);
PlatformRenderer.Initialise(g_pd3dDevice, g_pSwapChain);
return 0;
}
//--------------------------------------------------------------------------------------
// Render the frame
//--------------------------------------------------------------------------------------
void Render() {
// Just clear the backbuffer
float ClearColor[4] = {0.0f, 0.125f, 0.3f, 1.0f}; // red,green,blue,alpha
g_pImmediateContext->ClearRenderTargetView(g_pRenderTargetView, ClearColor);
g_pSwapChain->Present(0, 0);
}
//--------------------------------------------------------------------------------------
// Clean up the objects we've created
//--------------------------------------------------------------------------------------
void CleanupDevice() {
if (g_pImmediateContext) g_pImmediateContext->ClearState();
if (g_pRenderTargetView) g_pRenderTargetView->Release();
if (g_pSwapChain) g_pSwapChain->Release();
if (g_pImmediateContext) g_pImmediateContext->Release();
if (g_pd3dDevice) g_pd3dDevice->Release();
}
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine,
_In_ int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
if (lpCmdLine) {
if (lpCmdLine[0] == '1') {
g_iScreenWidth = 1280;
g_iScreenHeight = 720;
} else if (lpCmdLine[0] == '2') {
g_iScreenWidth = 640;
g_iScreenHeight = 480;
} else if (lpCmdLine[0] == '3') {
// Vita
g_iScreenWidth = 720;
g_iScreenHeight = 408;
// Vita native
// g_iScreenWidth = 960;
// g_iScreenHeight = 544;
}
}
// Initialize global strings
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow)) {
return false;
}
hMyInst = hInstance;
if (FAILED(InitDevice())) {
CleanupDevice();
return 0;
}
static bool bTrialTimerDisplayed = true;
app.loadMediaArchive();
PlatformRenderer.Initialise(g_pd3dDevice, g_pSwapChain);
app.loadStringTable();
ui.init(g_pd3dDevice, g_pImmediateContext, g_pRenderTargetView,
g_pDepthStencilView, g_iScreenWidth, g_iScreenHeight);
////////////////
// Initialise //
////////////////
// Set the number of possible joypad layouts that the user can switch
// between, and the number of actions
PlatformInput.Initialise(1, 3, MINECRAFT_ACTION_MAX, ACTION_MAX_MENU);
// Set the default joypad action mappings for Minecraft
DefineActions();
PlatformInput.SetJoypadMapVal(0, 0);
PlatformInput.SetKeyRepeatRate(0.3f, 0.2f);
// Initialise the profile manager with the game Title ID, Offer ID, a
// profile version number, and the number of profile values and settings
PlatformProfile.Initialise(
TITLEID_MINECRAFT, app.m_dwOfferID, PROFILE_VERSION_10,
NUM_PROFILE_VALUES, NUM_PROFILE_SETTINGS, dwProfileSettingsA,
app.GAME_DEFINED_PROFILE_DATA_BYTES * XUSER_MAX_COUNT,
&app.uiGameDefinedDataChangedBitmask);
// Set a callback for the default player options to be set - when there is
// no profile data for the player
PlatformProfile.SetDefaultOptionsCallback(
[](IPlatformProfile::PROFILESETTINGS* pSettings, int iPad) {
return Game::DefaultOptionsCallback(&app, pSettings, iPad);
});
// QNet needs to be setup after profile manager, as we do not want its
// Notify listener to handle XN_SYS_SIGNINCHANGED notifications. This does
// mean that we need to have a callback in the PlatformProfile for
// XN_LIVE_INVITE_ACCEPTED for QNet.
g_NetworkManager.Initialise();
// 4J-PB moved further down
// app.InitGameSettings();
// debug switch to trial version
PlatformProfile.SetDebugFullOverride(true);
// Initialise TLS for tesselator, for this main thread
Tesselator::CreateNewThreadStorage(1024 * 1024);
// Initialise TLS for AABB and Vec3 pools, for this main thread
Compression::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache();
Tile::CreateNewThreadStorage();
Minecraft::main();
Minecraft* pMinecraft = Minecraft::GetInstance();
app.InitGameSettings();
app.InitialiseTips();
// Set the default sound levels
pMinecraft->options->set(Options::Option::MUSIC, 1.0f);
pMinecraft->options->set(Options::Option::SOUND, 1.0f);
// app.TemporaryCreateGameStart();
// Sleep(10000);
MSG msg = {0};
while (WM_QUIT != msg.message) {
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}
PlatformRenderer.StartFrame();
// static bool bPlay=false;
// if(bPlay)
// {
// bPlay=false;
// app.audio.PlaySound();
// }
app.UpdateTime();
PlatformInput.Tick();
// PlatformProfile.Tick();
PlatformStorage.Tick();
PlatformRenderer.Tick();
// Tick the social networking manager.
// CSocialManager::Instance()->Tick();
// Tick sentient.
// SentientManager.Tick();
// g_NetworkManager.DoWork();
// PlatformLeaderboard.Tick();
// Render game graphics.
if (app.GetGameStarted()) {
pMinecraft->run_middle();
app.SetAppPaused(
g_NetworkManager.IsLocalGame() &&
g_NetworkManager.GetPlayerCount() == 1 &&
ui.IsPauseMenuDisplayed(PlatformProfile.GetPrimaryPad()));
} else {
pMinecraft->soundEngine->tick(nullptr, 0.0f);
pMinecraft->textures->tick(true, false);
if (app.GetReallyChangingSessionType()) {
pMinecraft
->tickAllConnections(); // Added to stop timing out when we
// are waiting after converting to
// an offline game
}
}
pMinecraft->soundEngine->playMusicTick();
ui.tick();
ui.render();
// Present the frame.
PlatformRenderer.Present();
ui.CheckMenuDisplayed();
// Any threading type things to deal with from the xui side?
app.HandleXuiActions();
// need to turn off the trial timer if it was on
if (bTrialTimerDisplayed) {
ui.ShowTrialTimer(false);
bTrialTimerDisplayed = false;
}
// Fix for #7318 - Title crashes after short soak in the leaderboards
}
// Free resources, unregister custom classes, and exit.
// app.Uninit();
g_pd3dDevice->Release();
}

View file

@ -71,11 +71,11 @@ void Minimap::reloadColours() {
int b = ((color) & 0xff) * br / 255;
// 4J - changed byte order to save having to reorder later
// #if defined(_WIN64) || __linux__
#if 1
LUT[i] = 255 << 24 | b << 16 | g << 8 | r;
// #else
// LUT[i] = r << 24 | g << 16 | b << 8 | 255;
// #endif
#else
LUT[i] = r << 24 | g << 16 | b << 8 | 255;
#endif
// pixels[i] = (255) << 24 | r << 16 | g << 8 | b;
}

View file

@ -988,11 +988,11 @@ void GameRenderer::updateLightTexture(float a) {
int g = (int)(_g * 255);
int b = (int)(_b * 255);
// #if defined(_WIN64) || __linux__
#if 1
lightPixels[j][i] = alpha << 24 | b << 16 | g << 8 | r;
// #else
#else
// lightPixels[j][i] = r << 24 | g << 16 | b << 8 | alpha;
// #endif
#endif
}
mc->textures->replaceTextureDirect(lightPixels[j], 16, 16,

View file

@ -200,10 +200,6 @@ bool Connection::writeTick() {
}
Packet::writePacket(packet, bufferedDos);
// #if defined(__linux__)
// bufferedDos->flush(); // Ensure buffered data reaches socket before any
// // other writes
// #endif
#if !defined(_CONTENT_PACKAGE)
// 4J Added for debugging
@ -252,15 +248,6 @@ bool Connection::writeTick() {
// write it to QNet as a single packet with priority flags Otherwise
// just buffer the packet with other outgoing packets as the java game
// did
// #if defined(__linux__)
// // Linux fix: For local connections, always use bufferedDos to avoid
// // byte interleaving between the BufferedOutputStream buffer and direct
// // sos writes. The shouldDelay/writeWithFlags path writes directly to
// // sos, which can inject bytes BEFORE unflushed bufferedDos data.
// Packet::writePacket(packet, bufferedDos);
// bufferedDos->flush(); // Ensure data reaches socket immediately for
// // delayed packets
// #else
if (packet->shouldDelay) {
Packet::writePacket(packet, byteArrayDos);
@ -276,8 +263,6 @@ bool Connection::writeTick() {
Packet::writePacket(packet, bufferedDos);
}
// #endif
#if !defined(_CONTENT_PACKAGE)
// 4J Added for debugging
if (!socket->isLocal()) {