Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objectify EGP #2646

Merged
merged 36 commits into from
Nov 3, 2023
Merged

Objectify EGP #2646

merged 36 commits into from
Nov 3, 2023

Conversation

Denneisk
Copy link
Member

@Denneisk Denneisk commented Jun 23, 2023

Makes EGP Objects a type, xeo or egpobject.
Copies nearly every EGP function to an xeo: version.
Adds fields (EGP) and methods (EditObject, Set, SetPos) to EGP Objects to perform specific actions when needed.

Polys, PolyOutlines, Lines, and LineStrips now have x, y, and angle and can be set accordingly. Internally this simply translates the vertices.

Simplified a bunch of things related to EGP object position.

EGP Object classes now inherit each other when applicable. Far more extensible and readable this way.

Unique functionality:
EGP Objects can now be created using tables to quickly initialize them.

MyEGPObject = EGP:egpBox(1, table())
MyEGPObject:egpPos(100, 200)
MyEGPObject:egpSize(100, 100)

MyOtherEGPObject = EGP:egpText(2, table("text" = "Hello, World!", "x" = 256, "y" = 256))

You can modify EGP Objects in a single operation using egpobject:modify(table).

MyEGPObject = EGP:egpText(1, "", vec2())
MyEGPObject:modify(table("text" = "I can eat glass", "g" = 0, "b" = 0)) # Changes the text content and makes it red

You can use array indexing on EGP Objects to get/set object fields.

MyEGPObject = EGP:egpBox(1, vec2(50, 100), vec2(60, 120))
print(MyEGPObject["x", number]) # prints 50
MyEGPObject["w", number] = 100
MyEGPObject["h"] = 200 # Implicitly typed for less keystrokes; still gets typechecked
print(MyEGPObject:egpSize()) # prints [100, 200]

With EGP Objects, you can use egpCopy between two different screens.

Box = EGP_1:egpBox(1, vec2(), vec2(50)) # Create a box at 0, 0
EGP_2:egpCopy(1, Box) # Copies the properties of Box to EGP_2

You can remove (hide) EGP objects from the screen while still being able to use and update their values.

if(HiddenElement:containsPoint(EGP:egpCursor())) {
    HiddenElement:draw()
} else {
    HiddenElement:hide()
}

Test code:
Features (Regression)
Operators

@Denneisk Denneisk marked this pull request as ready for review July 18, 2023 17:57
@Denneisk
Copy link
Member Author

Denneisk commented Aug 4, 2023

Can't forget that I've yet to document every function.

Genericized EGP object creation functions (will be used later for indexless functions)
Add xwl:egpHasObject(xeo)
Fixed removed EGP objects not equal to NULL
Method will be removed in a later PR
@Denneisk
Copy link
Member Author

Would appreciate some eyes on this as I'd like to start refactoring the entirety of EGP after this.

- Added wirelink:egpCreate, creates an EGP Object prototype that is not initialized
  - Added egpobject:initialize to initialize EGP Object prototypes
- Added xeo:unload(), removes the object while keeping its object intact
  - Added xeo:isLoaded() to see if object is initialized
- Added xeo:egpIndex(n) to set and replace indexes of EGP Objects
- Added xeo:egpSize(nn), :egpPos(nn), :egpPos(nnn) to better facilitate moving operations
- Added xeo:egpPosAng(), returns vector of x, y, angle
- Added xeo:egpPos(nnnn), sets x, y, x2, and y2 for lines
- Added xeo:egpSetVertices(...), sets vertices of EGP Object
- Added xeo:egpCopy(xeo) to copy one EGP object to another
- Added angle to EGP baseObj and baseObj:SetPos
- Nodiscard a bunch of functions
- Changed EGP.Objects to use lowercase name in most cases
- Bug fix for xwl:egpParent(xeoxeo)
- Deduplicated some E2Descriptions
@Denneisk
Copy link
Member Author

Denneisk commented Sep 7, 2023

I'm getting desperate here so enjoy this lovely content update.

- Added auto-generated egp<Type>(index, table) constructors, replaces egpCreate
- Added xeo:draw/:hide, replaces :initialize/:unload
- Moved NULL_EGPOBJECT as a field of EGP
- Made EGP:CreateObject() never return nil
- Fixed some EGP functions erroneously returning nil
- Changed xeo:egpOrderAbove/:egpOrderBelow to use EGP objects instead of index
@Vurv78
Copy link
Contributor

Vurv78 commented Sep 9, 2023

I feel like all the xeo methods should have the :egp prefix removed / replaced with set/get, so egpOrder -> setOrder / getOrder. Only reason why that prefix exists for wirelink is because wirelink isn't just egp

@Denneisk
Copy link
Member Author

Denneisk commented Sep 9, 2023

I feel like all the xeo methods should have the :egp prefix removed / replaced with set/get, so egpOrder -> setOrder / getOrder. Only reason why that prefix exists for wirelink is because wirelink isn't just egp

I agree. I was just worried that it would be a bit annoying when translating from indexed EGP to object EGP to have to learn new function names. I'll clean it up since you mentioned it and I already broke that rule.

Add xeo:parent(), returns parent object
Minor fixes and optimizations, chiefly with function returns
Remove xeo:egpIndex(n), indexes should be irrelevant
Removed redundant xeo:egpObjectType() that I swore I already removed
+Other miscellaneous fixes to make this work.
Fix getMaterial returning entity.
@Denneisk
Copy link
Member Author

Denneisk commented Sep 11, 2023

Okay I'll try to stop adding things now.

@Denneisk
Copy link
Member Author

Denneisk commented Sep 12, 2023

Actually I still have one thing left to do but maybe I'll save that for the refactor (add parent object reference to objects).

@thegrb93
Copy link
Contributor

thegrb93 commented Oct 26, 2023

Actually I still have one thing left to do but maybe I'll save that for the refactor (add parent object reference to objects).

Just ping when its ready. I think we'll have to assume its been tested and will review the code only to make sure everything looks safe.

@Denneisk
Copy link
Member Author

Denneisk commented Oct 26, 2023

No, trust me, I'll end up rewriting a quarter of EGP if I do start.

The code is already working and passable. I want to do things slowly in hopes that it makes your job a little easier.

Massively simplify global pos getting
Split getting global vertices into different function
Fixed bad egpo indexget
Harden EGPObjects against bad inputs
Change some small syntax things
+ minor change of local scope
@thegrb93
Copy link
Contributor

This ready to be looked at again?

@Denneisk
Copy link
Member Author

Should be fine now.

@thegrb93 thegrb93 merged commit d4fd71f into wiremod:master Nov 3, 2023
1 check failed
@Denneisk Denneisk deleted the egp-objectify branch November 8, 2024 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants