added updated m4, debugging

This commit is contained in:
FatalErr42O 2023-12-17 23:25:44 -08:00
parent 181d228a16
commit 8c9afdd44b
9 changed files with 53 additions and 29 deletions

View File

@ -33,7 +33,7 @@ function controls:update(dt)
self.player_pressed = self.player:get_player_control()
local pressed = self.player_pressed
local call_queue = {} --so I need to have a "call" queue so I can tell the functions the names of other active controls (busy_list)
local busy_list = self.busy_list --list of controls that have their conditions met. Has to be reset at END of update, so on_use and on_secondary_use can be marked
local busy_list = self.busy_list or {} --list of controls that have their conditions met. Has to be reset at END of update, so on_use and on_secondary_use can be marked
for i, control in pairs(self.controls) do
if not (i=="on_use") and not (i=="on_secondary_use") then
local def = control
@ -44,6 +44,7 @@ function controls:update(dt)
if not pressed[key] then conditions_met = false break end
end
if conditions_met then
busy_list[i] = true
data.timer = data.timer - dt
--when time is over, if it wasnt held (or loop is active) then reset and call the function.
--held indicates wether the function was called (as active) before last step.
@ -54,7 +55,6 @@ function controls:update(dt)
table.insert(call_queue, {control=def, active=false, interrupt=false, data=data})
end
else
busy_list[i] = true
data.held = false
--detect interrupts, check if the timer was in progress
if data.timer ~= def.timer then
@ -64,10 +64,8 @@ function controls:update(dt)
end
end
end
--busy list is so we can tell if a function should be allowed or not
if #busy_list == 0 then busy_list = nil end
for i, tbl in pairs(call_queue) do
tbl.control.func(tbl.active, tbl.interrupt, tbl.data, busy_list, self.handler)
tbl.control.func(tbl.active, tbl.interrupt, tbl.data, busy_list, self.handler.gun, self.handler)
end
self.busy_list = {}
end

View File

@ -18,6 +18,11 @@ local gun_default = {
horizontal_offset = 0,
aim_time = 1,
},
firemodes = {
"single", --not limited to semi-automatic.
"auto",
"burst"
},
recoil = { --used by update_recoil()
velocity_correction_factor = { --velocity correction factor is currently very broken.
gun_axial = 1,
@ -74,9 +79,10 @@ local gun_default = {
controls = { --used by control_handler
__overfill=true, --if present, this table will not be filled in.
aim = Guns4d.default_controls.aim,
fire = Guns4d.default_controls.fire,
auto = Guns4d.default_controls.auto,
reload = Guns4d.default_controls.reload,
on_use = Guns4d.default_controls.on_use
on_use = Guns4d.default_controls.on_use,
firemode = Guns4d.default_controls.firemode
},
reload = { --used by defualt controls. Still provides usefulness elsewhere.
__overfill=true, --if present, this table will not be filled in.
@ -90,6 +96,7 @@ local gun_default = {
},
visuals = {
--mesh
backface_culling = true,
root = "gun",
arm_right = "right_aimpoint",
arm_left = "left_aimpoint",
@ -127,10 +134,10 @@ local gun_default = {
spread = {
},
total_offset_rotation = { --can't be in offsets, as they're added automatically.
--[[total_offset_rotation = { --can't be in offsets, as they're added automatically.
gun_axial = Vec.new(),
player_axial = Vec.new(),
},
},]]
player_rotation = Vec.new(),
velocities = {
recoil = {
@ -174,6 +181,7 @@ local gun_default = {
]]
},
particle_spawners = {},
current_firemode = 1,
walking_tick = 0,
time_since_last_fire = 0,
time_since_creation = 0,
@ -247,6 +255,10 @@ function gun_default:update(dt)
end
end
function gun_default:cycle_firemodes()
self.current_firemode = (self.current_firemode+1)%(#self.properties.firemodes)
minetest.chat_send_all(self.properties.firemodes[self.current_firemode+1])
end
function gun_default:attempt_fire()
assert(self.instance, "attempt to call object method on a class")
if self.rechamber_time <= 0 then
@ -512,10 +524,10 @@ function gun_default:update_animation(dt)
if data.loop and (data.current_frame > data.frames.y) then
data.current_frame = data.frames.x
end
--track rotations
--track rotations and applies to aim.
if self.consts.ANIMATIONS_OFFSET_AIM then self:update_animation_rotation() end
end
--IMPORTANT!!! this does not directly modify the animation_data table, it's all hooked through ObjRef:set_animation() (init.lua) so if animation is set elsewhere it doesnt break.
--IMPORTANT!!! this does not directly modify the animation_data table anymore, it's all hooked through ObjRef:set_animation() (init.lua) so if animation is set elsewhere it doesnt break.
--this may be deprecated in the future- as it is no longer really needed now that I hook ObjRef functions.
function gun_default:set_animation(frames, length, fps, loop)
loop = loop or false --why the fuck default is true? I DONT FUCKIN KNOW (this undoes this)
@ -527,7 +539,7 @@ function gun_default:set_animation(frames, length, fps, loop)
elseif not fps then
fps = self.consts.DEFAULT_FPS
end
self.entity:set_animation(frames, fps, 0, loop)
self.entity:set_animation(frames, fps, 0, loop) --see init.lua for modified ObjRef stuff.
end
function gun_default:clear_animation()
local loaded = false
@ -538,7 +550,6 @@ function gun_default:clear_animation()
elseif self.ammo_handler.ammo.total_bullets > 0 then
loaded = true
end
local data = self.animation_data
if loaded then
self.entity:set_animation({x=self.properties.visuals.animations.loaded.x, y=self.properties.visuals.animations.loaded.y}, 0, 0, self.consts.LOOP_IDLE_ANIM)
else
@ -608,8 +619,6 @@ function gun_default:update_animation_rotation()
out = vector.new()
end
self.animation_rotation = out
--minetest.chat_send_all(dump(out))
--minetest.chat_send_all(self.animation_data.current_frame)
end
--relative to the gun's entity. Returns left, right vectors.
@ -689,7 +698,11 @@ gun_default.construct = function(def)
def.properties = table.fill(def.base_class.properties, def.properties)
def.particle_spawners = {} --Instantiatable_class only shallow copies. So tables will not change, and thus some need to be initialized.
def.property_modifiers = {}
def.total_offset_rotation = {
gun_axial = Vec.new(),
player_axial = Vec.new(),
}
def.player_rotation = Vec.new()
--initialize all offsets
--def.offsets = table.deep_copy(def.base_class.offsets)
def.offsets = {}
@ -836,6 +849,7 @@ gun_default.construct = function(def)
glow = 0,
pointable = false,
static_save = false,
backface_culling = props.visuals.backface_culling
},
on_step = function(self, dtime)
local obj = self.object

View File

@ -26,7 +26,6 @@ function player_handler:update(dt)
--was there a gun last time? did the wield index change?
local old_index = self.wield_index
self.wield_index = player:get_wield_index()
--initialize all handlers and objects
if (not self.gun) or (self.gun.id ~= self.wielded_item:get_meta():get_string("guns4d_id")) then
--initialize important player data

View File

@ -5,19 +5,29 @@ Guns4d.default_controls.aim = {
conditions = {"RMB"},
loop = false,
timer = 0,
func = function(active, interrupted, data, busy_list, handler)
func = function(active, interrupted, data, busy_list, gun, handler)
if active then
handler.control_bools.ads = not handler.control_bools.ads
end
end
}
Guns4d.default_controls.fire = {
Guns4d.default_controls.auto = {
conditions = {"LMB"},
loop = true,
timer = 0,
func = function(active, interrupted, data, busy_list, handler)
if not handler.control_handler.busy_list.on_use then
handler.gun:attempt_fire()
func = function(active, interrupted, data, busy_list, gun, handler)
if gun.properties.firemodes[gun.current_firemode+1] == "auto" then
gun:attempt_fire()
end
end
}
Guns4d.default_controls.firemode = {
conditions = {"sneak", "zoom"},
loop = false,
timer = .5,
func = function(active, interrupted, data, busy_list, gun, handler)
if not (busy_list.on_use or busy_list.auto) then
gun:cycle_firemodes()
end
end
}
@ -25,11 +35,10 @@ Guns4d.default_controls.reload = {
conditions = {"zoom"},
loop = false,
timer = 0, --1 so we have a call to initialize the timer.
func = function(active, interrupted, data, busy_list, handler)
local gun = handler.gun
func = function(active, interrupted, data, busy_list, gun, handler)
local ammo_handler = gun.ammo_handler
local props = gun.properties
if active then
if active and not busy_list.firemode then
if not data.state then
data.state = 0
end
@ -174,5 +183,5 @@ Guns4d.default_controls.reload = {
}
Guns4d.default_controls.on_use = function(itemstack, handler, pointed_thing)
handler.gun:attempt_fire()
handler.control_handler.busy_list.on_use = true
--handler.control_handler.busy_list.on_use = true
end

View File

@ -76,10 +76,14 @@ minetest.register_on_joinplayer(function(player)
end
--so... minetest is stupid, and so it won't let me set something to the same animation twice (utterly fucking brilliant).
--This means I literally need to flip flop between +1 frames
frame_range = (frame_range and table.copy(frame_range)) or {x=1,y=1}
frame_range = table.copy(frame_range)
minetest.chat_send_all(dump(frame_range))
if data.frames.x == frame_range.x and data.frames.y == frame_range.y then
frame_range.y = frame_range.y + 1 --oh yeah, and it only accepts whole frames... because of course.
--oh yeah, and it only accepts whole frames... because of course.
frame_range.x = frame_range.x+1
minetest.chat_send_all("+1")
end
minetest.chat_send_all(dump(frame_range))
data.frames = frame_range
data.current_frame = data.frames.x
end

View File

@ -262,7 +262,7 @@ function table.shallow_copy(t)
end
--for the following code and functions only:
--for license see the link on the next line.
--for license see the link on the next line (direct permission was granted).
--https://github.com/3dreamengine/3DreamEngine
function Point_to_hud(pos, fov, aspect)
local n = .1 --near

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB