mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 03:06:55 -04:00
Define itemdrop gravity in the file and make itemdrops less floaty.
This commit is contained in:
parent
59fdd1321e
commit
2f801c07f4
@ -639,7 +639,6 @@ pub const World = struct { // MARK: World
|
||||
manager: *ConnectionManager,
|
||||
ambientLight: f32 = 0,
|
||||
clearColor: Vec4f = Vec4f{0, 0, 0, 1},
|
||||
gravity: f64 = 9.81*1.5, // TODO: Balance
|
||||
name: []const u8,
|
||||
milliTime: i64,
|
||||
gameTime: Atomic(i64) = .init(0),
|
||||
@ -658,7 +657,7 @@ pub const World = struct { // MARK: World
|
||||
.milliTime = std.time.milliTimestamp(),
|
||||
};
|
||||
|
||||
self.itemDrops.init(main.globalAllocator, self);
|
||||
self.itemDrops.init(main.globalAllocator);
|
||||
network.Protocols.handShake.clientSide(self.conn, settings.playerName);
|
||||
|
||||
main.Window.setMouseGrabbed(true);
|
||||
|
@ -43,7 +43,8 @@ pub const ItemDropManager = struct { // MARK: ItemDropManager
|
||||
|
||||
pub const pickupRange: f64 = 1.0;
|
||||
|
||||
const maxSpeed = 10;
|
||||
const terminalVelocity = 40.0;
|
||||
const gravity = 9.81;
|
||||
|
||||
const maxCapacity = 65536;
|
||||
|
||||
@ -59,20 +60,18 @@ pub const ItemDropManager = struct { // MARK: ItemDropManager
|
||||
changeQueue: main.utils.ConcurrentQueue(union(enum) {add: struct {u16, ItemDrop}, remove: u16}),
|
||||
|
||||
world: ?*ServerWorld,
|
||||
gravity: f64,
|
||||
airDragFactor: f64,
|
||||
|
||||
size: u32 = 0,
|
||||
|
||||
pub fn init(self: *ItemDropManager, allocator: NeverFailingAllocator, world: ?*ServerWorld, gravity: f64) void {
|
||||
pub fn init(self: *ItemDropManager, allocator: NeverFailingAllocator, world: ?*ServerWorld) void {
|
||||
self.* = ItemDropManager{
|
||||
.allocator = allocator,
|
||||
.list = std.MultiArrayList(ItemDrop){},
|
||||
.isEmpty = .initFull(),
|
||||
.changeQueue = .init(allocator, 16),
|
||||
.world = world,
|
||||
.gravity = gravity,
|
||||
.airDragFactor = gravity/maxSpeed,
|
||||
.airDragFactor = gravity/terminalVelocity,
|
||||
};
|
||||
self.list.resize(self.allocator.allocator, maxCapacity) catch unreachable;
|
||||
}
|
||||
@ -329,7 +328,7 @@ pub const ItemDropManager = struct { // MARK: ItemDropManager
|
||||
self.fixStuckInBlock(chunk, pos, vel, deltaTime);
|
||||
return;
|
||||
}
|
||||
vel.* += Vec3d{0, 0, -self.gravity*deltaTime};
|
||||
vel.* += Vec3d{0, 0, -gravity*deltaTime};
|
||||
inline for(0..3) |i| {
|
||||
const move = vel.*[i]*deltaTime; // + acceleration[i]*deltaTime;
|
||||
if(main.game.collision.collides(.server, @enumFromInt(i), move, pos.*, hitBox)) |box| {
|
||||
@ -443,14 +442,14 @@ pub const ClientItemDropManager = struct { // MARK: ClientItemDropManager
|
||||
|
||||
var mutex: std.Thread.Mutex = .{};
|
||||
|
||||
pub fn init(self: *ClientItemDropManager, allocator: NeverFailingAllocator, world: *World) void {
|
||||
pub fn init(self: *ClientItemDropManager, allocator: NeverFailingAllocator) void {
|
||||
std.debug.assert(instance == null); // Only one instance allowed.
|
||||
instance = self;
|
||||
self.* = .{
|
||||
.super = undefined,
|
||||
.lastTime = @as(i16, @truncate(std.time.milliTimestamp())) -% settings.entityLookback,
|
||||
};
|
||||
self.super.init(allocator, null, world.gravity);
|
||||
self.super.init(allocator, null);
|
||||
self.interpolation.init(
|
||||
@ptrCast(self.super.list.items(.pos).ptr),
|
||||
@ptrCast(self.super.list.items(.vel).ptr),
|
||||
|
@ -412,7 +412,6 @@ const WorldIO = struct { // MARK: WorldIO
|
||||
|
||||
pub const ServerWorld = struct { // MARK: ServerWorld
|
||||
pub const dayCycle: u31 = 12000; // Length of one in-game day in units of 100ms. Midnight is at DAY_CYCLE/2. Sunrise and sunset each take about 1/16 of the day. Currently set to 20 minutes
|
||||
pub const earthGravity: f32 = 9.81;
|
||||
|
||||
itemDropManager: ItemDropManager = undefined,
|
||||
blockPalette: *main.assets.Palette = undefined,
|
||||
@ -426,7 +425,6 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
||||
lastUpdateTime: i64,
|
||||
lastUnimportantDataSent: i64,
|
||||
doGameTimeCycle: bool = true,
|
||||
gravity: f32 = earthGravity,
|
||||
|
||||
defaultGamemode: main.game.Gamemode = undefined,
|
||||
allowCheats: bool = undefined,
|
||||
@ -494,7 +492,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
||||
.chunkUpdateQueue = .init(main.globalAllocator, 256),
|
||||
.regionUpdateQueue = .init(main.globalAllocator, 256),
|
||||
};
|
||||
self.itemDropManager.init(main.globalAllocator, self, self.gravity);
|
||||
self.itemDropManager.init(main.globalAllocator, self);
|
||||
errdefer self.itemDropManager.deinit();
|
||||
|
||||
var loadArena = main.heap.NeverFailingArenaAllocator.init(main.stackAllocator);
|
||||
|
Loading…
x
Reference in New Issue
Block a user