rsc/ and common/ seem OK from the splice (read more)

common compiles correctly, although there are issues:

* There needs to be support for multiple pagers at once
* There needs to be a way to support multiple generation algorithms
This commit is contained in:
Kayne Ruse
2014-07-30 22:53:05 +10:00
parent 03f1723d88
commit 67c8bb6f11
5 changed files with 28 additions and 76 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. ../utilities INCLUDES+=. ../utilities ../graphics
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
-9
View File
@@ -1,9 +0,0 @@
--overwriting the existing hard coded methods
function Region.Load(region)
--the return value signals if this succeeded or failed
return false
end
function Region.Save(region)
--
end
-16
View File
@@ -1,16 +0,0 @@
--uber lazy declarations
function math.sqr(x) return x*x end
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x-i) + math.sqr(y-j)) end
--define these
function Region.Create(region)
for i = 1, Region.GetWidth() do
for j = 1, Region.GetHeight() do
Region.SetTile(region, i, j, 1, 1) --to show the basics are working
end
end
end
function Region.Unload(region)
--
end
-33
View File
@@ -1,33 +0,0 @@
local sheet = TileSheet.GetTileSheet()
local pager = RegionPager.GetRegionPager()
--the selected tilesheet
TileSheet.Load(sheet, config.dir.tilesets .. "terrain.bmp", 32, 32)
--tile macros, mapped to this tilesheet
local base = 14
local shift = 36
tiles = {
plains = base + shift * 0,
grass = base + shift * 1,
dirt = base + shift * 2,
sand = base + shift * 3,
water = base + shift * 4
}
--could set custom generation systems here, that differ from the global generators, etc.
function Region.Create(region)
for i = 1, Region.GetWidth() do
for j = 1, Region.GetHeight() do
local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
if dist < 10 then
Region.SetTile(region, i, j, 1, tiles.plains)
elseif dist < 12 then
Region.SetTile(region, i, j, 1, tiles.sand)
else
Region.SetTile(region, i, j, 1, tiles.water)
Region.SetSolid(region, i, j, true)
end
end
end
end
+27 -17
View File
@@ -1,35 +1,45 @@
print("Lua script check") print("Lua script check")
--uber lazy declarations --uber lazy declarations
function square(x) return x*x end function math.sqr(x) return x*x end
function distance(x, y, i, j) return math.sqrt(square(x - i) + square(y - j)) end function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
--tile macros, mapped to the tilesheet --objects to work on
--TODO: sheet is not accessable in the server
local sheet = TileSheet.GetTileSheet()
local pager = RegionPager.GetRegionPager()
--the selected tilesheet
TileSheet.Load(sheet, config.dir.tilesets .. "terrain.bmp", 32, 32)
--tile macros, mapped to this tilesheet
local base = 14 local base = 14
local shift = 36 local shift = 36
plains = base + shift * 0 tiles = {
grass = base + shift * 1 plains = base + shift * 0,
dirt = base + shift * 2 grass = base + shift * 1,
sand = base + shift * 3 dirt = base + shift * 2,
water = base + shift * 4 sand = base + shift * 3,
water = base + shift * 4
}
--Overwrite the original OnCreate with my own version --TODO: could set custom generation systems here, that differ from the global generators, etc.
Region.hcOnCreate = Region.OnCreate --TODO: I need a way to allow for different generation algorithms for different pager objects
Region.OnCreate = function(region) --TODO: This design requires only one pager, but this is not good.
local ret = Region.hcOnCreate(region) --best practices function Region.Create(region)
for i = 1, Region.GetWidth() do for i = 1, Region.GetWidth() do
for j = 1, Region.GetHeight() do for j = 1, Region.GetHeight() do
local dist = distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
if dist < 10 then if dist < 10 then
Region.SetTile(region, i, j, 1, plains) Region.SetTile(region, i, j, 1, tiles.plains)
elseif dist < 12 then elseif dist < 12 then
Region.SetTile(region, i, j, 1, sand) Region.SetTile(region, i, j, 1, tiles.sand)
else else
Region.SetTile(region, i, j, 1, water) Region.SetTile(region, i, j, 1, tiles.water)
Region.SetSolid(region, i, j, true)
end end
end end
end end
return ret
end end
print("Finished the lua script") print("Finished the lua script")