閒聊Python應用在game server的開發

1,047 views
923 views

Published on

2013/06/27 在Taipei.py分享的主題

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,047
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

閒聊Python應用在game server的開發

  1. 1. 閒聊Python應用在Game Server的開發 Eric Chen
  2. 2. Agenda ● Python應用在之前的專案中 ● Django與REST應用在遊戲開發上 ● 面臨的問題與挑戰
  3. 3. Before... ● Pure Python (Socket + Epoll) ● Django + PyAMF ● Django + REST
  4. 4. Socket vs Web Service ● Socket Server ○ Real Time ■ Player location info. ■ Chat ● Web Service ○ polling
  5. 5. REST API HTTP Method Data operate Description POST Create Create a resource without id. GET Read Get a resource. PUT Update Update a resource or create a resource with id if not existed. DELETE Delete Delete a resource
  6. 6. Framework ● Django ● Django REST framework
  7. 7. Why Django REST framework? Source of photo credit :http://django-rest-framework.org/
  8. 8. Example by Puzzle & Dragon Source of photo credit :http://www.gungho.co.jp/
  9. 9. Game flow 選擇關卡 進入戰鬥 卡片編輯 Source of photo credit :http://www.padpadblog.com/2012/11/blog-post_6024.html & http://zh.pad.wikia.com/wiki/Puzzle_%26_Dragons_%E7%BB%B4% E5%9F%BA 隊伍編輯
  10. 10. API ● /api/login/ ● /api/players/me/ ● /api/stages/ ● /api/cards/ ● /api/cards/groups/ ● etc...
  11. 11. Login models.py class Player(models.Model): access_token = models.CharField(max_length=255) level = models. exp = models. money = models ... serializer.py class LoginSerializer(serializers.Serializer): access_token = serializers.CharField() api.py class LoginView(APIView): def post(self, request): serializer = SnippetSerializer(data=request.DATA) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) player, created = Player.objects.get_or_create(access_token=access_token) result = {} request.session['player_id'] = player.id return Response(result)
  12. 12. Problem ● 資料庫存取次數 ● 資料庫延遲 ● Application Server 效能問題
  13. 13. ● 減少Server端計算 ● 修改企劃 ● 資料庫分割 ● 快取 ● NOSQL ● Queue
  14. 14. Q&A

×