mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 18:13:15 -05:00
Port Options.Set to C.
This commit is contained in:
parent
f84ba17d17
commit
cf8812a03c
13 changed files with 85 additions and 21 deletions
|
@ -50,7 +50,7 @@ namespace ClassicalSharp.Renderers {
|
|||
protected abstract void EnvVariableChanged(object sender, EnvVarEventArgs e);
|
||||
|
||||
|
||||
protected BlockID BlockOn(out float fogDensity, out FastColour fogCol) {
|
||||
protected void BlockOn(out float fogDensity, out FastColour fogCol) {
|
||||
Vector3 pos = game.CurrentCameraPos;
|
||||
Vector3I coords = Vector3I.Floor(pos);
|
||||
|
||||
|
@ -68,7 +68,6 @@ namespace ClassicalSharp.Renderers {
|
|||
float blend = (float)BlendFactor(game.ViewDistance);
|
||||
fogCol = FastColour.Lerp(map.Env.FogCol, map.Env.SkyCol, blend);
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
double BlendFactor(float x) {
|
||||
|
|
|
@ -105,7 +105,7 @@ namespace ClassicalSharp.Renderers {
|
|||
if (map.blocks == null) return;
|
||||
FastColour fogCol = FastColour.White;
|
||||
float fogDensity = 0;
|
||||
BlockID block = BlockOn(out fogDensity, out fogCol);
|
||||
BlockOn(out fogDensity, out fogCol);
|
||||
gfx.ClearColour(fogCol);
|
||||
|
||||
// TODO: rewrite this to avoid raising the event? want to avoid recreating vbos too many times often
|
||||
|
@ -167,7 +167,7 @@ namespace ClassicalSharp.Renderers {
|
|||
if (map.blocks == null || minimal) return;
|
||||
FastColour fogCol = FastColour.White;
|
||||
float fogDensity = 0;
|
||||
BlockID block = BlockOn(out fogDensity, out fogCol);
|
||||
BlockOn(out fogDensity, out fogCol);
|
||||
|
||||
if (fogDensity != 0) {
|
||||
gfx.SetFogMode(Fog.Exp);
|
||||
|
|
|
@ -14,7 +14,7 @@ Real32 Camera_AdjustHeadX(Real32 value) {
|
|||
return value * MATH_DEG2RAD;
|
||||
}
|
||||
|
||||
Vector3 PerspectiveCamera_GetDirVector() {
|
||||
Vector3 PerspectiveCamera_GetDirVector(void) {
|
||||
Entity* p = &LocalPlayer_Instance.Base.Base;
|
||||
Real32 yaw = p->HeadY * MATH_DEG2RAD;
|
||||
Real32 pitch = Camera_AdjustHeadX(p->HeadX);
|
||||
|
|
|
@ -744,7 +744,7 @@ void Gfx_BeginFrame(void) {
|
|||
void Gfx_EndFrame(void) {
|
||||
IDirect3DDevice9_EndScene(device);
|
||||
ReturnCode code = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
|
||||
if (code >= 0) return;
|
||||
if ((Int32)code >= 0) return;
|
||||
|
||||
if (code != D3DERR_DEVICELOST) {
|
||||
ErrorHandler_FailWithCode(code, "D3D9_EndFrame");
|
||||
|
|
|
@ -32,7 +32,7 @@ void LocationUpdate_Empty(LocationUpdate* update) {
|
|||
}
|
||||
|
||||
void LocationUpdate_MakeOri(LocationUpdate* update, Real32 rotY, Real32 headX) {
|
||||
LocationUpdate_Construct(update, 0.0f, 0.0f, 0.0f, exc, rotY, exc, exc, false, false);
|
||||
LocationUpdate_Construct(update, 0.0f, 0.0f, 0.0f, exc, rotY, exc, headX, false, false);
|
||||
}
|
||||
|
||||
void LocationUpdate_MakePos(LocationUpdate* update, Vector3 pos, bool rel) {
|
||||
|
|
|
@ -22,7 +22,7 @@ Real32 EnvRenderer_BlendFactor(Real32 x) {
|
|||
return blend;
|
||||
}
|
||||
|
||||
BlockID EnvRenderer_BlockOn(Real32* fogDensity, PackedCol* fogCol) {
|
||||
void EnvRenderer_BlockOn(Real32* fogDensity, PackedCol* fogCol) {
|
||||
Vector3 pos = Game_CurrentCameraPos;
|
||||
Vector3I coords;
|
||||
Vector3I_Floor(&coords, &pos); /* coords = floor(pos); */
|
||||
|
@ -42,7 +42,6 @@ BlockID EnvRenderer_BlockOn(Real32* fogDensity, PackedCol* fogCol) {
|
|||
Real32 blend = EnvRenderer_BlendFactor(Game_ViewDistance);
|
||||
*fogCol = PackedCol_Lerp(WorldEnv_FogCol, WorldEnv_SkyCol, blend);
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,7 +50,7 @@ void EnvRenderer_RenderMinimal(Real64 deltaTime) {
|
|||
|
||||
PackedCol fogCol = PackedCol_White;
|
||||
Real32 fogDensity = 0.0f;
|
||||
BlockID block = EnvRenderer_BlockOn(&fogDensity, &fogCol);
|
||||
EnvRenderer_BlockOn(&fogDensity, &fogCol);
|
||||
Gfx_ClearColour(fogCol);
|
||||
|
||||
/* TODO: rewrite this to avoid raising the event? want to avoid recreating vbos too many times often */
|
||||
|
@ -114,7 +113,7 @@ void EnvRenderer_UpdateFog(void) {
|
|||
if (World_Blocks == NULL || EnvRenderer_Minimal) return;
|
||||
PackedCol fogCol = PackedCol_White;
|
||||
Real32 fogDensity = 0.0f;
|
||||
BlockID block = EnvRenderer_BlockOn(&fogDensity, &fogCol);
|
||||
EnvRenderer_BlockOn(&fogDensity, &fogCol);
|
||||
|
||||
if (fogDensity != 0.0f) {
|
||||
Gfx_SetFogMode(Fog_Exp);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "GraphicsAPI.h"
|
||||
#include "Camera.h"
|
||||
#include "Options.h"
|
||||
#include "Funcs.h"
|
||||
|
||||
void Game_UpdateProjection(void) {
|
||||
Game_DefaultFov = Options_GetInt(OptionsKey_FieldOfView, 1, 150, 70);
|
||||
|
@ -34,6 +35,20 @@ void Game_UpdateBlock(Int32 x, Int32 y, Int32 z, BlockID block) {
|
|||
MapRenderer_RefreshChunk(cx, cy, cz);
|
||||
}
|
||||
|
||||
void Game_SetViewDistance(Real32 distance, bool userDist) {
|
||||
if (userDist) {
|
||||
Game_UserViewDistance = distance;
|
||||
Options_SetInt32(OptionsKey_ViewDist, (Int32)distance);
|
||||
}
|
||||
|
||||
distance = min(distance, Game_MaxViewDistance);
|
||||
if (distance == Game_ViewDistance) return;
|
||||
Game_ViewDistance = distance;
|
||||
|
||||
Event_RaiseVoid(&GfxEvents_ViewDistanceChanged);
|
||||
Game_UpdateProjection();
|
||||
}
|
||||
|
||||
bool Game_CanPick(BlockID block) {
|
||||
if (Block_Draw[block] == DrawType_Gas) return false;
|
||||
if (Block_Draw[block] == DrawType_Sprite) return true;
|
||||
|
|
|
@ -1134,7 +1134,7 @@ void BlockModel_Flush(void) {
|
|||
}
|
||||
|
||||
#define BlockModel_FlushIfNotSame if (BlockModel_lastTexIndex != BlockModel_texIndex) { BlockModel_Flush(); }
|
||||
Int32 BlockModel_GetTex(Face face) {
|
||||
TextureLoc BlockModel_GetTex(Face face) {
|
||||
TextureLoc texLoc = Block_GetTexLoc(BlockModel_block, face);
|
||||
BlockModel_texIndex = texLoc / Atlas1D_ElementsPerAtlas;
|
||||
BlockModel_FlushIfNotSame;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "Options.h"
|
||||
#include "ExtMath.h"
|
||||
#include "ErrorHandler.h"
|
||||
|
||||
UInt8 Options_KeysBuffer[String_BufferSize(26) * OPTIONS_COUNT];
|
||||
UInt8 Options_ValuesBuffer[
|
||||
|
@ -28,7 +29,7 @@ void Options_Init(void) {
|
|||
Options_InitStrs(Options_Values, OPTIONS_LARGESTRS, 512);
|
||||
}
|
||||
|
||||
Int32 Option_Find(String key) {
|
||||
Int32 Options_Find(String key) {
|
||||
Int32 i;
|
||||
for (i = 0; i < OPTIONS_COUNT; i++) {
|
||||
if (String_CaselessEquals(&Options_Keys[i], &key)) return i;
|
||||
|
@ -39,14 +40,14 @@ Int32 Option_Find(String key) {
|
|||
bool Options_TryGetValue(const UInt8* keyRaw, String* value) {
|
||||
String key = String_FromReadonly(keyRaw);
|
||||
*value = String_MakeNull();
|
||||
Int32 i = Option_Find(key);
|
||||
Int32 i = Options_Find(key);
|
||||
if (i >= 0) { *value = Options_Values[i]; return true; }
|
||||
|
||||
Int32 sepIndex = String_IndexOf(&key, '-', 0);
|
||||
if (sepIndex == -1) return false;
|
||||
|
||||
key = String_UNSAFE_SubstringAt(&key, sepIndex + 1);
|
||||
i = Option_Find(key);
|
||||
i = Options_Find(key);
|
||||
if (i >= 0) { *value = Options_Values[i]; return true; }
|
||||
return false;
|
||||
}
|
||||
|
@ -85,3 +86,49 @@ Real32 Options_GetFloat(const UInt8* key, Real32 min, Real32 max, Real32 defValu
|
|||
Math_Clamp(value, min, max);
|
||||
return value;
|
||||
}
|
||||
|
||||
void Options_Remove(Int32 i) {
|
||||
String_Clear(&Options_Keys[i]);
|
||||
String_Clear(&Options_Values[i]);
|
||||
}
|
||||
|
||||
Int32 Options_Insert(String key, String value) {
|
||||
Int32 i = Options_Find(key);
|
||||
/* The new value may not fit in the old slot, always insert into a new slot. */
|
||||
if (i >= 0) {
|
||||
Options_Remove(i);
|
||||
Options_Changed[i] = false;
|
||||
}
|
||||
|
||||
for (i = 0; i < OPTIONS_COUNT; i++) {
|
||||
if (Options_Keys[i].length > 0) continue;
|
||||
if (Options_Values[i].capacity < value.length) continue;
|
||||
|
||||
String_AppendString(&Options_Keys[i], &key);
|
||||
String_AppendString(&Options_Values[i], &value);
|
||||
return i;
|
||||
}
|
||||
|
||||
ErrorHandler_Fail("No free slot left to save option");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Options_SetInt32(const UInt8* keyRaw, Int32 value) {
|
||||
UInt8 numBuffer[String_BufferSize(STRING_INT32CHARS)];
|
||||
UInt8* ptr = numBuffer;
|
||||
String numStr = String_FromRawBuffer(ptr, STRING_INT32CHARS);
|
||||
String_AppendInt32(&numStr, value);
|
||||
Options_Set(keyRaw, numStr);
|
||||
}
|
||||
|
||||
void Options_Set(const UInt8* keyRaw, String value) {
|
||||
String key = String_FromReadonly(keyRaw);
|
||||
Int32 i;
|
||||
if (value.buffer == NULL) {
|
||||
i = Options_Find(key);
|
||||
if (i >= 0) Options_Remove(i);
|
||||
} else {
|
||||
i = Options_Insert(key, value);
|
||||
}
|
||||
if (i >= 0) Options_Changed[i] = true;
|
||||
}
|
|
@ -84,4 +84,7 @@ String Options_Get(const UInt8* key);
|
|||
Int32 Options_GetInt(const UInt8* key, Int32 min, Int32 max, Int32 defValue);
|
||||
bool Options_GetBool(const UInt8* key, bool defValue);
|
||||
Real32 Options_GetFloat(const UInt8* key, Real32 min, Real32 max, Real32 defValue);
|
||||
|
||||
void Options_SetInt32(const UInt8* keyRaw, Int32 value);
|
||||
void Options_Set(const UInt8* keyRaw, String value);
|
||||
#endif
|
|
@ -90,13 +90,11 @@ void RayTracer_Step(RayTracer* t) {
|
|||
/* tMax.X is the lowest, an YZ cell boundary plane is nearest. */
|
||||
t->X += t->step.X;
|
||||
t->tMax.X += t->tDelta.X;
|
||||
}
|
||||
else if (t->tMax.Y < t->tMax.Z) {
|
||||
} else if (t->tMax.Y < t->tMax.Z) {
|
||||
/* tMax.Y is the lowest, an XZ cell boundary plane is nearest. */
|
||||
t->Y += t->step.Y;
|
||||
t->tMax.Y += t->tDelta.Y;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* tMax.Z is the lowest, an XY cell boundary plane is nearest. */
|
||||
t->Z += t->step.Z;
|
||||
t->tMax.Z += t->tDelta.Z;
|
||||
|
@ -165,7 +163,9 @@ bool Picking_RayTrace(Vector3 origin, Vector3 dir, Real32 reach, PickedPos* pos,
|
|||
if (intersect(pos)) return true;
|
||||
RayTracer_Step(&tracer);
|
||||
}
|
||||
|
||||
ErrorHandler_Fail("Something went wrong, did over 10,000 iterations in Picking_RayTrace()");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Picking_ClipBlock(PickedPos* pos) {
|
||||
|
|
|
@ -121,7 +121,7 @@ bool String_AppendInt32(STRING_TRANSIENT String* str, Int32 num) {
|
|||
if (!String_Append(str, (UInt8)'-')) return false;
|
||||
}
|
||||
|
||||
UInt8 numBuffer[20];
|
||||
UInt8 numBuffer[STRING_INT32CHARS];
|
||||
Int32 numLen = String_MakeInt32(num, numBuffer);
|
||||
Int32 i;
|
||||
|
||||
|
@ -132,7 +132,7 @@ bool String_AppendInt32(STRING_TRANSIENT String* str, Int32 num) {
|
|||
}
|
||||
|
||||
bool String_AppendPaddedInt32(STRING_TRANSIENT String* str, Int32 num, Int32 minDigits) {
|
||||
UInt8 numBuffer[20];
|
||||
UInt8 numBuffer[STRING_INT32CHARS];
|
||||
Int32 i;
|
||||
for (i = 0; i < minDigits; i++) {
|
||||
numBuffer[i] = '0';
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
|
||||
#define String_BufferSize(n) (n + 1)
|
||||
#define STRING_INT32CHARS 20
|
||||
|
||||
typedef struct String_ {
|
||||
/* Pointer to raw characters. Size is capacity + 1, as buffer is null terminated. */
|
||||
|
|
Loading…
Add table
Reference in a new issue