The Thing Component code.

Started by superpirson, September 03, 2014, 08:15:20 PM

Previous topic - Next topic

superpirson

A few weeks ago I set out to make an animated thing library. While what I have works, it requires the creation of a new class of object just to add the animation effect. what would be much more preferable would be to add that functionality in a component, however it seems like as of right now that is not possible given my current design.
components do not seem to have a def structure with Post Load and resolve reference functions, even though they seem to have a CompProperties object called def.
is there something I am missing? Are we unable to extend the ThingComponent class yet?
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB

mrofa

#1
Switching textures wont do ?
Edit:
Not quite sure what you want to add, but you can try simple texture switching in drawmat.
All i do is clutter all around.

superpirson

Quote from: mrofa on September 04, 2014, 01:00:43 AM
Switching textures wont do ?
Edit:
Not quite sure what you want to add, but you can try simple texture switching in drawmat.
actually, that works. I have that working for both map mesh and real time drawers, thing is that I want to create a component so that in the future all people have to do to animate things is just add a single ThingComponent to the thing's def.
This would be great because then you could just attach this component onto anything, instead of having to make a new class for every single thing class you want to animate.


for instance, lets say I want an animated stool. that can be done by simply creating a thing class "AnimatedBuilding" that extends Building. This is what I did.
the problem with that is now I want to make an animated worktable. worktables use the Building_Worktable thing class, not the Building thing class, so in order to animate the worktable, I needed to create a "AnimatedBuilding_Worktable", and use that as the worktable's thing class.
this is a lot of work, so if I could just code a component, then that could do the job of animating without needing a whole new thing class.
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB

mrofa

Hmm i get it, im not sure didnt play with it, did fast search thrugh ilspy and i didnt find the category of comps so if they are not hardcoded, check Verse.ThingComp and ThingCompMaker to see how to use you custom class in comp.
All i do is clutter all around.

superpirson

Quote from: mrofa on September 04, 2014, 04:12:21 PM
Hmm i get it, im not sure didnt play with it, did fast search thrugh ilspy and i didnt find the category of comps so if they are not hardcoded, check Verse.ThingComp and ThingCompMaker to see how to use you custom class in comp.
I do believe I can in-fact make my own comp, it's just I want to be able to run a post-load function for that comp.

basicly, the animated frames are labeled with strings, and thus you can at any time say potato.setFrame("rotting") to be able to change the frame, the idea being that it allows more readable code and defs.

the thing is, to be able to do that efficently, I need to set up a HashTable (see:   https://en.wikipedia.org/wiki/Hash_table), and it would be very bad form for me to have to do that in-game whenever an animated item is spawned; the frames should be registered immeditly when the game is loaded in order to not waist space and speed.

for a def type, this would be done in the PostLoad function, but since thingcomp "defs" aren't actually a def type, I can't do that.
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB

mrofa

Well there is comp everything, CompSpawnSetup, CompApplyDamage maybe there is CompPostLoad.
I cant really help you with PostLoad since i have no idea how it works, its the same with hash tables even thrugh i did read 2 times the wiki page you posted :p

As for registering the state of the frame on load i suggest CompExposeData:D
All i do is clutter all around.

superpirson

Quote from: mrofa on September 04, 2014, 05:49:16 PM
Well there is comp everything, CompSpawnSetup, CompApplyDamage maybe there is CompPostLoad.
I cant really help you with PostLoad since i have no idea how it works, its the same with hash tables even thrugh i did read 2 times the wiki page you posted :p

As for registering the state of the frame on load i suggest CompExposeData:D

I know, hash tables are hard! (the only reason I decided to lean them was because a friend told me about them)
my source is available if you want to look at it, but my code is sloppy as hell. that's kinda why I'm here, I wanted to clean my stuff up!
https://github.com/superpirson/RimWorld-Mod-TrapPack-/

the def postloads are called when the game loads, somewhere. (I couldn't find where, the gameloader is really big)
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB

mrofa

Quotepostloads are called when the game loads, somewhere. (I couldn't find where, the gameloader is really big)

Thing is that its the same with spawnsetup of stuff that are already exist. Its called on load and all its settings are set.
I did encouter this when i did add expose data before spawnsetup in code sctructure :D

All i do is clutter all around.

superpirson

Quote from: mrofa on September 05, 2014, 12:59:38 AM
Thing is that its the same with spawnsetup of stuff that are already exist. Its called on load and all its settings are set.
I did encouter this when i did add expose data before spawnsetup in code sctructure :D

I don't quite understand what you are saying, though I am unfamiliar with exposedata. isn't that used for save/loading?
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB

mrofa

ExposeData save variables when you save the game.
public override void ExposeData()
        {
            base.ExposeData();
            Scribe_Values.LookValue<float>(ref CurRotationInt, "CurrentRotationAngel");
            Scribe_Values.LookValue<bool>(ref Rswitch, "CurrentTotationStatus");
        }

A small example from my hologram, it save the value of CurRotationInt variable when game get saved, and its runned on game load.
Same go for Rswitch it save if its true or false.
Thing is that on load both spawn setup and expose data are called, on which you get depends on you cod struture.
Becsoue i was stupid i had spawnsetup under expose data, so on load i got variable values from spawn setup insted of expose data since spawn setup was called last:D
All i do is clutter all around.

superpirson

Quote from: mrofa on September 05, 2014, 05:45:02 PM
ExposeData save variables when you save the game.
public override void ExposeData()
        {
            base.ExposeData();
            Scribe_Values.LookValue<float>(ref CurRotationInt, "CurrentRotationAngel");
            Scribe_Values.LookValue<bool>(ref Rswitch, "CurrentTotationStatus");
        }

A small example from my hologram, it save the value of CurRotationInt variable when game get saved, and its runned on game load.
Same go for Rswitch it save if its true or false.
Thing is that on load both spawn setup and expose data are called, on which you get depends on you cod struture.
Becsoue i was stupid i had spawnsetup under expose data, so on load i got variable values from spawn setup insted of expose data since spawn setup was called last:D
I see, so that is how it works! thank you!
too bad I can't use it, that gets called each time an thing gets loaded, not when a def gets loaded by the gameloader at the main menu.
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB

mrofa

For getting stuff on mod load you would need to hack Argain or Rawcode brains ;p
All i do is clutter all around.

superpirson

Quote from: mrofa on September 06, 2014, 03:04:10 AM
For getting stuff on mod load you would need to hack Argain or Rawcode brains ;p
well, the def postload functions are called on mod load, but that's just my problem, comp properties don't have postload functions to use! you're right, I think I need some major help here.

the only thing is, the vanilla game implements almost everything in comps, and for a good reason: comps are extremely versatile and much cleaner than just creating a new class for every object! the only problem is that the way comp properties are done, it's almost like they're hard coded. I can't really do all that much with comp properties class, and I really think that I should be doing everything in there.
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB

StorymasterQ

I see that "CurrentRotationAngel" and am reminded of the Rouge Angles of Satin.
I like how this game can result in quotes that would be quite unnerving when said in public, out of context. - Myself

The dubious quotes list is now public. See it here

superpirson

Quote from: StorymasterQ on September 07, 2014, 09:36:32 PM
I see that "CurrentRotationAngel" and am reminded of the Rouge Angles of Satin.
I'll admit, this helped quite a bit with the frustration  :)
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB