I've been using LOVE for quite a few years now but i've never quite got into the community as i have never been an active member on forums and for some reason i avoid trying to get help on them, I usually just search for other people's issues and responses and it has been great until several days ago.
I aspire to be a programmer, Game dev being the prefered field i'd say.
So i will initiate the problem with an example, and a few questions for which i'd like to explore new answers.
(I'd also want to start by saying that my english may not be trusted as it isn't my home language and I find it hard to judge myself on any aspect. Ask me directly if you don't understand some expression I may type so that i can try to use another word.)
It begins with the following concepts: An Object class, a World Table, and a Loaded World table
Code: Select all
-- I initialize by creating a world composed by XX by YY chunks, each with 16 by 16 tiles.
local chunk = 16
local XX, YY = 10, 10 -- I intend to set how many chunks in each axis i want to exist in the world
local world = {}
local loadedMap = {}
for i=1,xx do
world[i] = {} -- Here i set the table on chunk XX to contain the chunks YY in
for j=1,yy do
world[i][j] = {}
for x=1,chunk do
world[i][j][x] = {} -- here i start the tile's table for the X axis
for y=1,chunk do
world[i][j][x][y] = {} -- Y axis.
for z=1,2 do -- i intend to add more layers later
world[i][j][x][y][z] = {
{type = 'surface', tbl = {...} } -- Setting a table inside Z's table to represent one initial object, there shall be more objects inside this same dimensions. This initial object is the Surface object, tbl contains everything that individualizes this particular surface tile, like the XX,YY,X,Y,Z position in the world so it can be updated and drawn as an instance.
}
end
end
end
end
end
-- Everything above ,in theory, and in practice did work well and does the job pretty great, simply creating the whole world filled with equal Surface instances on their rightful positions which will then pass the variables needed to create the object through the ...[z][1]['tbl'] var.
-- I will now load the map by actually creating the instances
for xx,v in ipairs(world) do
for yy,v in ipairs(world[xx]) do
for x,v in ipairs(world[xx][yy] do
for y,v in ipairs(world[xx][yy][x]) do
for z,v in ipairs(world[xx][yy][x][y]) do
for k,v in ipairs(world[xx][yy][x][y][z]) do
if v.type = 'surface' then
loadedMap[#loadedMap +1] = ObjSurface:new(v.tbl) --Creates the instance with the customized variables inside v.tbl
loadedMap[#loadedMap]:init() -- Initiates the instance to perform some calculations before it can 'exist'
end
end
end
end
end
end
end
-- Nothing wrong in here either as it works like how it should.
-- First creates the world, with chunks so i can better control which tiles should be on the loadedMap later.
-- I also did this so i could save the world with the Binser lib as i can't save directly instances because i cant seem to load them after...
function love.update(dt)
--updates each instance
for k,v in ipairs(loadedMap) do
v:update()
end
end
function love.draw()
--draws each instance
for k,v in ipairs(loadedMap) do
v:draw()
end
end
I did not, however, intend to have such a low Frame rate with such a basic world grid. It is isometric and it is supposed to be a very customized world with construction and destruction but a simple tile filled world is so slow..
I managed to improve a bit by only having the objects drawn if they are near the player (anywhere the player would be, only 9 chunks would be drawn, the chunk where the player is obviously, and the 8 chunks around it.)
But still having less rendered stuff, it would only improve frame rate to around a mere 25 fps while it isnt affected by frame limiters on my mid-end gaming computer and pointless 5 fps on my Hybrid ideapad, which for its complexity and size should still have a typical frame rate of 60.
What i'm asking here is how can use my objects to have individual update cycles and still have a proper frame rate.
It looks as it takes too long drawing cause it is iterating through many objects.
In the objSurface:draw() itself, it is pretty optimized already, it simply backups current color, sets a new one, and draws a polygon based on self.points which is set only once on objSurface:init() and stays constant on that tile.
I also want to have different objects capable of interaction with the world's objects either by collision or telepathy(lol) with different draw and update states, but since i can't seem to even have just a couple of them, completly static, to lag out the whole game, it gets difficult.
I don't see spritebatch as an option and Canvases is quite nasty to update every second it might as well do worse.
I would post original code but It isn't at the state i above tried to replicate as i am currently exploring different stuff and i just currently gave up using love.thread as i can't pass objects through and i had an emotional breakdown around this issues ahah.
Thank you so much in advance for following down this, there are probably many ways to do this exactly but I for the first time hit the state where I can't find what i'm looking for.