summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2017-11-10 14:14:41 +0100
committernsensfel <SpamShield0@noot-noot.org>2017-11-10 14:14:41 +0100
commitbe244f5d25dcbc7dd5572665a30e9c99d52d2a71 (patch)
treed2769af420f4091b48f2c32556edd4080fd95875
parent5621bd5d513a2be44608f09f2b821e42387dd8f0 (diff)
That should do the trick.
-rw-r--r--conf/yaws.conf1
-rw-r--r--src/battlemap_load_state.erl4
-rw-r--r--src/battlemap_node.erl11
-rw-r--r--src/shim_battlemap_character.erl26
-rw-r--r--src/shim_database.erl3
-rw-r--r--src/timed_cache_object.erl2
-rw-r--r--src/timed_caches_manager.erl20
7 files changed, 52 insertions, 15 deletions
diff --git a/conf/yaws.conf b/conf/yaws.conf
index 573118f..ecd5bfb 100644
--- a/conf/yaws.conf
+++ b/conf/yaws.conf
@@ -111,4 +111,5 @@ keepalive_timeout = 30000
docroot = /my/src/tacticians-server/www/
auth_log = true
appmods = <cgi-bin, yaws_appmod_cgi>
+ start_mod = battlemap_node
</server>
diff --git a/src/battlemap_load_state.erl b/src/battlemap_load_state.erl
index e519886..43fde3d 100644
--- a/src/battlemap_load_state.erl
+++ b/src/battlemap_load_state.erl
@@ -9,7 +9,7 @@
handle (Req) ->
JSONReqMap = jiffy:decode(Req, [return_maps]),
BattlemapID = maps:get(<<"battlemap_id">>, JSONReqMap),
- io:format("~nLoading Battlemap ~p...", [BattlemapID]),
+ io:format("~nLoading Battlemap ~p...~n", [BattlemapID]),
{Battlemap, CharList} =
timed_cache_object:fetch(
battlemaps_db,
@@ -34,7 +34,7 @@ handle (Req) ->
{
<<"data">>,
[
- battlemap_battlemap:encode_to_json(Battlemap)
+ battlemap_battlemap:encode_in_json(Battlemap)
|
lists:map(
fun (Char) ->
diff --git a/src/battlemap_node.erl b/src/battlemap_node.erl
new file mode 100644
index 0000000..cf6b65b
--- /dev/null
+++ b/src/battlemap_node.erl
@@ -0,0 +1,11 @@
+-module(battlemap_node).
+-export([start/1]).
+
+start(_YawsParams) ->
+ {ok, Pid} = gen_server:start(timed_caches_manager, [], []),
+ gen_server:cast(Pid, {add, battlemaps_db, none}),
+%% timed_caches_manager:add_cache([], battlemaps_db, none),
+ receive
+ after 5000 ->
+ [] = ets:lookup(battlemaps_db, <<"00">>)
+ end.
diff --git a/src/shim_battlemap_character.erl b/src/shim_battlemap_character.erl
index 80e91b0..5d28c53 100644
--- a/src/shim_battlemap_character.erl
+++ b/src/shim_battlemap_character.erl
@@ -22,16 +22,22 @@ generate_char (N, X, Y, Team) ->
generate (0, Result, _MaxX, _MaxY) ->
Result;
generate (N, Prev, MaxX, MaxY) ->
- [
- generate_char
- (
- N,
- (rand:uniform(MaxX) - 1),
- (rand:uniform(MaxY) - 1),
- (N rem 2)
- )
- | Prev
- ].
+ generate
+ (
+ (N - 1),
+ [
+ generate_char
+ (
+ N,
+ (rand:uniform(MaxX) - 1),
+ (rand:uniform(MaxY) - 1),
+ (N rem 2)
+ )
+ | Prev
+ ],
+ MaxX,
+ MaxY
+ ).
generate (MaxX, MaxY) ->
generate(rand:uniform(14) + 2, [], MaxX, MaxY).
diff --git a/src/shim_database.erl b/src/shim_database.erl
index 237ff4d..4628664 100644
--- a/src/shim_database.erl
+++ b/src/shim_database.erl
@@ -1,7 +1,8 @@
-module(shim_database).
-export([fetch/2]).
-fetch(battlemaps_db, _Object_ID) ->
+fetch(battlemaps_db, Object_ID) ->
+ io:format("~nGenerating neew Battlemap ~p... ~n", [Object_ID]),
Width = (rand:uniform(54) + 10),
Height = (rand:uniform(54) + 10),
{ok,
diff --git a/src/timed_cache_object.erl b/src/timed_cache_object.erl
index 80127d5..341d128 100644
--- a/src/timed_cache_object.erl
+++ b/src/timed_cache_object.erl
@@ -26,7 +26,7 @@
%% LOCAL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
add_to_cache (DB, ObjectID) ->
- {ok, TimerPID} = gen_server:start(?MODULE, [{DB, ObjectID}], []),
+ {ok, TimerPID} = gen_server:start(?MODULE, {DB, ObjectID}, []),
{ok, Data} = shim_database:fetch(DB, ObjectID),
ets:insert(DB, {ObjectID, TimerPID, Data}),
Data.
diff --git a/src/timed_caches_manager.erl b/src/timed_caches_manager.erl
index c1c1363..4c3c267 100644
--- a/src/timed_caches_manager.erl
+++ b/src/timed_caches_manager.erl
@@ -32,19 +32,33 @@
delete_cache (DB) ->
ets:delete(DB).
+add_cache (DB, none) ->
+ io:format("~nTimed Caches Manager added a new cache. ~n"),
+ ets:new(
+ DB,
+ [
+ set,
+ public,
+ named_table,
+ {keypos, 1},
+ {read_concurrency, true},
+ {heir, none}
+ ]
+ );
add_cache (DB, Heir) ->
+ io:format("~nTimed Caches Manager added a new cache. ~n"),
ets:new(
DB,
[
set,
public,
+ named_table,
{keypos, 1},
{read_concurrency, true},
{heir, Heir, DB}
]
).
-
inherit_cache (CacheList, DB, Heir) ->
case lists:member(DB, CacheList) of
true ->
@@ -61,6 +75,7 @@ inherit_cache (CacheList, DB, Heir) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% gen_server
init (CacheList) ->
+ io:format("~nStarting Timed Caches Manager..."),
{ok,CacheList}.
handle_call ({delete, CacheName}, _Caller, State) ->
@@ -108,6 +123,9 @@ delete_cache (CacheList, DB) ->
add_cache (CacheList, DB, Heir) ->
case lists:member(DB, CacheList) of
+ true when (Heir =:= none) ->
+ CacheList;
+
true ->
ets:setopts(DB, {heir, Heir, DB}),
CacheList;