Esempio n. 1
0
static int l_graphics_SpriteBatch_set(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  int id = l_tools_toNumberOrError(state, 2);

  graphics_Quad const * quad = &defaultQuad;
  int baseidx = 3;

  if(l_graphics_isQuad(state, 3)) {
    quad = l_graphics_toQuad(state, 3);
    baseidx = 4;
  }

  float x  = luaL_optnumber(state, baseidx,     0.0f);
  float y  = luaL_optnumber(state, baseidx + 1, 0.0f);
  float r  = luaL_optnumber(state, baseidx + 2, 0.0f);
  float sx = luaL_optnumber(state, baseidx + 3, 1.0f);
  float sy = luaL_optnumber(state, baseidx + 4, sx);
  float ox = luaL_optnumber(state, baseidx + 5, 0.0f);
  float oy = luaL_optnumber(state, baseidx + 6, 0.0f);
  float kx = luaL_optnumber(state, baseidx + 7, 0.0f);
  float ky = luaL_optnumber(state, baseidx + 8, 0.0f);

  //graphics_Batch_set(&batch->batch, id, quad, x, y, r, sx, sy, ox, oy, kx, ky);

  return 0;
}
Esempio n. 2
0
static int l_graphics_SpriteBatch_add(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  graphics_Quad const * quad = &defaultQuad;
  int baseidx = 2;

  if(l_graphics_isQuad(state, 2)) {
    quad = l_graphics_toQuad(state, 2);
    baseidx = 3;
  }

  float x  = luaL_optnumber(state, baseidx,     0.0f);
  float y  = luaL_optnumber(state, baseidx + 1, 0.0f);
  float r  = luaL_optnumber(state, baseidx + 2, 0.0f);
  float sx = luaL_optnumber(state, baseidx + 3, 1.0f);
  float sy = luaL_optnumber(state, baseidx + 4, sx);
  float ox = luaL_optnumber(state, baseidx + 5, 0.0f);
  float oy = luaL_optnumber(state, baseidx + 6, 0.0f);
  float kx = luaL_optnumber(state, baseidx + 7, 0.0f);
  float ky = luaL_optnumber(state, baseidx + 8, 0.0f);

  int i = graphics_Batch_add(&batch->batch, quad, x, y, r, sx, sy, ox, oy, kx, ky);
  lua_pushinteger(state, i);


  return 1;
}
Esempio n. 3
0
static int l_graphics_SpriteBatch_clear(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);
  graphics_Batch_clear(&batch->batch);

  return 0;
}
Esempio n. 4
0
static int l_graphics_gcSpriteBatch(lua_State* state) {
  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);
  graphics_Batch_free(&batch->batch);
  luaL_unref(state, LUA_REGISTRYINDEX, batch->textureRef);


  return 0;
}
Esempio n. 5
0
int l_graphics_SpriteBatch_getTexture(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  lua_rawgeti(state, LUA_REGISTRYINDEX, batch->textureRef);

  return 1;
}
Esempio n. 6
0
int l_graphics_SpriteBatch_getCount(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  lua_pushnumber(state, batch->batch.insertPos);

  return 1;
}
Esempio n. 7
0
int l_graphics_SpriteBatch_getBufferSize(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  lua_pushnumber(state, batch->batch.maxCount);

  return 1;
}
Esempio n. 8
0
int l_graphics_SpriteBatch_setBufferSize(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  int newsize = l_tools_toNumberOrError(state, 2);

  graphics_Batch_changeBufferSize(&batch->batch, newsize);

  return 0;
}
Esempio n. 9
0
int l_graphics_SpriteBatch_setTexture(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  l_graphics_Image const* image = l_graphics_toImage(state, 2);

  batch->batch.texture = &image->image;
  luaL_unref(state, LUA_REGISTRYINDEX, batch->textureRef);
  lua_settop(state, 2);
  batch->textureRef = luaL_ref(state, LUA_REGISTRYINDEX);

  return 0;
}
Esempio n. 10
0
int l_graphics_SpriteBatch_getColor(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  if(!batch->batch.colorSet) {
    return 0;
  }

  lua_pushnumber(state, floor(batch->batch.color.x * 255));
  lua_pushnumber(state, floor(batch->batch.color.y * 255));
  lua_pushnumber(state, floor(batch->batch.color.z * 255));
  lua_pushnumber(state, floor(batch->batch.color.w * 255));

  return 4;
}
Esempio n. 11
0
int l_graphics_SpriteBatch_setColor(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  if(!lua_isnumber(state, 2)) {
    graphics_Batch_clearColor(&batch->batch);
  } else {
    float r = l_tools_toNumberOrError(state, 2);
    float g = l_tools_toNumberOrError(state, 3);
    float b = l_tools_toNumberOrError(state, 4);
    float a = luaL_optnumber(state, 5, 255);
    graphics_Batch_setColor(&batch->batch, r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
  }


  return 0;
}