mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 20:15:35 -04:00
Little bit less use of generics
This commit is contained in:
parent
7000e9d0c1
commit
7a77a34b14
@ -90,7 +90,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
for (int i = 0; i < namesCount; i++) {
|
||||
PlayerInfo pInfo = info[i];
|
||||
if (!pInfo.IsGroup && pInfo.NameId == e.Id) {
|
||||
RemoveInfoAt(info, i);
|
||||
RemoveItemAt(info, i);
|
||||
RemoveTextureAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -168,21 +169,18 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
DrawTextArgs args = new DrawTextArgs(group, titleFont, true);
|
||||
Texture tex = game.Drawer2D.MakeTextTexture(ref args, 0, 0);
|
||||
game.Drawer2D.ReducePadding(ref tex, Utils.Floor(titleFont.Size), 3);
|
||||
PlayerInfo pInfo = new PlayerInfo(group);
|
||||
|
||||
PushDown(info, index, pInfo);
|
||||
PushDown(textures, index, tex);
|
||||
for (int i = info.Length - 1; i > index; i--) {
|
||||
info[i] = info[i - 1];
|
||||
textures[i] = textures[i - 1];
|
||||
}
|
||||
info[index] = new PlayerInfo(group);
|
||||
textures[index] = tex;
|
||||
|
||||
index++;
|
||||
namesCount++;
|
||||
}
|
||||
|
||||
void PushDown<T>(T[] array, int index, T value) {
|
||||
for (int i = array.Length - 1; i > index; i--) {
|
||||
array[i] = array[i - 1];
|
||||
}
|
||||
array[index] = value;
|
||||
}
|
||||
|
||||
int GetGroupCount(int startIndex) {
|
||||
string group = info[startIndex].GroupName;
|
||||
int count = 0;
|
||||
|
@ -98,7 +98,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
for (int i = 0; i < namesCount; i++) {
|
||||
PlayerInfo pInfo = info[i];
|
||||
if (pInfo.Id == e.Id) {
|
||||
RemoveInfoAt(info, i);
|
||||
RemoveItemAt(info, i);
|
||||
RemoveTextureAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -119,10 +119,9 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
protected abstract void SortInfoList();
|
||||
|
||||
protected void RemoveInfoAt<T>(T[] info, int i) {
|
||||
protected void RemoveTextureAt(int i) {
|
||||
Texture tex = textures[i];
|
||||
gfx.DeleteTexture(ref tex);
|
||||
RemoveItemAt(info, i);
|
||||
gfx.DeleteTexture(ref tex);
|
||||
RemoveItemAt(textures, i);
|
||||
namesCount--;
|
||||
SortPlayerInfo();
|
||||
|
@ -86,10 +86,10 @@ namespace ClassicalSharp.Renderers {
|
||||
v.X = x2; v.Z = z2; v.U = 1; vertices[vCount++] = v;
|
||||
v.Y = y1; v.V = v1; vertices[vCount++] = v;
|
||||
|
||||
v.Z = z1; vertices[vCount++] = v;
|
||||
v.Y = y2; v.V = v2; vertices[vCount++] = v;
|
||||
v.X = x1; v.Z = z2; v.U = 0; vertices[vCount++] = v;
|
||||
v.Y = y1; v.V = v1; vertices[vCount++] = v;
|
||||
v.Z = z1; vertices[vCount++] = v;
|
||||
v.Y = y2; v.V = v2; vertices[vCount++] = v;
|
||||
v.X = x1; v.Z = z2; v.U = 0; vertices[vCount++] = v;
|
||||
v.Y = y1; v.V = v1; vertices[vCount++] = v;
|
||||
}
|
||||
if (particles && (rainAcc >= 0.25 || moved)) {
|
||||
rainAcc = 0;
|
||||
|
@ -1,14 +1,13 @@
|
||||
#include "Bitmap.h"
|
||||
#include "Platform.h"
|
||||
#include "PackedCol.h"
|
||||
#include "ExtMath.h"
|
||||
|
||||
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, Int32 stride, UInt8* scan0) {
|
||||
bmp->Width = width; bmp->Height = height; bmp->Stride = stride; bmp->Scan0 = scan0;
|
||||
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0) {
|
||||
bmp->Width = width; bmp->Height = height;
|
||||
bmp->Stride = width * Bitmap_PixelBytesSize;
|
||||
bmp->Scan0 = scan0;
|
||||
}
|
||||
|
||||
UInt32* Bitmap_GetRow(Bitmap* bmp, Int32 y) {
|
||||
return (UInt32*)(bmp->Scan0 + (y * bmp->Stride));
|
||||
}
|
||||
|
||||
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size) {
|
||||
Int32 x, y;
|
||||
for (y = 0; y < size; y++) {
|
||||
@ -31,6 +30,6 @@ void Bitmap_CopyRow(Int32 srcY, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 widt
|
||||
|
||||
void Bitmap_Allocate(Bitmap* bmp, Int32 width, Int32 height) {
|
||||
bmp->Width = width; bmp->Height = height;
|
||||
bmp->Stride = width * sizeof(UInt32);
|
||||
bmp->Stride = width * Bitmap_PixelBytesSize;
|
||||
bmp->Scan0 = Platform_MemAlloc(Bitmap_DataSize(width, height));
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#ifndef CS_BITMAP_H
|
||||
#define CS_BITMAP_H
|
||||
#include "Typedefs.h"
|
||||
#include "Stream.h"
|
||||
/* Represents a 2D array of pixels.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
@ -8,13 +9,10 @@
|
||||
typedef struct Bitmap_ {
|
||||
/* Pointer to first scaneline. */
|
||||
UInt8* Scan0;
|
||||
|
||||
/* Number of bytes in each scanline. */
|
||||
Int32 Stride;
|
||||
|
||||
Int32 Stride; /* TODO: Obsolete this completely and just use Width << 2 ? */
|
||||
/* Number of pixels horizontally. */
|
||||
Int32 Width;
|
||||
|
||||
/* Number of pixels vertically. */
|
||||
Int32 Height;
|
||||
} Bitmap;
|
||||
@ -22,23 +20,19 @@ typedef struct Bitmap_ {
|
||||
|
||||
/* Size of each ARGB pixel in bytes. */
|
||||
#define Bitmap_PixelBytesSize 4
|
||||
|
||||
/* Calculates size of data of a 2D bitmap in bytes. */
|
||||
#define Bitmap_DataSize(width, height) ((UInt32)(width) * (UInt32)(height) * (UInt32)Bitmap_PixelBytesSize)
|
||||
|
||||
/* Returns a pointer to the start of the y'th scanline. */
|
||||
#define Bitmap_GetRow(bmp, y) ((UInt32*)((bmp)->Scan0 + ((y) * (bmp)->Stride)))
|
||||
|
||||
/* Constructs or updates a Bitmap instance. */
|
||||
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, Int32 stride, UInt8* scan0);
|
||||
|
||||
/* Returns a pointer to the start of the y'th scanline. */
|
||||
UInt32* Bitmap_GetRow(Bitmap* bmp, Int32 y);
|
||||
|
||||
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0);
|
||||
/* Copies a block of pixels from one bitmap to another. */
|
||||
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size);
|
||||
|
||||
/* Copies a row of pixels from one bitmap to another. */
|
||||
void Bitmap_CopyRow(Int32 srcY, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 width);
|
||||
|
||||
/* Allocates a new bitmap of the given dimensions. You are responsible for freeing its memory! */
|
||||
void Bitmap_Allocate(Bitmap* bmp, Int32 width, Int32 height);
|
||||
/* Decodes a PNG bitmap from the given stream. */
|
||||
void Bitmap_DecodePng(Bitmap* bmp, Stream* stream);
|
||||
#endif
|
@ -335,7 +335,7 @@ void D3D9_DoMipmaps(IDirect3DTexture9* texture, Int32 x, Int32 y, Bitmap* bmp, b
|
||||
GfxCommon_GenMipmaps(width, height, cur, prev);
|
||||
|
||||
Bitmap mipmap;
|
||||
Bitmap_Create(&mipmap, width, height, width * Bitmap_PixelBytesSize, cur);
|
||||
Bitmap_Create(&mipmap, width, height, cur);
|
||||
if (partial) {
|
||||
D3D9_SetTexturePartData(texture, x, y, &mipmap, lvl);
|
||||
} else {
|
||||
|
@ -13,6 +13,10 @@ PackedCol PackedCol_Create3(UInt8 r, UInt8 g, UInt8 b) {
|
||||
return col;
|
||||
}
|
||||
|
||||
UInt32 PackedCol_ToARGB(PackedCol col) {
|
||||
return PackedCol_ARGB(col.R, col.G, col.B, col.A);
|
||||
}
|
||||
|
||||
PackedCol PackedCol_Scale(PackedCol value, Real32 t) {
|
||||
value.R = (UInt8)(value.R * t);
|
||||
value.G = (UInt8)(value.G * t);
|
||||
|
@ -20,28 +20,25 @@ typedef struct PackedCol_ {
|
||||
|
||||
/* Constructs a new ARGB colour. */
|
||||
PackedCol PackedCol_Create4(UInt8 r, UInt8 g, UInt8 b, UInt8 a);
|
||||
|
||||
/* Constructs a new ARGB colour. */
|
||||
PackedCol PackedCol_Create3(UInt8 r, UInt8 g, UInt8 b);
|
||||
|
||||
/* Returns whether two packed colours are equal. */
|
||||
#define PackedCol_Equals(a, b) (a.Packed == b.Packed)
|
||||
|
||||
/* Converts a colour to ARGB form. */
|
||||
#define PackedCol_ARGB(r, g, b, a) (((UInt32)(r) << 16) | ((UInt32)(g) << 8) | ((UInt32)(b)) | ((UInt32)(a) << 24))
|
||||
/* Converts a colour to ARGB form. */
|
||||
UInt32 PackedCol_ToARGB(PackedCol col);
|
||||
/* Multiplies the RGB components by t, where t is in [0, 1] */
|
||||
PackedCol PackedCol_Scale(PackedCol value, Real32 t);
|
||||
|
||||
/* Linearly interpolates the RGB components of both colours by t, where t is in [0, 1] */
|
||||
PackedCol PackedCol_Lerp(PackedCol a, PackedCol b, Real32 t);
|
||||
|
||||
|
||||
#define PackedCol_ShadeX 0.6f
|
||||
#define PackedCol_ShadeZ 0.8f
|
||||
#define PackedCol_ShadeYBottom 0.5f
|
||||
|
||||
/* Retrieves shaded colours for ambient block face lighting. */
|
||||
void PackedCol_GetShaded(PackedCol normal, PackedCol* xSide, PackedCol* zSide, PackedCol* yBottom);
|
||||
|
||||
|
||||
/* TODO: actual constant values? may need to rethink PackedCol */
|
||||
#define PackedCol_White PackedCol_Create3(255, 255, 255)
|
||||
#define PackedCol_Black PackedCol_Create3( 0, 0, 0)
|
||||
|
@ -4,9 +4,9 @@
|
||||
#include "String.h"
|
||||
#include "ErrorHandler.h"
|
||||
|
||||
#define STREAM_SEEK_BEGIN 0
|
||||
#define STREAM_SEEK_CURRENT 1
|
||||
#define STREAM_SEEK_END 2
|
||||
#define STREAM_SEEKFROM_BEGIN 0
|
||||
#define STREAM_SEEKFROM_CURRENT 1
|
||||
#define STREAM_SEEKFROM_END 2
|
||||
|
||||
typedef ReturnCode(*Stream_Operation)(UInt8* data, UInt32 count, UInt32* modified);
|
||||
typedef ReturnCode(*Stream_Seek)(Int32 offset, Int32 seekType);
|
||||
|
@ -38,7 +38,7 @@ Int32 Atlas2D_LoadTextureElement(TextureLoc texLoc) {
|
||||
} else {
|
||||
// TODO: does this even work??
|
||||
UInt8 scan0[Bitmap_DataSize(64, 64)];
|
||||
Bitmap_Create(&element, size, size, 64 * Bitmap_PixelBytesSize, scan0);
|
||||
Bitmap_Create(&element, size, size, scan0);
|
||||
return Atlas2D_LoadTextureElement_Raw(texLoc, &element);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user