I keep confusing myself, so always have result parameters as first.

This commit is contained in:
UnknownShadow200 2017-05-28 15:15:50 +10:00
parent 673ae93b0c
commit 055e564acc
10 changed files with 142 additions and 142 deletions

View file

@ -1,8 +1,8 @@
#ifndef CS_CHUNKINFO_H
#define CS_CHUNKINFO_H
#include "Typedefs.h"
/* Describes data necessary for rendering a chunk.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
#ifndef CS_CHUNKINFO_H
#define CS_CHUNKINFO_H
#include "Typedefs.h"
/* Describes data necessary for rendering a chunk.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
typedef struct ChunkPartInfo {
@ -42,5 +42,5 @@ typedef struct ChunkInfo {
} ChunkInfo;
/* Resets contents of given chunk render info structure. */
void ChunkInfo_Reset(ChunkInfo* chunk, Int32 x, Int32 y, Int32 z) { sizeof(ChunkInfo); }
void ChunkInfo_Reset(ChunkInfo* chunk, Int32 x, Int32 y, Int32 z);
#endif

View file

@ -11,9 +11,9 @@ bool Intersection_RayIntersectsRotatedBox(Vector3 origin, Vector3 dir, Entity* t
* /
/
*/
Vector3 delta; Vector3_Subtract(&origin, &target->Position, &delta); /* delta = origin - target.Position */
Vector3 delta; Vector3_Subtract(&delta, &origin, &target->Position); /* delta = origin - target.Position */
delta = Intersection_InverseRotate(delta, target); /* delta = UndoRotation(delta) */
Vector3_Add(&delta, &target->Position, &origin); /* origin = delta + target.Position */
Vector3_Add(&origin, &delta, &target->Position); /* origin = delta + target.Position */
dir = Intersection_InverseRotate(dir, target);
AABB bb = target.PickingBounds;

View file

@ -1,85 +1,85 @@
#ifndef CS_MAPRENDERER_H
#define CS_MAPRENDERER_H
#include "Typedefs.h"
#include "TerrainAtlas1D.h"
#include "ChunkInfo.h"
#ifndef CS_MAPRENDERER_H
#define CS_MAPRENDERER_H
#include "Typedefs.h"
#include "TerrainAtlas1D.h"
#include "ChunkInfo.h"
/* Renders the blocks of the world by subdividing it into chunks.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
/* Width of the world, in terms of number of chunks. */
Int32 MapRenderer_ChunksX;
/* Height of the world, in terms of number of chunks. */
Int32 MapRenderer_ChunksY;
/* Length of the world, in terms of number of chunks. */
Int32 MapRenderer_ChunksZ;
/* Packs a coordinate into a single integer index. */
#define MapRenderer_Pack(cx, cy, cz) (((cz) * MapRenderer_ChunksY + (cy)) * MapRenderer_ChunksX + (cx))
/* TODO: Swap Y and Z? Make sure to update ChunkUpdater's ResetChunkCache and ClearChunkCache methods! */
/* The count of actual used 1D atlases. (i.e. 1DIndex(maxTextureLoc) + 1*/
Int32 MapRenderer_1DUsedCount;
/* The number of non-empty ChunkPartInfos (across entire world) for each 1D atlas batch.
1D atlas batches that do not have any ChunkPartInfos can be entirely skipped. */
Int32 MapRenderer_PartsCount[Atlas1D_MaxAtlasesCount];
/* Whether there are any visible Translucent ChunkPartInfos for each 1D atlas batch.
1D atlas batches that do not have any visible translucent ChunkPartInfos can be skipped. */
bool MapRenderer_HasTranslucentParts[Atlas1D_MaxAtlasesCount];
/* Whether there are any visible Normal ChunkPartInfos for each 1D atlas batch.
1D atlas batches that do not have any visible normal ChunkPartInfos can be skipped. */
bool MapRenderer_HasNormalParts[Atlas1D_MaxAtlasesCount];
/* Whether renderer should check if there are any visible Translucent ChunkPartInfos for each 1D atlas batch. */
bool MapRenderer_CheckingTranslucentParts[Atlas1D_MaxAtlasesCount];
/* Whether renderer should check if there are any visible Normal ChunkPartInfos for each 1D atlas batch. */
bool MapRenderer_CheckingNormalParts[Atlas1D_MaxAtlasesCount];
/* Render info for all chunks in the world. Unsorted.*/
ChunkInfo* MapRenderer_Chunks;
/* The number of chunks in the world, or ChunksX * ChunksY * ChunksZ */
Int32 MapRenderer_ChunksCount;
/* Pointers to render info for all chunks in the world, sorted by distance from the camera. */
ChunkInfo** MapRenderer_SortedChunks;
/* Pointers to render info for all chunks in the world, sorted by distance from the camera.
Chunks that can be rendered (not empty and are visible) are included in this array. */
ChunkInfo** MapRenderer_RenderChunks;
/* The number of actually used pointers in the RenderChunks array.
Entries past this count should be ignored and skipped. */
Int32 MapRenderer_RenderChunksCount;
/* Retrieves the render info for the given chunk. */
ChunkInfo* MapRenderer_GetChunk(Int32 cx, Int32 cy, Int32 cz);
/* Marks the given chunk as needing to be deleted. */
void MapRenderer_RefreshChunk(Int32 cx, Int32 cy, Int32 cz);
/* Potentially generates meshes for several pending chunks. */
void MapRenderer_Update(Real64 deltaTime);
/* Renders all opaque and transparent blocks.
Pixels are either treated as fully replacing existing pixel, or skipped. */
void MapRenderer_RenderNormal(Real64 deltaTime);
/*Renders all translucent (e.g. water) blocks.
Pixels drawn blend into existing geometry.*/
void MapRenderer_RenderTranslucent(Real64 deltaTime);
static void MapRenderer_CheckWeather(Real64 deltaTime);
static void MapRenderer_RenderNormalBatch(Int32 batch);
static void MapRenderer_RenderTranslucentBatch(Int32 batch);
*/
/* Width of the world, in terms of number of chunks. */
Int32 MapRenderer_ChunksX;
/* Height of the world, in terms of number of chunks. */
Int32 MapRenderer_ChunksY;
/* Length of the world, in terms of number of chunks. */
Int32 MapRenderer_ChunksZ;
/* Packs a coordinate into a single integer index. */
#define MapRenderer_Pack(cx, cy, cz) (((cz) * MapRenderer_ChunksY + (cy)) * MapRenderer_ChunksX + (cx))
/* TODO: Swap Y and Z? Make sure to update ChunkUpdater's ResetChunkCache and ClearChunkCache methods! */
/* The count of actual used 1D atlases. (i.e. 1DIndex(maxTextureLoc) + 1*/
Int32 MapRenderer_1DUsedCount;
/* The number of non-empty ChunkPartInfos (across entire world) for each 1D atlas batch.
1D atlas batches that do not have any ChunkPartInfos can be entirely skipped. */
Int32 MapRenderer_PartsCount[Atlas1D_MaxAtlasesCount];
/* Whether there are any visible Translucent ChunkPartInfos for each 1D atlas batch.
1D atlas batches that do not have any visible translucent ChunkPartInfos can be skipped. */
bool MapRenderer_HasTranslucentParts[Atlas1D_MaxAtlasesCount];
/* Whether there are any visible Normal ChunkPartInfos for each 1D atlas batch.
1D atlas batches that do not have any visible normal ChunkPartInfos can be skipped. */
bool MapRenderer_HasNormalParts[Atlas1D_MaxAtlasesCount];
/* Whether renderer should check if there are any visible Translucent ChunkPartInfos for each 1D atlas batch. */
bool MapRenderer_CheckingTranslucentParts[Atlas1D_MaxAtlasesCount];
/* Whether renderer should check if there are any visible Normal ChunkPartInfos for each 1D atlas batch. */
bool MapRenderer_CheckingNormalParts[Atlas1D_MaxAtlasesCount];
/* Render info for all chunks in the world. Unsorted.*/
ChunkInfo* MapRenderer_Chunks;
/* The number of chunks in the world, or ChunksX * ChunksY * ChunksZ */
Int32 MapRenderer_ChunksCount;
/* Pointers to render info for all chunks in the world, sorted by distance from the camera. */
ChunkInfo** MapRenderer_SortedChunks;
/* Pointers to render info for all chunks in the world, sorted by distance from the camera.
Chunks that can be rendered (not empty and are visible) are included in this array. */
ChunkInfo** MapRenderer_RenderChunks;
/* The number of actually used pointers in the RenderChunks array.
Entries past this count should be ignored and skipped. */
Int32 MapRenderer_RenderChunksCount;
/* Retrieves the render info for the given chunk. */
ChunkInfo* MapRenderer_GetChunk(Int32 cx, Int32 cy, Int32 cz);
/* Marks the given chunk as needing to be deleted. */
void MapRenderer_RefreshChunk(Int32 cx, Int32 cy, Int32 cz);
/* Potentially generates meshes for several pending chunks. */
void MapRenderer_Update(Real64 deltaTime);
/* Renders all opaque and transparent blocks.
Pixels are either treated as fully replacing existing pixel, or skipped. */
void MapRenderer_RenderNormal(Real64 deltaTime);
/*Renders all translucent (e.g. water) blocks.
Pixels drawn blend into existing geometry.*/
void MapRenderer_RenderTranslucent(Real64 deltaTime);
static void MapRenderer_CheckWeather(Real64 deltaTime);
static void MapRenderer_RenderNormalBatch(Int32 batch);
static void MapRenderer_RenderTranslucentBatch(Int32 batch);
#endif

View file

@ -1,8 +1,8 @@
#ifndef FASTCOLOUR_H
#define FASTCOLOUR_H
#ifndef CS_PACKEDCOL_H
#define CS_PACKEDCOL_H
#include "Typedefs.h"
/* Manipulates an ARGB colour, in a format suitable for the native graphics api.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
/* Represents an ARGB colour, in a format suitable for the native graphics api. */
@ -40,5 +40,5 @@ void PackedCol_GetShaded(PackedCol normal, PackedCol* xSide, PackedCol* zSide, P
/* TODO: actual constant values? may need to rethink PackedCol */
#define FastColour_White PackedCol_Create3(255, 255, 255)
#define PackedCol_White PackedCol_Create3(255, 255, 255)
#endif

View file

@ -3,8 +3,8 @@
void SelectionBox_Make(SelectionBox* box, Vector3I* p1, Vector3I* p2, PackedCol col) {
box->ID = 0;
box->MinDist = 0.0f; box->MaxDist = 0.0f;
Vector3I_Min(p1, p2, &box->Min);
Vector3I_Max(p1, p2, &box->Max);
Vector3I_Min(&box->Min, p1, p2);
Vector3I_Max(&box->Max, p1, p2);
box->Colour = col;
}
@ -13,10 +13,10 @@ void SelectionBox_Render(SelectionBox* box, VertexP3fC4b** vertices, VertexP3fC4
Vector3 p1, p2;
PackedCol col = box->Colour;
Vector3I_ToVector3(&box->Min, &p1);
Vector3I_ToVector3(&box->Max, &p2);
Vector3_Add1(&p1, -offset, &p1);
Vector3_Add1(&p2, offset, &p2);
Vector3I_ToVector3(&p1, &box->Min);
Vector3I_ToVector3(&p2, &box->Max);
Vector3_Add1(&p1, &p1, -offset);
Vector3_Add1(&p2, &p2, offset);
SelectionBox_HorQuad(vertices, col, p1.X, p1.Z, p2.X, p2.Z, p1.Y); /* bottom */
SelectionBox_HorQuad(vertices, col, p1.X, p1.Z, p2.X, p2.Z, p2.Y); /* top */

View file

@ -31,7 +31,7 @@ bool Texture_IsValid(Texture* tex) {
void Texture_Render(Texture* tex) {
Gfx_BindTexture(tex->ID);
GfxCommon_Draw2DTexture(tex, FastColour_White);
GfxCommon_Draw2DTexture(tex, PackedCol_White);
}
void Texture_RenderShaded(Texture* tex, PackedCol shadeColour) {

View file

@ -11,25 +11,25 @@ Vector3I Vector3I_Create3(Int32 x, Int32 y, Int32 z) {
}
void Vector3I_Add(Vector3I* a, Vector3I* b, Vector3I* result) {
void Vector3I_Add(Vector3I* result, Vector3I* a, Vector3I* b) {
result->X = a->X + b->X;
result->Y = a->Y + b->Y;
result->Z = a->Z + b->Z;
}
void Vector3I_Subtract(Vector3I* a, Vector3I* b, Vector3I* result) {
void Vector3I_Subtract(Vector3I* result, Vector3I* a, Vector3I* b) {
result->X = a->X - b->X;
result->Y = a->Y - b->Y;
result->Z = a->Z - b->Z;
}
void Vector3I_Multiply1(Vector3I* a, Int32 scale, Vector3I* result) {
void Vector3I_Multiply1(Vector3I* result, Vector3I* a, Int32 scale) {
result->X = a->X * scale;
result->Y = a->Y * scale;
result->Z = a->Z * scale;
}
void Vector3I_Negate(Vector3I* a, Vector3I* result) {
void Vector3I_Negate(Vector3I* result, Vector3I* a) {
result->X = -a->X;
result->Y = -a->Y;
result->Z = -a->Z;
@ -40,25 +40,25 @@ bool Vector3I_Equals(Vector3I* a, Vector3I* b) {
return a->X == b->X && a->Y == b->Y && a->Z == b->Z;
}
void Vector3I_Floor(Vector3* a, Vector3I* result) {
void Vector3I_Floor(Vector3I* result, Vector3* a) {
result->X = Math_Floor(a->X);
result->Y = Math_Floor(a->Y);
result->Z = Math_Floor(a->Z);
}
void Vector3I_ToVector3(Vector3I* a, Vector3* result) {
void Vector3I_ToVector3(Vector3* result, Vector3I* a) {
result->X = (Real32)a->X;
result->Y = (Real32)a->Y;
result->Z = (Real32)a->Z;
}
void Vector3I_Min(Vector3I* a, Vector3I* b, Vector3I* result) {
void Vector3I_Min(Vector3I* result, Vector3I* a, Vector3I* b) {
result->X = min(a->X, b->X);
result->Y = min(a->Y, b->Y);
result->Z = min(a->Z, b->Z);
}
void Vector3I_Max(Vector3I* a, Vector3I* b, Vector3I* result) {
void Vector3I_Max(Vector3I* result, Vector3I* a, Vector3I* b) {
result->X = max(a->X, b->X);
result->Y = max(a->Y, b->Y);
result->Z = max(a->Z, b->Z);

View file

@ -24,30 +24,30 @@ Vector3I Vector3I_Create3(Int32 x, Int32 y, Int32 z);
/* Adds a and b. */
void Vector3I_Add(Vector3I* a, Vector3I* b, Vector3I* result);
void Vector3I_Add(Vector3I* result, Vector3I* a, Vector3I* b);
/* Subtracts b from a. */
void Vector3I_Subtract(Vector3I* a, Vector3I* b, Vector3I* result);
void Vector3I_Subtract(Vector3I* result, Vector3I* a, Vector3I* b);
/* Multiplies all components of a by scale. */
void Vector3I_Multiply1(Vector3I* a, Int32 scale, Vector3I* result);
void Vector3I_Multiply1(Vector3I* result, Vector3I* a, Int32 scale);
/* Negates components of a. */
void Vector3I_Negate(Vector3I* a, Vector3I* result);
void Vector3I_Negate(Vector3I* result, Vector3I* a);
/* Returns whether the two vectors are exact same on all axes. */
bool Vector3I_Equals(Vector3I* a, Vector3I* b);
/* Returns a vector such that each component is floor of input floating-point component.*/
void Vector3I_Floor(Vector3* a, Vector3I* result);
void Vector3I_Floor(Vector3I* result, Vector3* a);
/* Returns a vector with the integer components converted to floating-point components.*/
void Vector3I_ToVector3(Vector3I* a, Vector3* result);
void Vector3I_ToVector3(Vector3* result, Vector3I* a);
/* Returns a vector such that each component is minimum of corresponding a and b component.*/
void Vector3I_Min(Vector3I* a, Vector3I* b, Vector3I* result);
void Vector3I_Min(Vector3I* result, Vector3I* a, Vector3I* b);
/* Returns a vector such that each component is maximum of corresponding a and b component.*/
void Vector3I_Max(Vector3I* a, Vector3I* b, Vector3I* result);
void Vector3I_Max(Vector3I* result, Vector3I* a, Vector3I* b);
#endif

View file

@ -24,48 +24,48 @@ Real32 Vector3_LengthSquared(Vector3* v) {
}
void Vector3_Add(Vector3* a, Vector3* b, Vector3* result) {
void Vector3_Add(Vector3* result, Vector3* a, Vector3* b) {
result->X = a->X + b->X;
result->Y = a->Y + b->Y;
result->Z = a->Z + b->Z;
}
void Vector3_Add1(Vector3* a, Real32 b, Vector3* result) {
void Vector3_Add1(Vector3* result, Vector3* a, Real32 b) {
result->X = a->X + b;
result->Y = a->Y + b;
result->Z = a->Z + b;
}
void Vector3_Subtract(Vector3* a, Vector3* b, Vector3* result) {
void Vector3_Subtract(Vector3* result, Vector3* a, Vector3* b) {
result->X = a->X - b->X;
result->Y = a->Y - b->Y;
result->Z = a->Z - b->Z;
}
void Vector3_Multiply1(Vector3* a, Real32 scale, Vector3* result) {
void Vector3_Multiply1(Vector3* result, Vector3* a, Real32 scale) {
result->X = a->X * scale;
result->Y = a->Y * scale;
result->Z = a->Z * scale;
}
void Vector3_Multiply3(Vector3* a, Vector3* scale, Vector3* result) {
void Vector3_Multiply3(Vector3* result, Vector3* a, Vector3* scale) {
result->X = a->X * scale->X;
result->Y = a->Y * scale->Y;
result->Z = a->Z * scale->Z;
}
void Vector3_Divide1(Vector3* a, Real32 scale, Vector3* result) {
Vector3_Multiply1(a, 1.0f / scale, result);
void Vector3_Divide1(Vector3* result, Vector3* a, Real32 scale) {
Vector3_Multiply1(result, a, 1.0f / scale);
}
void Vector3_Divide3(Vector3* a, Vector3* scale, Vector3* result) {
void Vector3_Divide3(Vector3* result, Vector3* a, Vector3* scale) {
result->X = a->X / scale->X;
result->Y = a->Y / scale->Y;
result->Z = a->Z / scale->Z;
}
void Vector3_Lerp(Vector3* a, Vector3* b, Real32 blend, Vector3* result) {
void Vector3_Lerp(Vector3* result, Vector3* a, Vector3* b, Real32 blend) {
result->X = blend * (b->X - a->X) + a->X;
result->Y = blend * (b->Y - a->Y) + a->Y;
result->Z = blend * (b->Z - a->Z) + a->Z;
@ -75,13 +75,13 @@ Real32 Vector3_Dot(Vector3* a, Vector3* b) {
return a->X * b->X + a->Y * b->Y + a->Z * b->Z;
}
void Vector3_Cross(Vector3* a, Vector3* b, Vector3* result) {
void Vector3_Cross(Vector3* result, Vector3* a, Vector3* b) {
result->X = a->Y * b->Z - a->Z * b->Y;
result->Y = a->Z * b->X - a->X * b->Z;
result->Z = a->X * b->Y - a->Y * b->X;
}
void Vector3_Normalize(Vector3* a, Vector3* result) {
void Vector3_Normalize(Vector3* result, Vector3* a) {
float scale = 1.0f / Vector3_Length(a);
result->X = a->X * scale;
result->Y = a->Y * scale;
@ -89,13 +89,13 @@ void Vector3_Normalize(Vector3* a, Vector3* result) {
}
void Vector3_Transform(Vector3* a, Matrix* mat, Vector3* result) {
void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat) {
result->X = a->X * mat->Row0.X + a->Y * mat->Row1.X + a->Z * mat->Row2.X + mat->Row3.X;
result->Y = a->X * mat->Row0.Y + a->Y * mat->Row1.Y + a->Z * mat->Row2.Y + mat->Row3.Y;
result->Z = a->X * mat->Row0.Z + a->Y * mat->Row1.Z + a->Z * mat->Row2.Z + mat->Row3.Z;
}
void Vector3_TransformY(Real32 y, Matrix* mat, Vector3* result) {
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat) {
result->X = y * mat->Row1.X + mat->Row3.X;
result->Y = y * mat->Row1.Y + mat->Row3.Y;
result->Z = y * mat->Row1.Z + mat->Row3.Z;;

View file

@ -41,45 +41,45 @@ Real32 Vector3_LengthSquared(Vector3* v);
/* Adds a and b. */
void Vector3_Add(Vector3* a, Vector3* b, Vector3* result);
void Vector3_Add(Vector3* result, Vector3* a, Vector3* b);
/* Adds b to all components of a. */
void Vector3_Add1(Vector3* a, Real32 b, Vector3* result);
void Vector3_Add1(Vector3* result, Vector3* a, Real32 b);
/* Subtracts b from a. */
void Vector3_Subtract(Vector3* a, Vector3* b, Vector3* result);
void Vector3_Subtract(Vector3* result, Vector3* a, Vector3* b);
/* Multiplies all components of a by scale. */
void Vector3_Multiply1(Vector3* a, Real32 scale, Vector3* result);
void Vector3_Multiply1(Vector3* result, Vector3* a, Real32 scale);
/* Multiplies components of a by scale. */
void Vector3_Multiply3(Vector3* a, Vector3* scale, Vector3* result);
void Vector3_Multiply3(Vector3* result, Vector3* a, Vector3* scale);
/* Divides all components of a by scale. */
void Vector3_Divide1(Vector3* a, Real32 scale, Vector3* result);
void Vector3_Divide1(Vector3* result, Vector3* a, Real32 scale);
/* Divides components of a by scale. */
void Vector3_Divide3(Vector3* a, Vector3* scale, Vector3* result);
void Vector3_Divide3(Vector3* result, Vector3* a, Vector3* scale);
/* Linearly interpolates between two vectors. */
void Vector3_Lerp(Vector3* a, Vector3* b, Real32 blend, Vector3* result);
void Vector3_Lerp(Vector3* result, Vector3* a, Vector3* b, Real32 blend);
/* Calculates the dot product of two vectors. */
Real32 Vector3_Dot(Vector3* left, Vector3* right);
/* Calculates the cross product of two vectors. */
void Vector3_Cross(Vector3* a, Vector3* b, Vector3* result);
void Vector3_Cross(Vector3* result, Vector3* a, Vector3* b);
/* Calculates the normal of a vector. */
void Vector3_Normalize(Vector3* a, Vector3* result);
void Vector3_Normalize(Vector3* result, Vector3* a);
/* Transforms a vector by the given matrix. */
void Vector3_Transform(Vector3* a, Matrix* mat, Vector3* result);
void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat);
/* Transforms the Y component of a vector by the given matrix. */
void Vector3_TransformY(Real32 y, Matrix* mat, Vector3* result);
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat);
/* Rotates the given 3D coordinates around the x axis. */
Vector3 Vector3_RotateX(Vector3 v, Real32 angle);