From 94c0bbff6a3032bae20ce85775b01784fea0457c Mon Sep 17 00:00:00 2001 From: Crazylemon64 Date: Thu, 28 Jul 2016 19:07:02 -0700 Subject: [PATCH] Something to show to DZD --- code/__DEFINES/zlevel.dm | 0 code/modules/spacial_allocator/TODO | 3 + code/modules/spacial_allocator/heap_zlevel.dm | 12 +++ code/modules/spacial_allocator/space_chunk.dm | 13 +++ .../spacial_allocator/zlevel_manager.dm | 91 +++++++++++++------ paradise.dme | 3 + 6 files changed, 92 insertions(+), 30 deletions(-) create mode 100644 code/__DEFINES/zlevel.dm create mode 100644 code/modules/spacial_allocator/TODO create mode 100644 code/modules/spacial_allocator/heap_zlevel.dm create mode 100644 code/modules/spacial_allocator/space_chunk.dm diff --git a/code/__DEFINES/zlevel.dm b/code/__DEFINES/zlevel.dm new file mode 100644 index 00000000000..e69de29bb2d diff --git a/code/modules/spacial_allocator/TODO b/code/modules/spacial_allocator/TODO new file mode 100644 index 00000000000..2e70379bd77 --- /dev/null +++ b/code/modules/spacial_allocator/TODO @@ -0,0 +1,3 @@ +# Make sure people can't teleport while in our pocket dimensions +## Maybe add flags or similar, as an option for each requested chunk +# Something something lighting updates diff --git a/code/modules/spacial_allocator/heap_zlevel.dm b/code/modules/spacial_allocator/heap_zlevel.dm new file mode 100644 index 00000000000..50a9635e683 --- /dev/null +++ b/code/modules/spacial_allocator/heap_zlevel.dm @@ -0,0 +1,12 @@ +/datum/zlevel/heap + var/datum/space_chunk/top + +/datum/zlevel/heap/New() + ..() + top = new + +/datum/zlevel/heap/proc/request(width, height) + return 1 // All are welcome! At least until I add code for this + +/datum/zlevel/heap/allocate(width, height) + return diff --git a/code/modules/spacial_allocator/space_chunk.dm b/code/modules/spacial_allocator/space_chunk.dm new file mode 100644 index 00000000000..301d6d486da --- /dev/null +++ b/code/modules/spacial_allocator/space_chunk.dm @@ -0,0 +1,13 @@ +/datum/space_chunk + var/x + var/y + var/width + var/height + var/zpos + +/datum/space_chunk/New(w, h, z, new_x, new_y) + x = new_x + y = new_y + zpos = z + width = w + height = h diff --git a/code/modules/spacial_allocator/zlevel_manager.dm b/code/modules/spacial_allocator/zlevel_manager.dm index 3c6fb0a0048..cd96d152dc8 100644 --- a/code/modules/spacial_allocator/zlevel_manager.dm +++ b/code/modules/spacial_allocator/zlevel_manager.dm @@ -3,6 +3,7 @@ var/global/datum/zlev_manager/zlevels = new /datum/zlev_manager // A list of z-levels var/list/z_list = list() + var/list/heaps = list() // Populate our z level list @@ -21,36 +22,6 @@ var/global/datum/zlev_manager/zlevels = new else return z_list[z] -// For when you need the z-level to be at a certain point -/datum/zlev_manager/proc/increase_max_zlevel_to(new_maxz) - if(world.maxz>=new_maxz) - return - while(world.maxznew_maxz) - kill_topmost_zlevel() - -// Decrements the max z-level by one -// not normally used, but hey the swapmap loader wanted it -/datum/zlev_manager/proc/kill_topmost_zlevel() - var/our_z = world.maxz - qdel(z_list[our_z]) - z_list.len-- - world.maxz-- - /* * "Dirt" management * "Dirt" is used to keep track of whether a z level should automatically have @@ -87,3 +58,63 @@ var/global/datum/zlev_manager/zlevels = new /datum/zlev_manager/proc/postpone_init(z, thing) var/datum/zlevel/our_z = get_zlev(z) our_z.init_list.Add(thing) + + +/** +* +* SPACE ALLOCATION +* +*/ + + +// For when you need the z-level to be at a certain point +/datum/zlev_manager/proc/increase_max_zlevel_to(new_maxz) + if(world.maxz>=new_maxz) + return + while(world.maxznew_maxz) + kill_topmost_zlevel() + +// Decrements the max z-level by one +// not normally used, but hey the swapmap loader wanted it +/datum/zlev_manager/proc/kill_topmost_zlevel() + var/our_z = world.maxz + qdel(z_list[our_z]) + z_list.len-- + world.maxz-- + + +// An internally-used proc used for heap-zlevel management +/datum/zlev_manager/proc/add_new_heap() + world.maxz++ + z_list.len++ + var/datum/zlevel/yup = new /datum/zlevel/heap(our_z) + z_list[world.max_z] = yup + return yup + +// This is what you can call to allocate a section of space +// Later, I'll add an argument to let you define the flags on the region +/datum/zlev_manager/proc/allocate_space(width, height) + if(!heaps.len) + heaps.len++ + heaps[heaps.len] = add_new_heap() + var/datum/zlevel/heap/our_heap + for(our_heap in heaps) + var/weve_got_vacancy = our_heap.request(width, height) + if(weve_got_vacancy) + break // We're sticking with the present value of `our_heap` - it's got room + diff --git a/paradise.dme b/paradise.dme index d79069d135d..58e23a1152e 100644 --- a/paradise.dme +++ b/paradise.dme @@ -44,6 +44,7 @@ #include "code\__DEFINES\snpc.dm" #include "code\__DEFINES\stat.dm" #include "code\__DEFINES\tick.dm" +#include "code\__DEFINES\zlevel.dm" #include "code\__HELPERS\_string_lists.dm" #include "code\__HELPERS\AnimationLibrary.dm" #include "code\__HELPERS\constants.dm" @@ -2003,6 +2004,8 @@ #include "code\modules\spacepods\parts.dm" #include "code\modules\spacepods\pod_fabricator.dm" #include "code\modules\spacepods\spacepod.dm" +#include "code\modules\spacial_allocator\heap_zlevel.dm" +#include "code\modules\spacial_allocator\space_chunk.dm" #include "code\modules\spacial_allocator\zlevel.dm" #include "code\modules\spacial_allocator\zlevel_manager.dm" #include "code\modules\store\items.dm"