Skip to content

Commit

Permalink
Evacuates global namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
JujuAdams committed May 27, 2023
1 parent 3cf45ab commit cea28ae
Show file tree
Hide file tree
Showing 58 changed files with 479 additions and 393 deletions.
34 changes: 18 additions & 16 deletions Cardboard.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion scripts/CardboardBatchAutoGet/CardboardBatchAutoGet.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

function CardboardBatchAutoGet()
{
return global.__cardboardAutoBatching;
__CARDBOARD_GLOBAL

return _global.__autoBatching;
}
7 changes: 3 additions & 4 deletions scripts/CardboardBatchAutoGet/CardboardBatchAutoGet.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion scripts/CardboardBatchAutoSet/CardboardBatchAutoSet.gml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

function CardboardBatchAutoSet(_state)
{
global.__cardboardAutoBatching = _state;
__CARDBOARD_GLOBAL

_global.__autoBatching = _state;
}
7 changes: 3 additions & 4 deletions scripts/CardboardBatchAutoSet/CardboardBatchAutoSet.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 21 additions & 16 deletions scripts/CardboardBatchForceSubmit/CardboardBatchForceSubmit.gml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@

function CardboardBatchForceSubmit()
{
if (global.__cardboardBuildingModel) __CardboardError("Cannot force submit a batch whilst creating a model");
__CARDBOARD_GLOBAL

//Don't do anything we know this batch is empty
if (global.__cardboardBatchTexturePointer == undefined) return;

//Submit the batch we have
vertex_end(global.__cardboardBatchVertexBuffer);
vertex_submit(global.__cardboardBatchVertexBuffer, pr_trianglelist, global.__cardboardBatchTexturePointer);
vertex_delete_buffer(global.__cardboardBatchVertexBuffer);

//Clear the batch's texture state
global.__cardboardBatchTexturePointer = undefined;
global.__cardboardBatchTextureIndex = undefined;

//Then start the vertex buffer again!
global.__cardboardBatchVertexBuffer = vertex_create_buffer();
vertex_begin(global.__cardboardBatchVertexBuffer, global.__cardboardVertexFormat);
with(_global)
{
if (__buildingModel) __CardboardError("Cannot force submit a batch whilst creating a model");

//Don't do anything we know this batch is empty
if (__batchTexturePointer == undefined) return;

//Submit the batch we have
vertex_end(__batchVertexBuffer);
vertex_submit(__batchVertexBuffer, pr_trianglelist, __batchTexturePointer);
vertex_delete_buffer(__batchVertexBuffer);

//Clear the batch's texture state
__batchTexturePointer = undefined;
__batchTextureIndex = undefined;

//Then start the vertex buffer again!
__batchVertexBuffer = vertex_create_buffer();
vertex_begin(__batchVertexBuffer, __vertexFormat);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

function CardboardBatchNewVertexBuffer(_texture)
{
if (global.__cardboardBuildingModel) __CardboardError("Cannot use CardboardBatchNewVertexBuffer() whilst a model is being built\nUse CardboardModelNewVertexBuffer() to instead");
__CARDBOARD_GLOBAL

if (_global.__buildingModel) __CardboardError("Cannot use CardboardBatchNewVertexBuffer() whilst a model is being built\nUse CardboardModelNewVertexBuffer() to instead");

CardboardBatchForceSubmit();

global.__cardboardBatchTexturePointer = _texture;
global.__cardboardBatchTextureIndex = undefined;
_global.__batchTexturePointer = _texture;
_global.__batchTextureIndex = undefined;

return global.__cardboardBatchVertexBuffer;
return _global.__batchVertexBuffer;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions scripts/CardboardBillboardYawGet/CardboardBillboardYawGet.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Returns the yaw angle used for Cardboard's billboarded sprites

function CardboardBillboardYawGet()
{
__CARDBOARD_GLOBAL

return _global.__billboardYaw;
}
11 changes: 11 additions & 0 deletions scripts/CardboardBillboardYawGet/CardboardBillboardYawGet.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions scripts/CardboardModelBegin/CardboardModelBegin.gml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

function CardboardModelBegin()
{
if (global.__cardboardBuildingModel) __CardboardError("Only one model can be created at a time");
__CARDBOARD_GLOBAL

if (_global.__buildingModel) __CardboardError("Only one model can be created at a time");

__CardboardBatchComplete();

global.__cardboardBuildingModel = true;
global.__cardboardModel = new __CardboardClassModel();
_global.__buildingModel = true;
_global.__model = new __CardboardClassModel();
}
7 changes: 3 additions & 4 deletions scripts/CardboardModelBegin/CardboardModelBegin.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions scripts/CardboardModelEnd/CardboardModelEnd.gml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

function CardboardModelEnd()
{
if (!global.__cardboardBuildingModel) __CardboardError("No model has been created");
__CARDBOARD_GLOBAL

if (!_global.__buildingModel) __CardboardError("No model has been created");

__CardboardBatchComplete();

var _model = global.__cardboardModel;
var _model = _global.__model;

global.__cardboardBuildingModel = false;
global.__cardboardModel = undefined;
_global.__buildingModel = false;
_global.__model = undefined;

return _model;
}
7 changes: 3 additions & 4 deletions scripts/CardboardModelEnd/CardboardModelEnd.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

function CardboardModelNewVertexBuffer(_texture)
{
if (!global.__cardboardBuildingModel) __CardboardError("Cannot use CardboardModelNewVertexBuffer() when a model is not being built\nUse CardboardBatchNewVertexBuffer() to instead");
__CARDBOARD_GLOBAL

global.__cardboardModel.__AddBatch();
if (!_global.__buildingModel) __CardboardError("Cannot use CardboardModelNewVertexBuffer() when a model is not being built\nUse CardboardBatchNewVertexBuffer() to instead");

global.__cardboardBatchTexturePointer = _texture;
global.__cardboardBatchTextureIndex = undefined;
_global.__model.__AddBatch();

return global.__cardboardBatchVertexBuffer;
_global.__batchTexturePointer = _texture;
_global.__batchTextureIndex = undefined;

return _global.__batchVertexBuffer;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions scripts/CardboardModelSubmit/CardboardModelSubmit.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

function CardboardRenderStateReset()
{
__CARDBOARD_GLOBAL

//If we've got a pending batch then submit that before resetting draw state
CardboardBatchForceSubmit();

Expand All @@ -12,7 +14,7 @@ function CardboardRenderStateReset()
gpu_set_alphatestenable(false);

//Restore the old matrices we've been using
matrix_set(matrix_world, global.__cardboardOldWorld);
matrix_set(matrix_view, global.__cardboardOldView);
matrix_set(matrix_projection, global.__cardboardOldProjection);
matrix_set(matrix_world, _global.__oldRenderStateMatrixWorld);
matrix_set(matrix_view, _global.__oldRenderStateMatrixView);
matrix_set(matrix_projection, _global.__oldRenderStateMatrixProjection);
}
Loading

0 comments on commit cea28ae

Please # to comment.