Ya got me curious
[note: This demo is just a rough idea]
I went and modified the Dark A.I.'s Teams Demo. With Around 100 objects on screen fighting it out, I can get around 60fps. Ofcoarse, I have yet to look into any optimizations if there is any for this example.
The code I have below, I have 3 variables at top: enemy, friendly, neutral. Each var designed to be in the range of 1 and 200.
with 100 players and 3 neuts, my fps starts in the mid 80's. When they start shooting each other, it gets down to the mid 60's (I did run this code once and the FPS was hung around 24 for some reason ). When I get the friendly dudes to follow me, it drops down in the mid 40's. When I make them stop following me, the FPS slowly starts rising back to around 60 FPS.
If I make where there is around 200 objects on screen, My FPS jumps down around 15 FPS.
modded Teams Demo code:
remstart
*
* Teams
*
* -Creates 3 teams (friendly(green), enemy(red) and neutral(white))
* -Neutrals will run away from combat, friendlies will defend you, enemies will attack you
* -Sounds are enabled in this demo when an entity fires and will trigger nearby entities
*
* -Compiled with Version 6.1
*
remend
enemy = 50
friendly = 49
neutral = 3
sync on : sync rate 0 : autocam off
set text font "Verdana" : set text size 14
rem creates the AI system and sets everything to default.
AI Start
rem sets the global radius, all entities will assumed to be this size
AI Set Radius 2.5
MakeBackground()
MakeLevel()
dim shootTimer(100000) as float
rem make a patrol path
AI Make Path 1
AI Path Add Point 1,40,40
AI Path Add Point 1,-40,40
rem entity template
make object cone 1,5
xrotate object 1,90
fix object pivot 1
make mesh from object 1,1
delete object 1
rem attack template
make object plain 1,0.3,1,1
xrotate object 1,90
fix object pivot 1
make mesh from object 2,1
delete object 1
rem single color images
MakeColorImage(11,1,rgb(255,0,0))
MakeColorImage(12,1,rgb(0,255,0))
rem make 3 enemies
for i = 101 to (100+enemy)
make object i,1,0
position object i,rnd(50)-25,2.5,40
texture object i,11
make object i+1000,2,11
set object light i+1000,0
hide object i+1000
rem add them to the enemy team and set their speed (in units per second)
AI Add Enemy i
AI Set Entity Speed i,10.0
AI Set Entity Aggressive i
AI Set Entity View Arc i,90,180
AI Set Entity View Range i,60
AI Set Entity Hearing Range i,100
AI Entity Assign Patrol Path i,1
next i
rem assign entities their patrol paths (entityNum, pathNum)
`AI Entity Assign Patrol Path 2,1
`AI Entity Assign Patrol Path 3,1
`AI Entity Assign Patrol Path 4,1
rem make 3 cilivians
for i = 301 to (300+neutral)
make object i,1,0
position object i,rnd(50)-25,2.5,rnd(50)-25
rem add them to the enemy team and set their speed (in units per second)
AI Add Neutral i
AI Set Entity Speed i,10.0
AI Set Entity View Arc i,90,180
AI Set Entity Hearing Range i,100
next i
rem make 2 friendlies
for i = 501 to (500+friendly)
make object i,1,0
position object i,rnd(50)-25,2.5,-40
texture object i,12
make object i+1000,2,12
set object light i+1000,0
hide object i+1000
rem add them to the enemy team and set their speed (in units per second)
AI Add Friendly i
AI Set Entity Speed i,10.0
AI Set Entity View Arc i,90,180
AI Set Entity View Range i,60
AI Set Entity Hearing Range i,80
next i
rem make player
make object sphere 1,5
position object 1,20,2.5,-40
AI Add Player 1
position camera 0,100,-30 : point camera 0,0,-5
currtime# = timer()
lasttime# = currtime#
do
currtime# = timer()
speed# = 0.06*(currtime# - lasttime#)
lasttime# = currtime#
if upkey()=1 then move object 1,speed#
if downkey()=1 then move object 1,-speed#
if leftkey()=1 then move object left 1,speed#
if rightkey()=1 then move object right 1,speed#
rem handle debugging output
if keystate(2)=1 and ptimer<timer()
ptimer = timer()+300
pMode = 1-pMode
if ( pMode=0 ) then AI Debug Hide Paths else AI Debug Show Paths 2.5
endif
if keystate(3)=1 and btimer<timer()
btimer = timer()+300
bMode = 1-bMode
if ( bMode=0 ) then AI Debug Hide Obstacle Bounds 0 else AI Debug Show Obstacle Bounds 0,2.5
endif
if keystate(33)=1 and ftimer<timer()
ftimer = timer()+300
AI Team Follow Player 20
endif
if keystate(31)=1 and stimer<timer()
stimer = timer()+300
AI Team Separate
endif
rem handle F1 key
if ( keystate(59)=1 and f1Timer<timer() )
f1Timer = timer()+300
F1Pressed=1-F1Pressed
endif
if ( F1Pressed )
rem display info
set cursor 0,0
print "Enemies Are Red, Friendlies Are Green, Neutral Is White"
print
print "Controls: "
print "[ArrowKeys] Move Player"
print "[F] Make Friendlies Follow Player"
print "[S] Stop Friendlies Following Player"
print
print "Debug Controls: "
print "[1] Toggle Entity Path"
print "[2] Toggle Obstacle Bounds"
print
print "FPS: ";screen fps()
else
center text screen width()/2, 30, "-- Press F1 For Help --"
endif
rem hide attack lines
for i=1001 to 1025
if object exist(i) and shootTimer(i-1000)<70 then hide object i
next i
rem Call this command every sync to update entity AI state
AI Update
for i = 100 to 1000
if AI Entity Exist(i)=1
if AI Get Entity Can Fire(i) and shootTimer(i)<=0
tx# = AI Get Entity Target X(i)
tz# = AI Get Entity Target Z(i)
x# = object position x(i)
z# = object position z(i)
dx# = ( x# + tx# ) / 2.0
dz# = ( z# + tz# ) / 2.0
dist# = sqrt ( (tx#-x#)*(tx#-x#) + (tz#-z#)*(tz#-z#) )
ang# = acos ( (tz#-z#) / dist# )
if ( (tx#-x#) < 0 ) then ang# = 360 - ang#
position object i+1000,dx#,2.5,dz#
yrotate object i+1000,ang#+0.1
scale object i+1000,100,100,100*dist#
show object i+1000
shootTimer(i)=100
AI Create Sound x#,z#,11,100
endif
endif
if shootTimer(i)>0 then shootTimer(i) = shootTimer(i)-(speed#*3)
if object exist(i+1000) and shootTimer(i)<70 then hide object i+1000
next i
sync
loop
function MakeBackground()
load image "stripe5.png",1
load image "stripe6.png",2
rem create the background object
make object sphere 99999,400,48,48
texture object 99999,1
scale object texture 99999,6,6
set object cull 99999,0
set object light 99999,0
rotate object 99999,0,0,90
rem add the logo across the bottom
load image "logo.png", 100000
sprite 1, 0, screen height() - 60, 100000
endfunction
function MakeLevel()
rem make floor
make object box 10000,100,1,100
position object 10000,0,-0.5,0
texture object 10000,2
i = 10111
for x = -1 to 1
for z = -1 to 1
if ( x<>0 or z<>0 )
y# = rnd(5)+5
make object box i,12,y#,12
position object i,x*30,y#/2,z*30
color object i,rgb(rnd(180),rnd(180),rnd(180))
AI Add Static Obstacle i
inc i
endif
next y
next x
rem make boundary obstacle, encloses the space to keep the entity in
AI Start New Obstacle
rem add points in a anti-clockwise direction to create a boundary (use clockwise to create an obstacle)
AI Add Obstacle Vertex -50,-50
AI Add Obstacle Vertex 50,-50
AI Add Obstacle Vertex 50,50
AI Add Obstacle Vertex -50,50
rem finish creating our boundary
AI End New Obstacle 0,1
AI Complete Obstacles
endfunction
function MakeColorImage(image,mem,color)
make memblock mem,16
write memblock dword mem,0,1
write memblock dword mem,4,1
write memblock dword mem,8,32
write memblock dword mem,12,color
make image from memblock image,mem
delete memblock mem
endfunction
Inspirational Music: Descent ][ Redbook Audio CD Soundtrack