Skip to content

Commit

Permalink
Merge pull request #1610 from Mico27/develop
Browse files Browse the repository at this point in the history
Add Animation States To Global Header File
  • Loading branch information
chrismaltby authored Oct 19, 2024
2 parents 6873645 + e0e6186 commit 4d20ea0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add ability to right click a scene to "Run From Here" allowing quick preview of a specific scene. Optionally can only include the selected scenes for faster build previews in large projects.
- Add events "Load Projectile Into Slot" and "Launch Projectile In Slot" to allow more advanced control over setup and launch of projectiles and changing the loaded projectiles at run time
- Add ability to hover over tiles in debugger VRAM preview to see tile memory address information [@pau-tomas](https://github.com/pau-tomas)
- Add animation states to generated `game_globals.h` allowing use from engine code [@Mico27](https://github.com/Mico27)

### Changed

Expand Down
3 changes: 2 additions & 1 deletion src/lib/compiler/compileData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,8 @@ const compile = async (

output["game_globals.h"] = compileGameGlobalsHeader(
variableAliasLookup,
projectData.variables.constants
projectData.variables.constants,
precompiled.stateReferences
);

const variableMap = keyBy(Object.values(variableAliasLookup), "symbol");
Expand Down
8 changes: 7 additions & 1 deletion src/lib/compiler/generateGBVMData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,8 @@ export const compileGameGlobalsInclude = (

export const compileGameGlobalsHeader = (
variableAliasLookup: Record<string, VariableMapData>,
constants: Constant[]
constants: Constant[],
stateReferences: string[]
) => {
return (
`#ifndef GAME_GLOBALS_H\n#define GAME_GLOBALS_H\n\n` +
Expand All @@ -1269,6 +1270,11 @@ export const compileGameGlobalsHeader = (
return `#define ${constant.symbol.toLocaleUpperCase()} ${
constant.value
}\n`;
})
.join("") +
stateReferences
.map((string, stringIndex) => {
return `#define ${string} ${stringIndex}\n`;
})
.join("") +
`\n` +
Expand Down
51 changes: 51 additions & 0 deletions test/compiler/generateGBVMData.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { compileGameGlobalsHeader } from "lib/compiler/generateGBVMData";

describe("compileGameGlobalsHeader", () => {
test("should include variables, constants and state references in global header", () => {
const output = compileGameGlobalsHeader(
{
var1: {
id: "var1",
name: "Variable 1",
symbol: "VAR_1",
isLocal: false,
entityType: "scene",
entityId: "",
sceneId: "",
},
var2: {
id: "var2",
name: "Variable 2",
symbol: "VAR_2",
isLocal: false,
entityType: "scene",
entityId: "",
sceneId: "",
},
},
[
{
symbol: "CONST_0",
id: "const0",
name: "Constant 0",
value: 0,
},
{
symbol: "CONST_1",
id: "const1",
name: "Constant 1",
value: 64,
},
],
["STATE_DEFAULT", "STATE_EXPLODE", "STATE_OPEN"]
);
expect(output).toInclude("VAR_1 0");
expect(output).toInclude("VAR_2 1");
expect(output).toInclude("MAX_GLOBAL_VARS 2");
expect(output).toInclude("CONST_0 0");
expect(output).toInclude("CONST_1 64");
expect(output).toInclude("STATE_DEFAULT 0");
expect(output).toInclude("STATE_EXPLODE 1");
expect(output).toInclude("STATE_OPEN 2");
});
});

0 comments on commit 4d20ea0

Please sign in to comment.