Skip to content

Commit

Permalink
slabset things refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 9, 2023
1 parent 0aad3c1 commit b37951a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 79 deletions.
109 changes: 52 additions & 57 deletions Autoload/Slabset.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extends Node

var tngIndex = []
var tngObject = []
var tng = []
var numberOfThings = 0

# dat[slabID][variation][subtile]
Expand All @@ -22,81 +21,77 @@ enum dir {
center = 27
}



func load_slabset():
tng = []
dat = []
var CODETIME_START = OS.get_ticks_msec()
var oGame = Nodelist.list["oGame"]
var oMessage = Nodelist.list["oMessage"]

var dat_buffer = Filetypes.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.DAT"))
dat_buffer.seek(2)
var tng_buffer = Filetypes.file_path_to_buffer(oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.TNG"))

var object_info = create_object_list(tng_buffer)
if object_info.size() == 0:
oMessage.quick("Failed to load objects")
return

var totalSlabs = 42 + 16
dat = []
dat.resize(28*totalSlabs) # Ensure each slab has space for 28 variations
var totalVariations = totalSlabs * 28
tng.resize(totalVariations)
dat.resize(totalVariations)
tng_buffer.seek(2)
dat_buffer.seek(2)

for variation in dat.size():
dat[variation] = []
dat[variation].resize(9)
tng[variation] = []
dat[variation] = [0,0,0, 0,0,0, 0,0,0]
if variation < 42*28 or (variation % 28) < 8: # Handle the longslabs and the shortslabs
#if variation < 42*28 or (variation >= 42*28 and (variation % 28) < 8):
for subtile in 9:
var value = 65536 - dat_buffer.get_u16()
dat[variation][subtile] = value
else: # Fill the extra space at the end of the shortslabs
for subtile in 9:
dat[variation][subtile] = 0
dat[variation][subtile] = 65536 - dat_buffer.get_u16()

var getObjectIndex = tng_buffer.get_u16()

while getObjectIndex < object_info.size(): # Continue until "break"
var objectStuff = object_info[getObjectIndex]
if objectStuff[1] != variation:
break
tng[variation].append(objectStuff)
getObjectIndex += 1

print('Created Slabset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')

func load_slabset_things():
CODETIME_START = OS.get_ticks_msec()
var oGame = Nodelist.list["oGame"]
var filePath = oGame.get_precise_filepath(oGame.DK_DATA_DIRECTORY, "SLABS.TNG")
var buffer = Filetypes.file_path_to_buffer(filePath)

buffer.seek(0)
numberOfThings = buffer.get_u16() # It says 359, however there are actually 362 entries in the file.
func create_object_list(tng_buffer):
tng_buffer.seek(0)
numberOfThings = tng_buffer.get_u16() # It says 359, however there are actually 362 entries in the file.
print('Number of Things: '+str(numberOfThings))

buffer.seek(2)
var numberOfSets = 1304
tngIndex.resize(numberOfSets)

for i in tngIndex.size():
var value = buffer.get_u16()
tngIndex[i] = value
tng_buffer.seek(2 + (1304*2))

buffer.seek(2 + (1304*2))

tngObject.resize(numberOfThings)
for i in tngObject.size():

tngObject[i] = []
tngObject[i].resize(9) #(this is coincidentally size 9, it has nothing to do with subtiles)
tngObject[i][0] = buffer.get_u8() # 0 = object/effectgen, 1 = light
tngObject[i][1] = buffer.get_u16() # slabVariation
tngObject[i][2] = buffer.get_u8() # subtile (between 0 and 8)
var object_info = []
object_info.resize(numberOfThings)
for i in object_info.size():
object_info[i] = []
object_info[i].resize(9) #(this is coincidentally size 9, it has nothing to do with subtiles)
object_info[i][0] = tng_buffer.get_u8() # 0 = object/effectgen, 1 = light

var datnum
var variation = tng_buffer.get_u16() # Extract the old slab variation index
if variation >= 1176: # If the variation index is from the short slabs in the original structure, calculate its new index in the uniform 58*28 structure.
variation = 1176 + ((variation - 1176) / 8) * 28 + (variation % 8)
object_info[i][1] = variation # Set the new slab variation index

# Location values can look like 255.75, this is supposed to be -0.25
datnum = buffer.get_u16() / 256.0
if datnum > 255: datnum -= 256
tngObject[i][3] = datnum
object_info[i][2] = tng_buffer.get_u8() # subtile (between 0 and 8)

datnum = buffer.get_u16() / 256.0
if datnum > 255: datnum -= 256
tngObject[i][4] = datnum
for xxx in [3,4,5]: # Location values can look like 255.75, this is supposed to be -0.25
var datnum = tng_buffer.get_u16() / 256.0
if datnum > 255: datnum -= 256
object_info[i][xxx] = datnum

datnum = buffer.get_u16() / 256.0
if datnum > 255: datnum -= 256
tngObject[i][5] = datnum

tngObject[i][6] = buffer.get_u8() # Thing type
tngObject[i][7] = buffer.get_u8() # Thing subtype
tngObject[i][8] = buffer.get_u8() # Effect range
for xxx in [6,7,8]: # Thing type, # Thing subtype, # Effect range
object_info[i][xxx] = tng_buffer.get_u8()

print('slabtng_object_entry_asset : '+str(OS.get_ticks_msec()-CODETIME_START)+'ms')

return object_info

func fetch_column_index(variation, subtile):
if variation < dat.size():
Expand Down
46 changes: 26 additions & 20 deletions Scenes/PlaceThingWithSlab.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ onready var dir = oSlabPlacement.dir
# For example the Prison bars need extra rules for detecting nearby walls, but the original slab cubes did not need these rules.
# So objects have their own placement rules, though we use the original bitmask/fullVariationIndex (from oSlabPlacement) as a basis to work from.

func place_slab_objects(xSlab, ySlab, slabID, ownership, fullVariationIndex, bitmask, surrID, surrOwner):
func place_slab_objects(xSlab, ySlab, slabID, ownership, slabVar, bitmask, surrID, surrOwner):
oInstances.delete_attached_objects_on_slab(xSlab, ySlab)

if slabID == Slabs.PRISON:
Expand Down Expand Up @@ -42,11 +42,13 @@ func place_slab_objects(xSlab, ySlab, slabID, ownership, fullVariationIndex, bit
var isMiddle = determine_if_middle(slabID, ownership, bitmask, surrID, surrOwner)
if isMiddle == false:
constructedSlab = oSlabPlacement.slab_all
#print(fullVariationIndex + constructedSlab[0])
#print(slabVar + constructedSlab[0])
#print(slabVar)

for subtile in 9:
var idx = get_obj_idx(fullVariationIndex + constructedSlab[subtile], subtile)
if idx != -1:
oInstances.spawn(xSlab, ySlab, slabID, ownership, subtile, Slabset.tngObject[idx])
var objectStuff = get_object(slabVar + constructedSlab[subtile], subtile)
if objectStuff.size() > 0:
oInstances.spawn(xSlab, ySlab, slabID, ownership, subtile, objectStuff)

func create_door_thing(xSlab, ySlab, ownership):
var createAtPos = Vector3((xSlab*3)+1.5, (ySlab*3)+1.5, 5)
Expand Down Expand Up @@ -83,21 +85,25 @@ func determine_if_middle(slabID, ownership, bitmask, surrID, surrOwner):
return true
return false

func get_obj_idx(newSlabVar, subtile):
if newSlabVar >= Slabset.tngIndex.size(): return -1 # Out of bounds, causes crash

var idx = Slabset.tngIndex[newSlabVar]
if idx >= Slabset.numberOfThings: return -1
# "tngIndex" has one index per fullVariationIndex.
# But there are actually multiple entries inside "tngObject" with the same fullVariationIndex value. Their index is grouped up, that's why I do idx+=1.
while true:
if subtile == Slabset.tngObject[idx][2]:
return idx

idx += 1
if idx >= Slabset.numberOfThings: return -1
if Slabset.tngObject[idx][1] != newSlabVar:
return -1
func get_object(slabVar, subtile):
for objectStuff in Slabset.tng[slabVar]:
if subtile == objectStuff[2]:
return objectStuff
return []
# if slabVar >= Slabset.tng.size(): return -1 # Out of bounds, causes crash
#
# var idx = Slabset.tng[slabVar]
# if idx >= Slabset.numberOfThings: return -1
# # "tng" has one index per fullVariationIndex.
# # But there are actually multiple entries inside "tngObject" with the same fullVariationIndex value. Their index is grouped up, that's why I do idx+=1.
# while true:
# if subtile == Slabset.tngObject[idx][2]:
# return idx
#
# idx += 1
# if idx >= Slabset.numberOfThings: return -1
# if Slabset.tngObject[idx][1] != slabVar:
# return -1

func prison_bar_bitmask(slabID, surrID):
var bitmask = 0
Expand Down
1 change: 0 additions & 1 deletion Scenes/SlabPalette.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ func start():
# Do this only once.
if Slabset.dat.empty() == true: Slabset.load_slabset()
if Columnset.cubes.empty() == true: Columnset.load_columnset()
if Slabset.tngIndex.empty() == true: Slabset.load_slabset_things()

#func test_write_to_file(data):
# print('WRITING TO CLM.TXT')
Expand Down
2 changes: 1 addition & 1 deletion Scenes/VoxelViewer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -6, 0,
projection = 1
current = true
fov = 90.0
size = 11.5
size = 20.0
far = 8192.0
script = ExtResource( 1 )

Expand Down

0 comments on commit b37951a

Please sign in to comment.