Grrrr.... I've ripped out a chunk of code but I'm having an issue with it... Hopefully it will explain it better than what I type up...
Okay, currently not working on the other test mode, but in the main project using the many base tiles for instancing, the FPS drops...
sync on : sync rate 60 : autocam off
set display mode 800, 600, 32
global iTexture1, iTexture2 as integer
iTexture1 = Create_Texture( 1 )
iTexture2 = Create_texture( 2 )
global TEST_MODE as integer
TEST_MODE = 0 // 1 for optimised tilesets / 0 for normal cubes
if TEST_MODE = 1
make object cube 1, 10
make object cube 2, 10
texture object 1, iTexture1
texture object 2, iTexture2
hide object 1
hide object 2
else
make_base_tiles()
make_optimised_tileset( iTexture1, inst_tiles + ( 0 * 64 ) )
make_optimised_tileset( itexture2, inst_tiles + ( 1 * 64 ) )
endif
position camera 0,0,-50
point camera 0,0,0
camspd = 2
do
curr_object = 1000
for loop_z = 0 to 29
for loop_y = 0 to 1
for loop_x = 0 to 29
if object exist( curr_object )
delete object curr_object
endif
if TEST_MODE = 0
if rnd(1) = 1
instance object curr_object, 1
else
instance object curr_object, 2
endif
position object curr_object, loop_x * 10, loop_y * 10, loop_z * 10
else
temp = rnd(63)
if temp > 0
if rnd(1) = 1
instance object curr_object, inst_tiles + ( 0 * 64 ) + temp
else
instance object curr_object, inst_tiles + ( 1 * 64 ) + temp
endif
endif
ENDIF
inc curr_object
next // loop_x
next // loop_y
NEXT // loop_z
// camera
mx# = mousemovex() / 4.0
my# = mousemovey() / 4.0
yrotate camera camera angle y() + mx#
xrotate camera camera angle x() + my#
if upkey() then move camera camspd
if downkey() then move camera -camspd
if leftkey() then move camera left camspd
if rightkey() then move camera right camspd
text 0,0,"FPS = " + str$(screen fps())
sync
LOOP
END
Rem ***** Included Source File *****
// Creates 63 base tile for a cube object
// The main base tiles are from reserved object ID's from 512 to 575
// all other instanced tiles start from 576
// base_tiles is the list of objects to copy the main blocks from
// inst_tiles is the block instance object ID starting from 576
// to calc the ID to instance use:
// ID = inst_tiles + ( tile_main * 64 ) + tile_ref
#constant FACEMASK_FRONT 1
#constant FACEMASK_BACK 2
#constant FACEMASK_LEFT 4
#constant FACEMASK_RIGHT 8
#constant FACEMASK_BOTTOM 16
#constant FACEMASK_TOP 32
type BT_VERT
x, y, z as float
endtype
function make_base_tiles()
global base_tiles as integer
global inst_tiles as integer
base_tiles = 512
inst_tiles = 576
global dim BT_VERTS() as BT_VERT
global BT_UV1, BT_UV2 as float
local num_sides, num_verts, num_indices, curr_face as integer
local curr, fvf as integer
fvf = FVF_XYZ || FVF_NORMAL || FVF_NORMAL || FVF_DIFFUSE || FVF_SPECULAR || FVF_TEX1
// tile 0 is always empty
// just loop through all tiles with at least 1 of 6 faces
for curr = 1 to 63
// calc number of verts and faces before creating the object
num_sides = 0
if curr and FACEMASK_FRONT then inc num_sides
if curr and FACEMASK_BACK then inc num_sides
if curr and FACEMASK_LEFT then inc num_sides
if curr and FACEMASK_RIGHT then inc num_sides
if curr and FACEMASK_BOTTOM then inc num_sides
if curr and FACEMASK_TOP then inc num_sides
num_verts = num_sides * 4
num_indices = num_sides * 6
make object new base_tiles + curr, num_verts, num_indices, fvf
curr_face = 0
lock vertexdata for limb base_tiles + curr, 0
if curr and FACEMASK_FRONT then add_front_face( curr_face ) : inc curr_face
if curr and FACEMASK_BACK then add_back_face( curr_face ) : inc curr_face
if curr and FACEMASK_LEFT then add_left_face( curr_face ) : inc curr_face
if curr and FACEMASK_RIGHT then add_right_face( curr_face ) : inc curr_face
if curr and FACEMASK_BOTTOM then add_bottom_face( curr_face ) : inc curr_face
if curr and FACEMASK_TOP then add_top_face( curr_face ) : inc curr_face
unlock vertexdata
set object normals base_tiles + curr
hide object base_tiles + curr
exclude object on base_tiles + curr
NEXT
ENDFUNCTION
#constant UVTOP 0.0
#constant UVBOT 0.98
#constant UVTOP1 0.0
#constant UVTOP2 0.32
#constant UVBOT1 0.67
#constant UVBOT2 0.98
#constant UVSID1 0.33
#constant UVSID2 0.65
function add_front_face( pos )
empty array BT_VERTS()
add_bt_vert(-5, 5, -5)
add_bt_vert( 5, 5, -5)
add_bt_vert( 5, -5, -5)
add_bt_vert(-5, -5, -5)
BT_UV1 = UVSID1
BT_UV2 = UVSID2
add_bt_vert_face( pos )
ENDFUNCTION
function add_back_face( pos )
empty array BT_VERTS()
add_bt_vert( 5, 5, 5)
add_bt_vert(-5, 5, 5)
add_bt_vert(-5, -5, 5)
add_bt_vert( 5, -5, 5)
BT_UV1 = UVSID1
BT_UV2 = UVSID2
add_bt_vert_face( pos )
ENDFUNCTION
function add_left_face( pos )
empty array BT_VERTS()
add_bt_vert(-5, 5, 5)
add_bt_vert(-5, 5, -5)
add_bt_vert(-5, -5, -5)
add_bt_vert(-5, -5, 5)
BT_UV1 = UVSID1
BT_UV2 = UVSID2
add_bt_vert_face( pos )
ENDFUNCTION
function add_right_face( pos )
empty array BT_VERTS()
add_bt_vert( 5, 5, -5)
add_bt_vert( 5, 5, 5)
add_bt_vert( 5, -5, 5)
add_bt_vert( 5, -5, -5)
BT_UV1 = UVSID1
BT_UV2 = UVSID2
add_bt_vert_face( pos )
ENDFUNCTION
function add_bottom_face( pos )
empty array BT_VERTS()
add_bt_vert(-5, -5, -5)
add_bt_vert( 5, -5, -5)
add_bt_vert( 5, -5, 5)
add_bt_vert(-5, -5, 5)
BT_UV1 = UVBOT1
BT_UV2 = UVBOT2
add_bt_vert_face( pos )
ENDFUNCTION
function add_top_face( pos )
empty array BT_VERTS()
add_bt_vert(-5, 5, 5)
add_bt_vert( 5, 5, 5)
add_bt_vert( 5, 5, -5)
add_bt_vert(-5, 5, -5)
BT_UV1 = UVTOP1
BT_UV2 = UVTOP2
add_bt_vert_face( pos )
ENDFUNCTION
function add_bt_vert(x#, y#, z#)
array insert at bottom BT_VERTS()
BT_VERTS().x = x#
BT_VERTS().y = y#
BT_VERTS().z = z#
endfunction
function add_bt_vert_face( pos )
vpos = pos * 4
ipos = pos * 6
local x1, y1, z1, x2, y2, z2 as float
local x3, y3, z3, x4, y4, z4 as float
x1 = BT_VERTS(0).x : y1 = BT_VERTS(0).y : z1 = BT_VERTS(0).z
x2 = BT_VERTS(1).x : y2 = BT_VERTS(1).y : z2 = BT_VERTS(1).z
x3 = BT_VERTS(2).x : y3 = BT_VERTS(2).y : z3 = BT_VERTS(2).z
x4 = BT_VERTS(3).x : y4 = BT_VERTS(3).y : z4 = BT_VERTS(3).z
set vertexdata position vpos , x1, y1, z1
set vertexdata position vpos+1, x2, y2, z2
set vertexdata position vpos+2, x3, y3, z3
set vertexdata position vpos+3, x4, y4, z4
set vertexdata uv vpos , BT_UV1, UVTOP
set vertexdata uv vpos+1, BT_UV2, UVTOP
set vertexdata uv vpos+2, BT_UV2, UVBOT
set vertexdata uv vpos+3, BT_UV1, UVBOT
set indexdata ipos , 0
set indexdata ipos+1, 1
set indexdata ipos+2, 2
set indexdata ipos+3, 0
set indexdata ipos+4, 2
set indexdata ipos+5, 3
ENDFUNCTION
function make_optimised_tileset( image, obj_start )
local a as integer
for a = 1 to 63
clone object obj_start + a, base_tiles + a
texture object obj_start + a, image
hide object obj_start + a
exclude object on obj_start + a
NEXT
ENDFUNCTION
function get_tile_ref( front, back, left, right, bottom, top )
local inst_object = 0
if front then inst_object = inst_object + 1
if back then inst_object = inst_object + 2
if left then inst_object = inst_object + 4
if right then inst_object = inst_object + 8
if bottom then inst_object = inst_object + 16
if top then inst_object = inst_object + 32
ENDFUNCTION inst_object
function Create_Texture( r )
randomize r
local size, id as integer
size = 16
draw_block(0, 0, size, size)
draw_block(size, 0, size, size)
draw_block(size*2, 0, size, size)
id = free_image()
get image id, 0,0,size*3-1, size-1
ENDFUNCTION id
function free_image()
local c as integer
c=1
while image exist(c)
inc c
ENDWHILE
ENDFUNCTION c
function draw_block(topx, topy, wid, hgt)
local red_main, grn_main, blu_main as integer
local red_curr, grn_curr, blu_curr as integer
red_main = rnd(255)
grn_main = rnd(255)
blu_main = rnd(255)
lock pixels
for x = topx to topx + wid - 1
for y = topy to topy + hgt - 1
red_curr = red_main + rnd(64) - 32
grn_curr = grn_main + rnd(64) - 32
blu_curr = blu_main + rnd(64) - 32
if red_curr < 0
red_curr = 0
else
if red_curr > 255
red_curr = 255
endif
ENDIF
if grn_curr < 0
grn_curr = 0
else
if grn_curr > 255
grn_curr = 255
endif
ENDIF
if blu_curr < 0
blu_curr = 0
else
if blu_curr > 255
blu_curr = 255
endif
ENDIF
dot x, y, rgb( red_curr, grn_curr, blu_curr )
next
NEXT
unlock pixels
ENDFUNCTION
Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!