Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Finalized Project
Browse files Browse the repository at this point in the history
-Added in Example Room/Object
-Added in lwo_clear() function
-Cleaned up with regions
-Inserted readme.md with basic function descriptions
  • Loading branch information
tabularelf committed Aug 20, 2020
1 parent 4e37609 commit ed89ad1
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 44 deletions.
1 change: 1 addition & 0 deletions LWO.yyp

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

4 changes: 4 additions & 0 deletions objects/obj_engine/Create_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// @description Init LWO Instances
repeat(100) {
lwo_create(new lwo_test(irandom(1024),irandom(1024)));
}
2 changes: 2 additions & 0 deletions objects/obj_engine/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// @description Process LWO
lwo_process(lwoEvents.DRAW);
2 changes: 2 additions & 0 deletions objects/obj_engine/Draw_64.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// @description Draw FPS
draw_text(8,8,"FPS: " + string(fps) + " : " + string(fps_real));
35 changes: 35 additions & 0 deletions objects/obj_engine/obj_engine.yy

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

42 changes: 42 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div align="center">

# LWO v1.0 - Light Weight Objects for GameMaker Studio 2.3.0
</div>

This is a system I'm designing to use as light weight objects for some of my upcoming projects. These take advantage of GameMaker's newly featured structs, and allows you to make entire objects out of them.


## Functions
`lwo_create(struct)`

Provides the necessary information via said struct, adding it to the LWO System. Returns struct.

i.e.

`lwo_create(new lwo_test(x,y));`



`lwo_count()`

Returns the current number of LWO instances.

`lwo_find(id)`

Returns the specific struct if found. Otherwise returns undefined.

`lwo_destroy([id],[execute destroy (bool)])`

Destroys struct with either ID provided, or will obtain current ID executing it.

`lwo_process(event)`

Processes all LWO specific events. Currently step and draw events are supported only. Though it's recommended to only use one of the two, as processing multiple events degrades performance.

`lwo_free()`

Only use when you absolutely no longer need LWO system. Will free the LWO system from memory. As of currently, there's no way to recreate the LWO System besides restarting the game.

`lwo_clear()`

Removes all structs from memory.
8 changes: 6 additions & 2 deletions rooms/rm_test/rm_test.yy

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

84 changes: 45 additions & 39 deletions scripts/lwo_system/lwo_system.gml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ global.__lwo_system = {
lwo_map : ds_map_create(),

// Functions
lwo_sys_delete : function() {
lwo_sys_clear : function() {
if (ds_list_size(lwo_list) > 0) {
var _size = lwo_counter;
for(var _i = 0; _i < _size; ++_i) {
delete(lwo_list[| 0]);
ds_list_delete(lwo_list,0);
}
}

}
},

lwo_sys_delete : function() {
lwo_clear();
ds_map_destroy(lwo_map);
ds_list_destroy(lwo_list);
//ds_list_destroy(lwo_list_inactive);
Expand Down Expand Up @@ -85,7 +88,7 @@ function lwo_find(_id) {

/// @function lwo_create
/// @param struct
/// @description Use case: lwo_create(new lwo_test(x,y)). This is to ensure that the lwo instance is properly added to the system.
/// @description Use case: lwo_create(new lwo_test(x,y)). This is to ensure that the lwo instance is properly added to the system. Returns struct.
function lwo_create(_lwo) {
// Give it an ID
_lwo.id = global.__lwo_system.lwo_ids++;
Expand All @@ -99,48 +102,17 @@ function lwo_create(_lwo) {
//ds_queue_clear()
return _lwo;
}

/// @function lwo_process
/// @param event
/// @description Processes all instances with the appropriate event. Currently step and draw are supported.
function lwo_process(_event) {
var _size = global.__lwo_system.lwo_counter;
var _list = global.__lwo_system.lwo_list;

// Loop
for(global.__lwo_system.lwo_pos = 0; global.__lwo_system.lwo_pos < _size; ++global.__lwo_system.lwo_pos) {
var _lwo = _list[| global.__lwo_system.lwo_pos];
//show_debug_message(global.__lwo_system.lwo_pos);
//show_debug_message(_lwo);
if is_undefined(_lwo) {
ds_list_delete(_list,global.__lwo_system.lwo_pos);
--_size;
--global.__lwo_system.lwo_pos;
//--global.__lwo_system.lwo_pos;
--global.__lwo_system.lwo_counter;
} else {
// Check for Event Type and execute base upon type
var _func = undefined;
switch(_event) {
case lwoEvents.STEP: _func = _lwo.e_step; break;
case lwoEvents.DRAW: _func = _lwo.e_draw; break;
}

if is_method(_func) {
_func();
}//*/

//_lwo.e_draw();//draw_sprite_ext(spr_test,0,_lwo.x,_lwo.y,1,1,0,_lwo.blend,1);
}
}
}

/// @function lwo_free
/// @description ONLY USE WHEN YOU CLOSE THE PROGRAM!!! lwo_free simply removes the lwo_system from memory, along with all instances.
function lwo_free() {
global.__lwo_system.lwo_sys_delete();
delete global.__lwo_system;
}

function lwo_clear() {
global.__lwo_system.lwo_sys_clear();
}

/// @function lwo_free
/// @param [id]
Expand Down Expand Up @@ -172,5 +144,39 @@ function lwo_destroy() {
ds_map_delete(global.__lwo_system.lwo_map,_idd);
}
}


/// @function lwo_process
/// @param event
/// @description Processes all instances with the appropriate event. Currently step and draw are supported.
function lwo_process(_event) {
var _size = global.__lwo_system.lwo_counter;
var _list = global.__lwo_system.lwo_list;

// Loop
for(global.__lwo_system.lwo_pos = 0; global.__lwo_system.lwo_pos < _size; ++global.__lwo_system.lwo_pos) {
var _lwo = _list[| global.__lwo_system.lwo_pos];
//show_debug_message(global.__lwo_system.lwo_pos);
//show_debug_message(_lwo);
if is_undefined(_lwo) {
ds_list_delete(_list,global.__lwo_system.lwo_pos);
--_size;
--global.__lwo_system.lwo_pos;
//--global.__lwo_system.lwo_pos;
--global.__lwo_system.lwo_counter;
} else {
// Check for Event Type and execute base upon type
var _func = undefined;
switch(_event) {
case lwoEvents.STEP: _func = _lwo.e_step; break;
case lwoEvents.DRAW: _func = _lwo.e_draw; break;
}

if is_method(_func) {
_func();
}
}
}
}

#endregion
19 changes: 16 additions & 3 deletions scripts/lwo_test/lwo_test.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

function lwo_test(_x, _y) : lwo_struct() constructor {

// Create Event
#region Create Event
x = _x;
y = _y;
z = 100;
xstart = _x;
ystart = _y;
blend = make_color_hsv(irandom(255),irandom(255),255);
timer = irandom(60*100);
#endregion

#region Destroy Event
// We also have control of the hidden destroy event.
e_destroy = LWO_EVENT_START
show_debug_message("Goodbye cruel world! " + string(id));
LWO_EVENT_END


#endregion
#region Step Event
// Commented out by default as there's some performance losses when processing more than one event.
// I've yet to find a more optimial solution, but this seems to be more of an issue in regards to
// Function calls. Which is a bummer, given that this system was meant to be fairly easy to
Expand All @@ -29,12 +32,22 @@ function lwo_test(_x, _y) : lwo_struct() constructor {
y = ystart + (sin(current_time/100)*2);
LWO_EVENT_END*/
#endregion

#region Draw Event
// Draw Event
e_draw = LWO_EVENT_START

//matrix_set(matrix_world,matrix_build(x,y,z,0,0,0,1,1,1));
draw_sprite_ext(spr_test,0,x + (cos(current_time/100)*2),y + (sin(current_time/100)*2),1,1,0,blend,1);

// We have a timer to it's ultimate demise.
if (timer == 0) {
lwo_destroy();
} else {
--timer;
}

LWO_EVENT_END
#endregion
}

0 comments on commit ed89ad1

Please sign in to comment.