Posts: 677
Threads: 69
Joined: Nov 2023
Reputation:
7
02-21-2026, 01:57 AM
(This post was last modified: 02-21-2026, 02:40 AM by johnno56.)
Thank you for the information... Now. Let's see what makes this game tick... or tick slower...
Ok. I thought I would modify the game to actually cause it to slow dow... I increased the number of stars to 1000, number of enemies to 100 and the number of bullets to 100. Asolutely no difference. No slow down at all. Eventually I could probably get it slow down if I increased the amounts to ridiculous numbers... lol Which left me to conclude that the number of active objects may not be the cause of the slow down...
Then I noticed that you are using the variable "dt" (which I assume is a reference to Delta Time?) to cause the "framerate" to behave equally based on CPU speed of the host machine... (this is a guess). I may be wrong but, N7 has the command "fwait 60" to do that very thing. This command is also in the game. My understanding of the inner workings of N7 is extremely limited, but my guess would be, having both "dt" and "fwait 60" may be causing a "timing" problem? Marcus would probably be able to correct me if I am wrong... lol
Out of curiosity, what are the specs of your machine? CPU speed, RAM etc
Logic is the beginning of wisdom.
Posts: 625
Threads: 79
Joined: Nov 2023
Reputation:
6
Is it just small "frame stutters", or does the game actually slow down and stays slow for a "long" period of time?
Posts: 625
Threads: 79
Joined: Nov 2023
Reputation:
6
02-21-2026, 07:22 AM
(This post was last modified: 02-21-2026, 07:23 AM by Marcus.)
I've actually bumped into cases where a program REALLY slows down for no obvious reason. But it was memory related; the runtime waited too long with garbage collecting and the program was running on "memory fumes". This has been fixed.
The small frame stutters, when using 'fwait' is something I'm aware of and annoyed about  And I will try to do something about it, promise.
Posts: 18
Threads: 2
Joined: Dec 2023
Reputation:
0
Thanks, it's not something with the computer, because even though it's not a rocket, I have an Nvidia 1650 card with a 10400f CPU, enough for this type of engines.
Posts: 402
Threads: 54
Joined: Nov 2023
Reputation:
3
Playing space shooter in 62-63 FPS
Code: ' =================
' SPACE SHOOTER v2
' =================
#win32
set window "Space Shooter v2", 800,600
set redraw off
randomize time()
' use sound library
include "sfx.n7"
sfx = SFX()
sfx.SetSampleRate(16000)
visible sfxHit= sfx.Noise(0.01, 500, 50)
visible sfxPower= sfx.SquareWave(0.01, 500, 0.75)
'createfont(<font name>,<bold>, <italic>, <underline>, <smooth>)
visible arial30 = createfont("arial", 30, true, false, false, true)
set font arial30
' constants
constant TARGET_DT = 0.016
constant MAX_DT = 0.1
constant MIN_DT = 0.0
' timing
visible dt = 0
visible dt_real = 0
visible time_last = 0
visible time_now = 0
visible time_fps_start = 0
visible frame_count = 0
visible fps = 0
' player
visible player = []
player.x = 0
player.y = 0
player.size = 30
player.speed = 300
player.shootCooldown = 0
' weapon
visible weapon = []
weapon.Level = 1
weapon.Timer = 0
' flame
visible flame = []
flame.Timer = 0
flame.Size = 10
' bullets
visible bullet = []
bullet.number = 200
bullet.x = []
bullet.y = []
bullet.dx = []
bullet.actif = []
bullet.size = 6
bullet.speed = 500
bullet.Offsets = [0, -150, 150, -300, 300]
' enemies
visible enemy = []
enemy.number = 500
enemy.x = []
enemy.y = []
enemy.actif = []
enemy.type = []
enemy.baseX = []
enemy.timing = []
enemy.size = 40
enemy.speed = 150
enemy.spawnTimer = 0
enemy.spawnRate = 0.8
' powerups
visible powerup = []
powerup.number = 10
powerup.x = []
powerup.y = []
powerup.actif = []
powerup.size = 20
' initialization
time_fps_start = time()
resetGame()
time_last = time()
'-----------
' MAIN LOOP
'-----------
do
' Delta Time
time_now = time()
dt_real = max(MIN_DT, min(time_now - time_last, MAX_DT))
time_last = time_now
dt = TARGET_DT
updateLogic()
updateVisuals()
' Render
set color 0,0,0; cls
set color 255,255,255
drawGame()
' FPS Counter
frame_count = frame_count + 1
fwait 60
if time_now - time_fps_start >= 1 then
fps = frame_count / (time_now - time_fps_start)
time_fps_start = time_now
frame_count = 0
endif
set caret width()-200, 10
wln "Current FPS: " + fps
redraw
until keydown(KEY_ESCAPE,true)
'------------
' FUNCTIONS
'------------
function resetGame()
player.x = width()/2 - player.size/2
player.y = height() - 60
player.shootCooldown = 0
weapon.Level = 1
weapon.Timer = 0
flame.Timer = 0
flame.Size = 10
enemy.spawnTimer = 0
' Clear
for i=0 to bullet.number-1; bullet.actif[i]=0; next
for i=0 to enemy.number-1; enemy.actif[i]=0; next
for i=0 to powerup.number-1; powerup.actif[i]=0; next
endfunc
function updateLogic()
if weapon.Timer > 0 then
weapon.Timer = weapon.Timer - dt_real*10
if weapon.Timer <= 0 then weapon.Level = 1
endif
updatePlayer()
updateBullets()
updateEnemies()
updatePowerups()
handleSpawning()
endfunc
function updateVisuals()
flame.Timer = flame.Timer + dt_real
flame.Size = 8 + sin(flame.Timer * 20) * 4 + rnd(0, 3)
endfunc
function updatePlayer()
if keydown(KEY_LEFT) or keydown(KEY_A) then
player.x = player.x - player.speed * dt
endif
if keydown(KEY_RIGHT) or keydown(KEY_D) then
player.x = player.x + player.speed * dt
endif
player.x = clamp(player.x, 0, width() - player.size)
if player.shootCooldown <= 0 then
fireBullets()
player.shootCooldown = 0.25
else
player.shootCooldown = player.shootCooldown - dt
endif
endfunc
function fireBullets()
centerX = player.x + player.size/2 - bullet.size/2
centerY = player.y
count = 1
if weapon.Level >= 2 then count = 5
for i=0 to count-1
spawnBullet(centerX, centerY, bullet.Offsets[i])
next
endfunc
function spawnBullet(x, y, dx)
for i=0 to bullet.number-1
if bullet.actif[i]=0 then
bullet.x[i] = x
bullet.y[i] = y
bullet.dx[i] = dx
bullet.actif[i] = 1
break
endif
next
endfunc
function updateBullets()
for i=0 to bullet.number-1
if bullet.actif[i]=1 then
bullet.y[i] = bullet.y[i] - bullet.speed * dt
bullet.x[i] = bullet.x[i] + bullet.dx[i] * dt
if bullet.y[i] < -bullet.size or bullet.x[i] < 0 or bullet.x[i] > width() then
bullet.actif[i] = 0
endif
endif
next
endfunc
function updateEnemies()
for i=0 to enemy.number-1
if enemy.actif[i]=1 then
enemy.timing[i] = enemy.timing[i] + dt
enemy.y[i] = enemy.y[i] + enemy.speed * dt
if enemy.type[i]=1 then
enemy.x[i] = enemy.baseX[i] + sin(enemy.timing[i]*3)*60
elseif enemy.type[i]=2 then
if player.x + player.size/2 < enemy.x[i] then
enemy.x[i] = enemy.x[i] - 100 * dt
else
enemy.x[i] = enemy.x[i] + 100 * dt
endif
endif
enemy.x[i] = clamp(enemy.x[i], 0, width() - enemy.size)
' Bullet collision
for j=0 to bullet.number-1
if bullet.actif[j]=1 then
if checkCollision(bullet.x[j],bullet.y[j],bullet.size,bullet.size,
enemy.x[i],enemy.y[i],enemy.size,enemy.size)=1 then
play sound sfxHit
bullet.actif[j]=0
enemy.actif[i]=0
spawnPowerup(enemy.x[i], enemy.y[i])
break
endif
endif
next
if enemy.y[i] > height() then
enemy.actif[i]=0
endif
endif
next
endfunc
function handleSpawning()
enemy.spawnTimer = enemy.spawnTimer - dt
if enemy.spawnTimer <= 0 then
spawnEnemy()
enemy.spawnTimer = enemy.spawnRate
endif
endfunc
function spawnEnemy()
for i=0 to enemy.number-1
if enemy.actif[i]=0 then
enemy.x[i] = rnd(0, width() - enemy.size)
enemy.y[i] = -enemy.size
enemy.actif[i] = 1
enemy.type[i] = rnd(0, 2)
enemy.baseX[i] = enemy.x[i]
enemy.timing[i] = 0
break
endif
next
endfunc
function spawnPowerup(x, y)
if rnd(0, 100) >= 20 then return
for i=0 to powerup.number-1
if powerup.actif[i]=0 then
powerup.x[i] = x
powerup.y[i] = y
powerup.actif[i] = 1
break
endif
next
endfunc
function updatePowerups()
for i=0 to powerup.number-1
if powerup.actif[i]=1 then
powerup.y[i] = powerup.y[i] + 100 * dt
if checkCollision(powerup.x[i], powerup.y[i], powerup.size, powerup.size,
player.x, player.y, player.size, player.size)=1 then
play sound sfxPower
weapon.Level = 2
weapon.Timer = 5
powerup.actif[i] = 0
endif
if powerup.y[i] > height() then powerup.actif[i] = 0
endif
next
endfunc
function drawGame()
drawBullets()
drawEnemies()
drawPowerups()
drawPlayer()
drawUI()
endfunc
function drawPlayer()
set color 0,255,0
draw rect player.x, player.y, player.size, player.size, true
drawFlame(player.x + 5)
drawFlame(player.x + player.size - 10)
endfunc
function drawFlame(fx)
set color 255,100,0
draw rect fx, player.y + player.size - 2, 5, flame.Size, true
set color 255,255,0
draw rect fx + 1, player.y + player.size - 2, 3, flame.Size - 3, true
set color 255,255,255
draw rect fx + 2, player.y + player.size - 2, 1, flame.Size - 6, true
endfunc
function drawBullets()
set color 255,255,0
for i=0 to bullet.number-1
if bullet.actif[i]=1 then
draw rect bullet.x[i], bullet.y[i], bullet.size, bullet.size, true
endif
next
endfunc
function drawEnemies()
for i=0 to enemy.number-1
if enemy.actif[i]=1 then
set color 255,50,50
draw rect enemy.x[i], enemy.y[i], enemy.size, enemy.size, true
set color 100,0,0
draw rect enemy.x[i]+5, enemy.y[i]+5, enemy.size-10, enemy.size-10, true
endif
next
endfunc
function drawPowerups()
set color 255,255,0
set font 0
for i=0 to powerup.number-1
if powerup.actif[i]=1 then
set caret powerup.x[i]-15, powerup.y[i]-20
write "POWER UP"
draw rect powerup.x[i], powerup.y[i], powerup.size, powerup.size, true
endif
next
set font arial30
endfunc
function drawUI()
set color 255,255,255
set caret 10,10
if weapon.Level >= 2 then
set color 0,255,255
write "POWER SHOT: " + str(int(weapon.Timer))
else
set color 150,150,150
write "AUTO FIRE: ON"
endif
endfunc
function clamp(v, lo, hi)
return max(lo, min(v, hi))
endfunc
function checkCollision(ax,ay,aw,ah,bx,by,bw,bh)
if ax<bx+bw and ax+aw>bx and ay<by+bh and ay+ah>by then return 1
return 0
endfunc
Posts: 625
Threads: 79
Joined: Nov 2023
Reputation:
6
Yes, fps is not really the problem. You can see stutters even when running at 120 fps. I think it's a matter of "frame pacing" (the "clock" running at lower resolution on some systems may possibly cause this) and not being able to wait for vsync. I never noticed these issues in n6 though ...
Posts: 677
Threads: 69
Joined: Nov 2023
Reputation:
7
No problems... Smooth as glass... 62-63fps... Best part... I didn't get killed off... lol
Logic is the beginning of wisdom.
Posts: 154
Threads: 11
Joined: Feb 2024
Reputation:
2
WOW
OMG... .... ....
AUTOFIRE...I LIKE IT
Posts: 115
Threads: 21
Joined: Nov 2023
Reputation:
2
I've also noticed that jump or jitter in the stars; it's very slight, but if you look closely, it's there.
It could be due to V-Sync. I don't know if Naalaa has a way to enable V-Sync.
It could also be because Naalaa doesn't have hardware acceleration and everything runs on CPU.
Another possibility is how it's programmed; it might not be configured correctly for Naalaa.
|