Skip to content

Instantly share code, notes, and snippets.

View GoodBoyDigital's full-sized avatar

Mat Groves GoodBoyDigital

View GitHub Profile
@GoodBoyDigital
GoodBoyDigital / example.ts
Last active July 26, 2024 09:27
An example of how to use zod (https://www.npmjs.com/package/zod) to get a structured result from OpenAI
async function makeOpenAICall({ style, theme }: { style: string; theme: string }) {
/**
* set up a schema for the result using zod (https://www.npmjs.com/package/zod). we can then use this schema to tell open ai how to format the result
* it will use the descriptions to figure our what to but in each property..
*
*/
const resultSchema = z.object({
name: z.string().describe('The name of the game'),
backgroundPrompt: z.string().describe('A midjourney prompt for the game background image '),
});
const throttleMap = new Map<Function, {throttledFunction: Function; args: any[]}>();
/**
* Lets you call a function and have it throttled by a certain delay.
* Useful for when a function may be spammed!
*
* @example
* ```
* function resize(w, h){
* console.log('resized', w, h);
@GoodBoyDigital
GoodBoyDigital / pixi-performance-tips.txt
Last active June 29, 2023 13:40
Pixi Performance Tips
Global :
- Only optimize when you need to! Pixi can handle a fair amount of content off the bat.
- Be mindful of the complexity of your scene. The more objects you add the slower things will end up.
- Order can help, for example sprite / graphic / sprite / graphic is slower than sprite / sprite / graphic / graphic
- Some older mobile devices run things a little slower. passing in the option 'legacy:true' to the renderer can help with performance
- Culling, is disabled by default as its often better to do this at an application level. If you are GPU it will improve performance, if you are CPU bound - it will degrade performance
Sprites:
- Use spritesheets where possible to minimize total textures
- Sprites can be batched with up to 16 different textures (dependent on hardware)
var ResourceLoader = require('resource-loader'),
textureParser = require('./textureParser'),
spritesheetParser = require('./spritesheetParser'),
spineAtlasParser = require('./spineAtlasParser'),
bitmapFontParser = require('./bitmapFontParser')
// loader = new Loader();
var Loader = function()
{
ResourceLoader.call(this);
FilterManager.prototype.calculateMagixMatrix = function (filterArea, wt)
{
var m = new math.Matrix();
// scale..
var ratio = this.textureSize.height / this.textureSize.width;
m.translate(filterArea.x / (this.textureSize.width), filterArea.y / this.textureSize.height);
m.scale(1 , ratio);
/**
* User: xperiments
* Date: 14/03/13
*/
declare module PIXI
{