src/player_server.old
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
package main
import "core:fmt"
Player :: struct {
id: int,
walkForce: iFP,
walkDrag: iFP,
groundDrag: iFP,
rightward: [3]iFP,
foward: [3]iFP,
//Might Turn into a pointer of a pointer if the Heap fucks with me
kinematics: ^[dynamic]Maybe(DerivX),
clientKinematics: ^[dynamic]Maybe(DerivXFloat),
aabb: ^[dynamic]Maybe(AABB),
collision: ^[dynamic]Maybe(proc(e1: int, e2: int))
}
PlayerInit :: proc(
player: ^Player, entities: ^[dynamic]Maybe(DerivX),
clientEntities: ^[dynamic]Maybe(DerivXFloat),
aabbs: ^[dynamic]Maybe(AABB),
collision: ^[dynamic]Maybe(proc(e1: int, e2: int, delta: iFP)),
gravity: ^[dynamic]Maybe(bool)
) {
index, found := AvailableSlot()
if !found do return
player.id = index
player.foward = [3]iFP{0,0,METER}
player.kinematics = entities
player.clientKinematics = clientEntities
player.walkForce = DEFAULT_WALK_FORCE
player.groundDrag = DEFAULT_GROUND_DRAG
player.walkDrag = DEFAULT_WALK_DRAG
x := DerivX{
x = [3]iFP{0.0,FOUR_METER,0.0},
v = [3]iFP{0.0,0.0,0.0},
a = [3]iFP{0.0,0.0,0.0},
}
cx := DerivXFloat{
x = [3]f32{0.0,0.0,0.0},
v = [3]f32{0.0,0.0,0.0},
a = [3]f32{0.0,0.0,0.0},
}
bb := AABB{
solid = true,
min = [3]iFP{-Div(METER,TWO_METER),-METER,-Div(METER,TWO_METER)},
max = [3]iFP{Div(METER,TWO_METER),METER,Div(METER,TWO_METER)}
}
entities^[index] = x
clientEntities^[index] = cx
aabbs^[index] = bb
collision^[index] = RigidInelasticCollision
gravity^[index] = true
// Add Octree to funcuntion procs
AddEntityToNode(index,FindEnclosingNode(bb,x.x,&octree))
}
PlayerMove :: proc(player: ^Player, commandBuffer: ^bit_set[Command]) {
if commandBuffer^ == {} do return
kinematics, ok := player^.kinematics[player^.id].?
if !ok do return
vecLen: i64 = 0
if Command.MOVE_FOWARDS in commandBuffer^ {
kinematics.a += VecMul(player.foward,player.walkForce)
vecLen += 1
}
if Command.MOVE_BACKWARDS in commandBuffer^ {
kinematics.a -= VecMul(player.foward,player.walkForce)
vecLen += 1
}
if Command.STRAFE_LEFT in commandBuffer^ {
kinematics.a -= VecMul(player.rightward,player.walkForce)
vecLen += 1
}
if Command.STRAFE_RIGHT in commandBuffer^ {
kinematics.a += VecMul(player.rightward,player.walkForce)
vecLen += 1
}
if Command.JUMP in commandBuffer^ {
kinematics.v += VecMul(UP, FloatToInt(10.0))
fmt.println("asfhhlak")
}
if vecLen == 2 {
kinematics.a = VecDiv(kinematics.a,SQRT2)
}
player^.kinematics[player^.id] = kinematics
}
PlayerDrag :: proc(player: ^Player, commandBuffer: bit_set[Command]) {
kinematics, ok := player^.kinematics[player^.id].?
if !ok do return
kinematics.a -= VecMul(kinematics.v,player.walkDrag)
if Command.MOVE_FOWARDS not_in commandBuffer && Command.MOVE_BACKWARDS in commandBuffer {
force := VecMul( player.foward, Mul(player.groundDrag , DotProduct(kinematics.v,player.foward)) )
if DotProduct(kinematics.v,player.foward) > 0 do kinematics.a -= force
}
if Command.MOVE_BACKWARDS not_in commandBuffer && Command.MOVE_FOWARDS in commandBuffer {
force := VecMul( player.foward, Mul(player.groundDrag , DotProduct(kinematics.v,player.foward)) )
if DotProduct(kinematics.v,player.foward) < 0 do kinematics.a -= force
}
if Command.STRAFE_RIGHT not_in commandBuffer && Command.STRAFE_LEFT in commandBuffer {
force := VecMul( player.rightward, Mul(player.groundDrag , DotProduct(kinematics.v,player.rightward)) )
if DotProduct(kinematics.v,player.rightward) > 0 do kinematics.a -= force
}
if Command.STRAFE_LEFT not_in commandBuffer && Command.STRAFE_RIGHT in commandBuffer {
force := VecMul( player.rightward, Mul(player.groundDrag , DotProduct(kinematics.v,player.rightward)) )
if DotProduct(kinematics.v,player.rightward) < 0 do kinematics.a -= force
}
player^.kinematics[player^.id] = kinematics
}
PlayerAlignToCamera :: proc(camFoward: ^[3]f32, player: ^Player) {
foward := ToIntVector(camFoward^)
player^.foward = foward
player.rightward = CrossProduct(foward,UP)
}
|