diff --git a/src/Block.c b/src/Block.c index e4b06ef42..798947e3b 100644 --- a/src/Block.c +++ b/src/Block.c @@ -192,16 +192,15 @@ void Block_SetCollide(BlockID block, cc_uint8 collide) { } void Block_SetDrawType(BlockID block, cc_uint8 draw) { - Vec3 zero = Vec3_Zero(); - Vec3 one = Vec3_One(); - if (draw == DRAW_OPAQUE && Blocks.Collide[block] != COLLIDE_SOLID) draw = DRAW_TRANSPARENT; Blocks.Draw[block] = draw; Block_RecalcIsLiquid(block); + /* Whether a block is opaque and exactly occupies a cell in the world */ + /* The mesh builder module needs this information for optimisation purposes */ Blocks.FullOpaque[block] = draw == DRAW_OPAQUE - && Vec3_Equals(&Blocks.MinBB[block], &zero) - && Vec3_Equals(&Blocks.MaxBB[block], &one); + && Blocks.MinBB[block].X == 0 && Blocks.MinBB[block].Y == 0 && Blocks.MinBB[block].Z == 0 + && Blocks.MaxBB[block].X == 1 && Blocks.MaxBB[block].Y == 1 && Blocks.MaxBB[block].Z == 1; } @@ -244,12 +243,11 @@ void Block_ResetProps(BlockID block) { Blocks.Draw[block] = DefaultSet_Draw(block); if (Blocks.Draw[block] == DRAW_SPRITE) { - Blocks.MinBB[block] = Vec3_Create3(2.50f/16.0f, 0.0f, 2.50f/16.0f); - Blocks.MaxBB[block] = Vec3_Create3(13.5f/16.0f, 1.0f, 13.5f/16.0f); + Vec3_Set(Blocks.MinBB[block], 2.50f/16.0f, 0, 2.50f/16.0f); + Vec3_Set(Blocks.MaxBB[block], 13.5f/16.0f, 1, 13.5f/16.0f); } else { - Blocks.MinBB[block] = Vec3_Zero(); - Blocks.MaxBB[block] = Vec3_One(); - Blocks.MaxBB[block].Y = DefaultSet_Height(block); + Vec3_Set(Blocks.MinBB[block], 0, 0, 0); + Vec3_Set(Blocks.MaxBB[block], 1, DefaultSet_Height(block), 1); } Block_SetDrawType(block, Blocks.Draw[block]); diff --git a/src/Entity.c b/src/Entity.c index 87b6178a4..a8625e381 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -68,7 +68,7 @@ static PackedCol Entity_GetCol(struct Entity* e) { void Entity_Init(struct Entity* e) { static const String model = String_FromConst("humanoid"); - e->ModelScale = Vec3_Create1(1.0f); + Vec3_Set(e->ModelScale, 1,1,1); e->uScale = 1.0f; e->vScale = 1.0f; e->StepSize = 0.5f; @@ -118,7 +118,7 @@ static void Entity_ParseScale(struct Entity* e, const String* scale) { /* local player doesn't allow giant model scales */ /* (can't climb stairs, extremely CPU intensive collisions) */ if (e->ModelRestrictedScale) { value = min(value, e->Model->MaxScale); } - e->ModelScale = Vec3_Create1(value); + Vec3_Set(e->ModelScale, value,value,value); } static void Entity_SetBlockModel(struct Entity* e, const String* model) { @@ -136,13 +136,13 @@ static void Entity_SetBlockModel(struct Entity* e, const String* model) { void Entity_SetModel(struct Entity* e, const String* model) { String name, scale, skin; - e->ModelScale = Vec3_Create1(1.0f); + Vec3_Set(e->ModelScale, 1,1,1); String_UNSAFE_Separate(model, '|', &name, &scale); /* 'giant' model kept for backwards compatibility */ if (String_CaselessEqualsConst(&name, "giant")) { name = String_FromReadonly("humanoid"); - e->ModelScale = Vec3_Create1(2.0f); + Vec3_Set(e->ModelScale, 2,2,2); } e->ModelBlock = BLOCK_AIR; @@ -796,7 +796,10 @@ static void LocalPlayer_HandleInput(float* xMoving, float* zMoving) { hacks->FlyingDown = KeyBind_IsPressed(KEYBIND_FLY_DOWN); if (hacks->WOMStyleHacks && hacks->Enabled && hacks->CanNoclip) { - if (hacks->Noclip) p->Base.Velocity = Vec3_Zero(); + if (hacks->Noclip) { + /* need the { } because it's a macro */ + Vec3_Set(p->Base.Velocity, 0,0,0); + } hacks->Noclip = KeyBind_IsPressed(KEYBIND_NOCLIP); } } @@ -826,7 +829,7 @@ static void LocalPlayer_Tick(struct Entity* e, double delta) { /* Immediate stop in noclip mode */ if (!hacks->NoclipSlide && (hacks->Noclip && xMoving == 0 && zMoving == 0)) { - e->Velocity = Vec3_Zero(); + Vec3_Set(e->Velocity, 0,0,0); } PhysicsComp_UpdateVelocityState(&p->Physics); @@ -906,7 +909,7 @@ static void LocalPlayer_Init(void) { static void LocalPlayer_Reset(void) { struct LocalPlayer* p = &LocalPlayer_Instance; p->ReachDistance = 5.0f; - p->Base.Velocity = Vec3_Zero(); + Vec3_Set(p->Base.Velocity, 0,0,0); p->Physics.JumpVel = 0.42f; p->Physics.ServerJumpVel = 0.42f; /* p->Base.Health = 20; TODO: survival mode stuff */ @@ -914,8 +917,8 @@ static void LocalPlayer_Reset(void) { static void LocalPlayer_OnNewMap(void) { struct LocalPlayer* p = &LocalPlayer_Instance; - p->Base.Velocity = Vec3_Zero(); - p->OldVelocity = Vec3_Zero(); + Vec3_Set(p->Base.Velocity, 0,0,0); + Vec3_Set(p->OldVelocity, 0,0,0); p->_warnedRespawn = false; p->_warnedFly = false; @@ -956,7 +959,7 @@ static void LocalPlayer_DoRespawn(void) { spawn.Y += 2.0f/16.0f; LocationUpdate_MakePosAndOri(&update, spawn, p->SpawnRotY, p->SpawnHeadX, false); p->Base.VTABLE->SetLocation(&p->Base, &update, false); - p->Base.Velocity = Vec3_Zero(); + Vec3_Set(p->Base.Velocity, 0,0,0); /* Update onGround, otherwise if 'respawn' then 'space' is pressed, you still jump into the air if onGround was true before */ Entity_GetBounds(&p->Base, &bb); diff --git a/src/EntityComponents.c b/src/EntityComponents.c index 4a554ac73..e52449aa1 100644 --- a/src/EntityComponents.c +++ b/src/EntityComponents.c @@ -874,10 +874,9 @@ static void Collisions_CollideWithReachableBlocks(struct CollisionsComp* comp, i void Collisions_MoveAndWallSlide(struct CollisionsComp* comp) { struct Entity* e = comp->Entity; struct AABB entityBB, entityExtentBB; - Vec3 zero = Vec3_Zero(); int count; - if (Vec3_Equals(&e->Velocity, &zero)) return; + if (Vec3_IsZero(e->Velocity)) return; count = Searcher_FindReachableBlocks(e, &entityBB, &entityExtentBB); Collisions_CollideWithReachableBlocks(comp, count, &entityBB, &entityExtentBB); } diff --git a/src/EnvRenderer.c b/src/EnvRenderer.c index 00fdad3da..73aa4edad 100644 --- a/src/EnvRenderer.c +++ b/src/EnvRenderer.c @@ -308,7 +308,7 @@ void EnvRenderer_RenderSkybox(double deltaTime) { /* Rotate around camera */ pos = Camera.CurrentPos; - Camera.CurrentPos = Vec3_Zero(); + Vec3_Set(Camera.CurrentPos, 0,0,0); Camera.Active->GetView(&view); Matrix_MulBy(&m, &view); Camera.CurrentPos = pos; diff --git a/src/HeldBlockRenderer.c b/src/HeldBlockRenderer.c index 96a33195f..720231072 100644 --- a/src/HeldBlockRenderer.c +++ b/src/HeldBlockRenderer.c @@ -30,14 +30,14 @@ static void HeldBlockRenderer_RenderModel(void) { if (Blocks.Draw[held_block] == DRAW_GAS) { model = LocalPlayer_Instance.Base.Model; - held_entity.ModelScale = Vec3_Create1(1.0f); + Vec3_Set(held_entity.ModelScale, 1.0f,1.0f,1.0f); Gfx_SetAlphaTest(true); Model_RenderArm(model, &held_entity); Gfx_SetAlphaTest(false); } else { model = Model_Get(&block); - held_entity.ModelScale = Vec3_Create1(0.4f); + Vec3_Set(held_entity.ModelScale, 0.4f,0.4f,0.4f); Gfx_SetupAlphaState(Blocks.Draw[held_block]); Model_Render(model, &held_entity); diff --git a/src/Input.h b/src/Input.h index c35bc9430..280e958bd 100644 --- a/src/Input.h +++ b/src/Input.h @@ -70,7 +70,6 @@ void Input_SetPressed(Key key, cc_bool pressed); /* Resets all keyboard keys to released state. */ /* Raises InputEvents.Up for each previously pressed key. */ void Key_Clear(void); -typedef int MouseButton; /* Whether raw mouse/touch input is being listened for. */ extern cc_bool Input_RawMode; diff --git a/src/LScreens.c b/src/LScreens.c index f72eb7133..7ed80014e 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -117,7 +117,7 @@ static void LScreen_KeyPress(struct LScreen* s, char key) { s->selectedWidget->VTABLE->KeyPress(s->selectedWidget, key); } -static void LScreen_MouseDown(struct LScreen* s, MouseButton btn) { +static void LScreen_MouseDown(struct LScreen* s, int btn) { struct LWidget* over = LScreen_WidgetAt(s, Mouse_X, Mouse_Y); struct LWidget* prev = s->selectedWidget; @@ -125,7 +125,7 @@ static void LScreen_MouseDown(struct LScreen* s, MouseButton btn) { if (over) LScreen_SelectWidget(s, over, over == prev); } -static void LScreen_MouseUp(struct LScreen* s, MouseButton btn) { +static void LScreen_MouseUp(struct LScreen* s, int btn) { struct LWidget* over = LScreen_WidgetAt(s, Mouse_X, Mouse_Y); struct LWidget* prev = s->selectedWidget; @@ -1274,7 +1274,7 @@ static void ServersScreen_KeyDown(struct LScreen* s_, Key key, cc_bool was) { } } -static void ServersScreen_MouseUp(struct LScreen* s_, MouseButton btn) { +static void ServersScreen_MouseUp(struct LScreen* s_, int btn) { struct ServersScreen* s = (struct ServersScreen*)s_; s->table.VTABLE->OnUnselect(&s->table); LScreen_MouseUp(s_, btn); diff --git a/src/LScreens.h b/src/LScreens.h index 3f29eaae3..d41510db7 100644 --- a/src/LScreens.h +++ b/src/LScreens.h @@ -19,8 +19,8 @@ typedef void (*LWidget_Func)(struct LScreen* s, struct LWidget* w); LScreen_Func OnDisplay; /* Called when framebuffer is about to be displayed. */ \ void (*KeyDown)(struct LScreen* s, Key key, cc_bool wasDown); \ void (*KeyPress)(struct LScreen* s, char c); \ - void (*MouseDown)(struct LScreen* s, MouseButton btn); \ - void (*MouseUp)(struct LScreen* s, MouseButton btn); \ + void (*MouseDown)(struct LScreen* s, int btn); \ + void (*MouseUp)(struct LScreen* s, int btn); \ void (*MouseMove)(struct LScreen* s, int deltaX, int deltaY); \ void (*MouseWheel)(struct LScreen* s, float delta); \ LWidget_Func HoverWidget; /* Called when mouse is moved over a given widget. */ \ diff --git a/src/Model.c b/src/Model.c index 33370e064..82cf3eb60 100644 --- a/src/Model.c +++ b/src/Model.c @@ -39,9 +39,9 @@ void Model_Init(struct Model* model) { model->UsesHumanSkin = false; model->Pushes = true; - model->Gravity = 0.08f; - model->Drag = Vec3_Create3(0.91f, 0.98f, 0.91f); - model->GroundFriction = Vec3_Create3(0.6f, 1.0f, 0.6f); + model->Gravity = 0.08f; + Vec3_Set(model->Drag, 0.91f, 0.98f, 0.91f); + Vec3_Set(model->GroundFriction, 0.6f, 1.0f, 0.6f); model->MaxScale = 2.0f; model->ShadowScale = 1.0f; diff --git a/src/Particle.c b/src/Particle.c index 9af644c5b..2d073ad50 100644 --- a/src/Particle.c +++ b/src/Particle.c @@ -73,8 +73,10 @@ static cc_bool Particle_TestY(struct Particle* p, int y, cc_bool topFace, cc_boo cc_bool collideVer; if (y < 0) { - p->nextPos.Y = ENTITY_ADJUSTMENT; p->lastPos.Y = ENTITY_ADJUSTMENT; - p->velocity = Vec3_Zero(); + p->nextPos.Y = ENTITY_ADJUSTMENT; + p->lastPos.Y = ENTITY_ADJUSTMENT; + + Vec3_Set(p->velocity, 0,0,0); particle_hitTerrain = true; return false; } @@ -90,7 +92,8 @@ static cc_bool Particle_TestY(struct Particle* p, int y, cc_bool topFace, cc_boo float adjust = topFace ? ENTITY_ADJUSTMENT : -ENTITY_ADJUSTMENT; p->lastPos.Y = collideY + adjust; p->nextPos.Y = p->lastPos.Y; - p->velocity = Vec3_Zero(); + + Vec3_Set(p->velocity, 0,0,0); particle_hitTerrain = true; return false; } diff --git a/src/Vectors.h b/src/Vectors.h index 3f6f06eb7..105917256 100644 --- a/src/Vectors.h +++ b/src/Vectors.h @@ -21,14 +21,6 @@ struct Matrix { struct Vec4 Row0, Row1, Row2, Row3; }; /* Identity matrix. (A * Identity = A) */ extern const struct Matrix Matrix_Identity; -/* Returns a vector with all components 0. */ -static CC_INLINE Vec3 Vec3_Zero(void) { - Vec3 v = { 0, 0, 0 }; return v; -} -/* Returns a vector with all components 1. */ -static CC_INLINE Vec3 Vec3_One(void) { - Vec3 v = { 1, 1, 1 }; return v; -} /* Returns a vector with all components set to Int32_MaxValue. */ static CC_INLINE IVec3 IVec3_MaxValue(void) { IVec3 v = { Int32_MaxValue, Int32_MaxValue, Int32_MaxValue }; return v; @@ -37,13 +29,15 @@ static CC_INLINE Vec3 Vec3_BigPos(void) { Vec3 v = { 1e25f, 1e25f, 1e25f }; return v; } -static CC_INLINE Vec3 Vec3_Create1(float value) { - Vec3 v; v.X = value; v.Y = value; v.Z = value; return v; -} static CC_INLINE Vec3 Vec3_Create3(float x, float y, float z) { Vec3 v; v.X = x; v.Y = y; v.Z = z; return v; } +/* Sets the X, Y, and Z components of a 3D vector */ +#define Vec3_Set(v, x, y, z) (v).X = x; (v).Y = y; (v).Z = z; +/* Whether all components of a 3D vector are 0 */ +#define Vec3_IsZero(v) ((v).X == 0 && (v).Y == 0 && (v).Z == 0) + /* Returns the squared length of the vector. */ /* Squared length can be used for comparison, to avoid a costly sqrt() */ /* However, you must sqrt() this when adding lengths. */