Skip to content

Instantly share code, notes, and snippets.

@arch-jslin
arch-jslin / gist:634137
Created October 19, 2010 12:51
guess_server_script.js
// env, kit 為 server 暴露給開發者用的功能物件
var sys = kit.sys; // 服務管理工具
var game = kit.game; // 遊戲邏輯工具
var db = kit.db; // 資料永續儲存介面
var mem = kit.sharedmem; // shared variable, 跨多個 logic files
var data_ = {}; // user defined local variable
/*
* 1. 覆寫遊戲服務的管理事件, 如 start, stop 等, 沒寫的話 server 會用內建版本
*/
@arch-jslin
arch-jslin / lua_meta.lua
Created February 14, 2011 04:27
Lua: C++ template like example
-- suppose you have a Vec2 and Vec3 type, and a T type which will use them accordingly
-- The Class information should be available out side of this file scope, e.g
-- require 'Vec2'
-- require 'Vec3'
-- require 'Class_with_dimension'
-- I wrote it down here just for simplification
local Vec2 = {}
function Vec2:new(x, y) return setmetatable({x, y}, {__index = self}) end
@arch-jslin
arch-jslin / saveGameData.java
Created February 23, 2011 17:44
saveGameData.java
//igdshare 110220: code provided by hsufong
private int saveGameData(int fIndex){
String saveFileName = "/data/data/com.mobile_sango/sangoSave"+fIndex+".bin";
String description = setSaveDescription();
FileOutputStream fosFile;
OutputStream fosDes;
File saveFile = new File(saveFileName);
if (!saveFile.exists()){
try {
@arch-jslin
arch-jslin / surfaceview.java
Created February 23, 2011 17:45
surfaceview.java
//igdshare 110220: code provided by hsufong
class MainPlan extends SurfaceView implements SurfaceHolder.Callback {
private DrawPlanThread drawplanThread;
public MainPlan(Context context) {
super(context);
getHolder().addCallback(this);
drawplanThread = new DrawPlanThread(getHolder(), this);
}
private boolean XYInRect(int fX,int fY,Rect fRect){
boolean tInside = false;
@arch-jslin
arch-jslin / blah.lua
Created May 31, 2011 15:21
just blah
function Game:process_dropping(now_t, last_t)
self.cubes:for2d(function(c)
if c:is_waiting() then
if self:is_below_empty(c) then
drop_cube_logical(c, self.cubes)
drop_cube(c, now_t, last_t)
end
elseif c:is_dropping() then
drop_cube(c, now_t, last_t)
if c:arrived_at_logical_position() then
@arch-jslin
arch-jslin / 123
Created November 18, 2011 14:54 — forked from gaspard/gist:1087380
#include <cstdio>
#include <cstdlib>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "luajit.h"
}
@arch-jslin
arch-jslin / simple_jit.lua
Created November 18, 2011 14:56 — forked from gaspard/simple_jit.lua
Testing Luajit bindings to C++
local ffi = require 'ffi'
local C = ffi.C
ffi.cdef[[
typedef struct Simple Simple;
Simple *Simple_Simple(int);
void Simple__gc(Simple *);
int Simple_id(Simple *);
@arch-jslin
arch-jslin / main.cpp
Created November 18, 2011 15:03
Simple C++ class in a main executable, see if luajit ffi should be able to resolve symbols.
#include <cstdio>
#include <cstdlib>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "luajit.h"
}
@arch-jslin
arch-jslin / misspell.lua
Created December 1, 2011 09:10
misspell.lua
local input = arg[1]
math.randomseed(os.time())
local function random(n) return math.floor(math.random()*n) end
local function chararray(w)
local t = {};
for i = 1, #w do t[i] = w:sub(i,i) end
return t
end
local counter = 0
local function proc1()
while counter < 100000000 do
counter = counter + 1
coroutine.yield()
end
end
local function proc2()