From d35cd5304d334582d8479062a52a8c7b34f892a1 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Sun, 25 Feb 2018 12:31:54 +0100 Subject: Fixes a few typos, adds 'unimplemented' functions. --- src/io/database_shim.erl | 110 ----------------------------------------------- 1 file changed, 110 deletions(-) delete mode 100644 src/io/database_shim.erl (limited to 'src/io/database_shim.erl') diff --git a/src/io/database_shim.erl b/src/io/database_shim.erl deleted file mode 100644 index d55d848..0000000 --- a/src/io/database_shim.erl +++ /dev/null @@ -1,110 +0,0 @@ --module(database_shim). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( - [ - generate_db/1, - fetch/2, - commit/4, - assert_session_is_valid/2 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -create_db (_Heir) -> - ets:new - ( - db_shim, - [ - set, - public, - named_table, - {keypos, 1}, - {read_concurrency, true} - ] - ), - io:format("~ndb_shim ets created.~n"). - -add_to_db (ID, Val) -> - io:format("~nadd to db_shim: ~p.~n", [{ID, Val}]), - ets:insert(db_shim, {ID, Val}). - -generate_char_instances (Battlemap, Characters) -> - lists:map - ( - fun (Char) -> - { - character:get_id(Char), - character_instance:new_instance_of - ( - Char, - (rand:uniform(2) - 1), % team, - { - rand:uniform(battlemap:get_width(Battlemap) - 1), % X - rand:uniform(battlemap:get_height(Battlemap) - 1) % Y - } - ) - } - end, - Characters - ). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -generate_db (Heir) -> - Pid = self(), - spawn(fun () -> create_db(Heir), Pid ! ok, receive ok -> ok end end), - receive - ok -> ok - end, - Players = [<<"0">>, <<"1">>], - Battlemap = battlemap_shim:generate_random(), - Characters = character_shim:generate_random(rand:uniform(12) + 4), - CharacterInsts = generate_char_instances(Battlemap, Characters), - BattlemapInstance = - battlemap_instance_shim:generate_random - ( - CharacterInsts, - Players - ), - add_to_db({battlemap_db, battlemap:get_id(Battlemap)}, Battlemap), - lists:map - ( - fun (Char) -> - add_to_db({character_db, character:get_id(Char)}, Char) - end, - Characters - ), - add_to_db - ( - {battlemap_instance_db, battlemap_instance:get_id(BattlemapInstance)}, - BattlemapInstance - ). - -fetch (DB, ObjectID) -> - io:format("~ndb_shim lookup: ~p.~n", [{DB, ObjectID}]), - case ets:lookup(db_shim, {DB, ObjectID}) of - [{_Key, Value}] -> {ok, Value}; - [] -> nothing - end. - -commit (DB, Owner, ObjectID, Value) -> - add_to_db({DB, ObjectID}, Value), - timed_cache:invalidate(DB, Owner, ObjectID). - -assert_session_is_valid (_PlayerID, _SessionToken) -> - % Ask PlayerID's login server if SessionToken is correct. - % If so, update last login time to prevent relogin within - % (database_timeout * 2). - % If not, crash. - ok. -- cgit v1.2.3-70-g09d2