Slowdown on different plattforms (SOLVED)

Since my other issue were (partially) solved so quickly by you guys, i have yet another mystery for you.

I’m developing on a linux computer using the 64-bit editor. The project is working as intended on this setup. However, when i swap to my PC at home (running 64-bit windows and the windows editor) the game is significantly slower. As in roughly a third of the speed.
The same thing happens if i compile to HTML on my Linux (that runs the game perfectly normally).
No settings are changed between the runs.
What could cause this issue?

I would start by checking the profiler. Could it be that your Linux machine has more power and is able to churn out 60 fps while your Windows machine and browser isn’t able to keep up?

My Linux machine (being a laptop) is significantly slower then my Windows machine. The profiler doesn’t show any kind of congestion issues.
Another rather interesting effect effect of the issue is that the script controlling my character (that i made work with my last topic…) seems to break as well. In a rather interesting way…
I am able to do about half of my actions, but moving right does not work.
Most of the things that seem to malfunction are numerical calculations, is it possible that the 64-bit editor just simply doesn’t translate well when compiled with 32-bit?

No, there is no difference in compilation. If you experience behavioral differences it’s likely some errors in your script(s) that somehow manifest themselves differently on the platforms. It would be very interesting to run some tests ourselves. Do you have a minimal example that you can post?

The entirety of the script controlling my character (mostly based on the tutorialscript):
If there is indeed an error in a script that is causing this, it should be in there.
The game itself is also rather minimal, as i’ve just started out. It would be hard to post it though.


local move_acceleration = 5
local air_acceleration_factor = 0.8
local max_speed = 15
local gravity = -7
local jump_takeoff_speed = 50


-- pre-hashing ids improves performance
local msg_contact_point_response = hash("contact_point_response")
local msg_animation_done = hash("animation_done")
local group_Ground = hash("Ground")
local group_Walls = hash("Walls")
local group_Breakable = hash("Breakable")
local input_left = hash("Left")
local input_right = hash("Right")
local input_jump = hash("Jump")
local input_rush = hash("Rush")
local input_glide = hash("Glide")
local animation_done_message = hash("animation_done")


function init(self)
    msg.post(".", "acquire_input_focus")
    self.velocity = vmath.vector3(0, 0, 0)
    self.correction = vmath.vector3()
    self.ground_contact = false
    self.move_input = 0
    self.anim = nil
    self.hit_roof = false
    self.face_left = false
    self.rushing = false
    self.gliding = false
    self.animating = false
    print("finished init")
end

function update(self, dt)
	if self.face_left then
		sprite.set_hflip("#sprite", true)
	else
		sprite.set_hflip("#sprite",false)
	end
	msg.post("camera","look_at",{ position = go.get_position()})
    local target_speed = self.move_input * max_speed
    local speed_diff = target_speed - self.velocity.x
    local acceleration = vmath.vector3(0, gravity, 0)
    if self.gliding and self.velocity.y <= 0  then
    	acceleration.y = acceleration.y/9
    end
    if speed_diff ~= 0 then
        if speed_diff < 0 then
            acceleration.x = -move_acceleration
        else
            acceleration.x = move_acceleration
        end
        if not self.ground_contact then
            acceleration.x = air_acceleration_factor * acceleration.x
        end
    end
    local dv = acceleration * dt
    if math.abs(dv.x) > math.abs(speed_diff) then
        dv.x = speed_diff
    end
    local v0 = self.velocity
    self.velocity = self.velocity + dv
    if self.rushing then
    	if self.face_left then
    		self.velocity.x = -max_speed-10
    	else
    		self.velocity.x = max_speed+10
    	end
    end
    local dp = (v0 + self.velocity) * dt * 0.5
    go.set_position(go.get_position() + dp)
    self.correction = vmath.vector3()
    self.move_input = 0
  	if self.gliding and not self.ground_contact then
   		msg.post("#sprite","play_animation",{id = hash("Gliding")})
  	elseif self.rushing then
  		msg.post("#sprite","play_animation",{id = hash("Rushing")})
  	else
  		local moving = not (self.velocity.x == 0) and not (self.gliding or self.rushing)

    	if moving and not self.animating then
   			msg.post("#sprite", "play_animation", {id = hash("Running")})
   			self.animating = true
   		elseif not moving and not self.animating then
   			msg.post("#sprite","play_animation", {id = hash("Idle")})
   		end
 	end	
 	self.ground_contact = false
end

local function handle_obstacle_contact(self, normal, distance)
    local proj = vmath.dot(self.correction, normal)
    local comp = (distance - proj) * normal
    self.correction = self.correction + comp
    go.set_position(go.get_position() + comp)
    if normal.y > 0.7 then
        self.ground_contact = true
        self.gliding = false
    end
        proj = vmath.dot(self.velocity, normal)
    if proj < 0 then
       self.velocity = self.velocity - proj * normal
    end
end

function on_message(self, message_id, message, sender)
    if message_id == msg_contact_point_response then
        if message.group == group_Ground or message.group == group_Walls then
            handle_obstacle_contact(self, message.normal, message.distance)
        elseif message.group == group_Breakable then
        	if self.rushing then
        		msg.post(message.other_id,"destroy_self")
        	else 
        		handle_obstacle_contact(self, message.normal, message.distance)
        	end
    	end
	end
	if message_id == animation_done_message then
		self.animating = false
	end
end

local function jump(self)
    if self.ground_contact then
        self.velocity.y = jump_takeoff_speed
    end
end

local function abort_jump(self)
    if self.velocity.y > 0 then
        self.velocity.y = self.velocity.y * 0.5
    end
end

function on_input(self, action_id, action)
    if action_id == input_left then
        self.move_input = -action.value
        self.face_left = true
        self.rushing = false
    elseif action_id == input_right then
        self.move_input = action.value
        self.face_left = false
        self.rushing = false
    elseif action_id == input_jump then
        if action.pressed then
            jump(self)
        elseif action.released then
            abort_jump(self)
        end
    elseif action_id == input_rush then
    	self.rushing = true
    elseif action_id == input_glide then
    	if not self.ground_contact and action.pressed then
    		self.gliding = not self.gliding
    	end
    end
end

if you would like the entirety of the game to do tests, i’ll happily provide it in any form that would be suitable.

You can add me (bjorn.ritzl@king.com) and Mikael (mikael.saker@king.com) as team members from the dashboard. Once we’re added we will be able to access the project and do some tests. Don’t forget to sync your project!

There, I have added you.

Thanks,

Looking at the project it’s a bit hard to see how it’s supposed to play. I had to multiply all constants (acceleration, speeds etc) by 100 to get the character moving reasonably. Do you have unsynched stuff on your machine.

No, i’ve synced everything. And that is the problem. Playing the same game with the same code on my Linux distro runs at a “normal” speed, but i experience the same thing as you do when i swap to another machine or use the HTML-build.

But you have a max speed of 15 IIRC and that’s like half a tile per second. Isn’t that very slow? A much more reasonable speed for a platformer would, with the size and scale of your game, be ~100 pixels per second or something like that.

But increasing that number makes the game incredibly quick on my Linux distro, which is what i mainly develop on.

Ah, then there might be a problem with the vsync.

If you print dt in update:

function update(self, dt)
    print(dt)
    ....

What value do you get?

1 Like

Here’s a discussion around too fast update speeds: Why is the update speed too fast? (DEF-1785) (SOLVED)

1 Like

I get 0.016666667535901 when i print dt.
I think i have found a solution though. Setting the “variable dt” setting in project slowed my game down to about the speed that the Windows setup runs it on. I should have tried that earlier (in fact, i am fairly certain i did).
The “missing functionality” of the html part was due to me running a vim enhancement for my browser, rebinding the movement keys to other stuff.

Thank you for the help!

3 Likes

Ok, great! I’m happy to hear that you figured it out!