|
Rocko Bonaparte posted:I mean, yeah, but that "easily" there is doing a lot of work. Not really; it took about 10 minutes. (But about twice as long to write the unit tests.)
|
# ? Nov 9, 2022 07:33 |
|
|
# ? Jun 8, 2024 06:32 |
|
God drat. I'd have looked at it already but it was 1:30AM and I was telling myself if I touched that, I wouldn't be going to bed until 3AM, and I'm trying to actually wake up at a normal time again.
|
# ? Nov 9, 2022 21:19 |
|
If you grabbed it, I just pushed a couple changes to brush it up, correct some minor issues, and add documentation.
|
# ? Nov 9, 2022 22:25 |
|
Imma try but it'll probably be my self-imposed bedtime again before I can crack the lid on it. Edit: Got my paws on it but my scheduler implementation is borked thanks to Newtonsoft.Json dependency hell with Unity and I hit my quota for the night dealing with that. I'm going to try my best to compare the implementations over the extended weekend. Rocko Bonaparte fucked around with this message at 08:39 on Nov 10, 2022 |
# ? Nov 10, 2022 07:03 |
|
Hey all, got a C# question hoping someone can help out! I'm trying to store some data in a similiar manner to a JSON object ala: code:
code:
so i'm hoping somoene can point me in the right direction or help me out as to what I need to do thanks goons
|
# ? Nov 11, 2022 03:05 |
Is it for a one-off thing or a program you expect to be using and extending a lot in the future? What will be consuming the data, your own program or something else that you don't control? Will you be reading the data or only writing? If it's something you expect to be developing further and using/extending, it's probably worth it to design a data model in C# classes that describes the data, and then set up serialization with some JSON library. If it's just a one-off, maybe you're fine just doing something with lists of dictionaries or similar awkward stuff.
|
|
# ? Nov 11, 2022 03:47 |
|
I guess it's for a long term project - it's a little game I'm working on. Basically these objects tie to a songs run time and when the time comes up, I have it reference this table. That said if there's a different better way to do it I'm all ears
|
# ? Nov 11, 2022 04:19 |
If it's only for your own use, and not making data for someone else's game, then definitely start out defining an object model for your data in C# that makes sense to use for your game code. When you have the object model, you can look at ways to serialize it using standard libraries.
|
|
# ? Nov 11, 2022 05:47 |
|
worms butthole guy posted:I'm trying to store some data in a similiar manner to a JSON object-- I would personally recommend using Newtonsoft's Json.NET until you reach a point that you know you have a reason not to use it (which does happen).
|
# ? Nov 11, 2022 07:59 |
|
worms butthole guy posted:I guess it's for a long term project - it's a little game I'm working on. Basically these objects tie to a songs run time and when the time comes up, I have it reference this table. Even if it's just once off, it's often better to have a clearly specified data structure. code:
maps more or less to: code:
TheBlackVegetable fucked around with this message at 09:24 on Nov 11, 2022 |
# ? Nov 11, 2022 09:18 |
|
Sweet thank you all so much. When I try it out later I'll report back
|
# ? Nov 11, 2022 13:30 |
|
So I tried the above suggestions and I think I got closer to what I was trying to accomplish...I think. And i'm stuck again . So I ended up with:code:
code:
|
# ? Nov 12, 2022 04:53 |
|
worms butthole guy posted:So I tried the above suggestions and I think I got closer to what I was trying to accomplish...I think. And i'm stuck again . So I ended up with: shouldn’t that be Beat == beat?
|
# ? Nov 12, 2022 05:19 |
|
No, he's newing up an object with the idea of using it as an equality test, but there aren't correct equality operators on the object. I can add more tomorrow but I have to get to bed
|
# ? Nov 12, 2022 06:11 |
|
worms butthole guy posted:So I tried the above suggestions and I think I got closer to what I was trying to accomplish...I think. And i'm stuck again . So I ended up with: It won’t match a new instance of a class. use .Any() or Where() code:
|
# ? Nov 12, 2022 06:15 |
|
worms butthole guy posted:So I tried the above suggestions and I think I got closer to what I was trying to accomplish...I think. And i'm stuck again . So I ended up with: That’s not going to work. You’re creating a new ChartMap and asking the Gems list if it contains this new object you just created, which it won’t. The Contains method doesn’t know you just want to compare on the Beat field, and compares actual objects to each other. What you want instead is Gems.Any(gem => gem.Beat == beat) Here you’re invoking a different method, Any, and specifying a comparison operation which will return true as soon as it’s met. The Any method iterates over all the gems in your Gems list, puts the current one in the gem variable that’s been defined inside the call to Any, and invokes the comparison you defined, which is to compare the beat of the current gem to the beat that you’re comparing against. As soon as that’s true, it breaks out and returns true. If you want the actual gem which matches your beat, then instead of Any, which will just tell you that a match exists, you can call FirstOrDefault instead, which will give you the actual gem which matches the beat tier looking for, or null if there’s no match
|
# ? Nov 12, 2022 06:21 |
|
My brain is screaming at me: will the loc ever change or be more than two values? Because why is it a list and not an array (immutable even)? If it’s [beginning, end] then being able to use deconstruction and having more guarantees it’s going to be just those two elements will probably be nice to have.
|
# ? Nov 12, 2022 10:29 |
|
Throw my sleep schedule under the bus so here I am:biznatchio posted:If you grabbed it, I just pushed a couple changes to brush it up, correct some minor issues, and add documentation. I started screwing around with it in earnest. A superficial experiment with it and the PriorityQueue's GenericPriorityQueue had the generic queue running six times as fast for me. This was with a test where I pre-loaded each with 50 entries of the same random garbage, and then ran each 100,000 times. In the iteration, I'd give them each 50 more of the matching random garbage, and then dequeue 50 entries. I was kind of surprised since a basic read of .NET's own PriorityQueue states it's "an array-backed, quaternary min-heap." I guess I was focusing on the "array-backed" part of that instead of the "quaternary min-heap" part of that. The GenericPriorityQueue is just using a flat array. I had to pre-set it with a capacity and the world ends if I exceed it. That's RAM I'm eating no matter what and maybe I should reconsider that. So I guess there's some apples-to-oranges going on here. Edit: I should probably just favor the FxPriorityQueue unless I find a specific reason I really need a straight array-based heap.
|
# ? Nov 12, 2022 10:33 |
|
worms butthole guy posted:So I tried the above suggestions and I think I got closer to what I was trying to accomplish...I think. And i'm stuck again . So I ended up with: Apart from the other advice, I see that you're using a List<int> for what I assume to be a coordinate? Depending on what you want to do with it I'd say you might want to change that to a Point so you can actually use X/Y coords.
|
# ? Nov 12, 2022 14:39 |
|
Thank you all for the help. Yeah I have no idea about the types and such in C# so any area of "you should do it this way" is very very helpful lol. Essentially the goal is that anytime the times pan changes it looks up this table of data, gets the equivalent time span (concerted to string) and then returns the data back for it to render at the loc and the note corresponds to what sprite. With JavaScript ID do it with a json object but I wasn't sure what the best way was to do it in c# either by efficiency or in general structure. That said I also don't have much knowledge in OOP so I'm using this as a opportunity to learn that too lol. Thanks goons edit: This is what I did and it works! code:
code:
worms butthole guy fucked around with this message at 15:42 on Nov 12, 2022 |
# ? Nov 12, 2022 14:45 |
|
does the "else" clause in GrabNote() ever get exercised? GrabNote() has two different behaviours. One of them leads to it returning an object[] with three elements that are all integers. The other one leads to it returning an object[] with two elements; the first is an integer and the second one is a Point. The other code snippet you shared is going to break if the "else" branch is chosen, because it tries to cast beatTF[1] to an int (which will fail) and because it tries to access beatTF[2] (which doesn't exist). Should the else clause perhaps return new object[] {0, 0, 0} instead? At that point you could dispense with the casting to integers because you could just declare it as returning int[] instead. To hazard a guess, you changed the return-type declaration to object[] because the compiler was telling you that you couldn't return a mixed-type array without doing that. You could even dispense with arrays and declare it as returning (int Note, int X, int Y).
|
# ? Nov 12, 2022 15:58 |
|
code:
code:
Hammerite fucked around with this message at 16:09 on Nov 12, 2022 |
# ? Nov 12, 2022 16:04 |
|
Wow good catch and yeah 100% thank you. I think I could nix the else statement tbh cuz it wouldn't use that data. I tried using vars before but got errors. Although maybe I didn't import a library to use them or something. Thank you so mucj
|
# ? Nov 12, 2022 17:27 |
|
"var" is native to C# itself, and is cool and good to use as often as you can. It tells the language "use the best datatype you can for this", and the only real complaint against it is developers have to actually mouse-over the word "var" to see what the compiler is choosing. If you're getting errors, it's because you're trying to assign incompatible things to it in different branches, and that's an actual error. It's far better to catch those at compile time instead of runtime. As for your project, if these gems are supposed to be appearing at timestamps, it makes sense to me anyway to use a Stack, ordered by timestamp. You can continually Peek() the top item on the Stack, and look at its timestamp value. If the timestamp hasn't passed yet, move on. If it is time to do something with it, Pop that item and get to work rendering your gem. This will help prevent looking at items that have already been rendered (since you've Popped them), and will also stop you from looking ahead on items that aren't anywhere ready to be rendered (since you only ever Peek at the first item that's remaining).
|
# ? Nov 12, 2022 18:11 |
|
Thanks insta. I went back in and var worked this time so I used that more. I didn't know it was so "acceptable" to use it alot, figured it was the C# equivalent of "any" which is kinda shunned upon lol. Didn't know about Stacks either, will check that out. Thank you!
|
# ? Nov 12, 2022 22:01 |
|
worms butthole guy posted:Thanks insta. I went back in and var worked this time so I used that more. I didn't know it was so "acceptable" to use it alot, figured it was the C# equivalent of "any" which is kinda shunned upon lol. You actually might want a Queue, which is the opposite order: First in, first out. Stacks are first in, last out. It depends on what you're doing with the contents of the data structure. Stacks and queues are appropriate for guaranteed ordering based on insertion sequence, which certainly sounds like your use case. var just means "let the compiler figure it out". It's still typed. You can also do instantiation without specifying the type on the right hand side if you provide it on the left-hand side: List<int> foo = new().
|
# ? Nov 12, 2022 23:00 |
|
drat it's crazy how many types C# has lol. Yeah I was wondering if a stack would work but good to know about queue
|
# ? Nov 12, 2022 23:04 |
|
Really the point I was going for was to add them to an ordered data structure and only Peek the first element. Pop it when it's time to actually use it, then resume Peeking again. You never have to actually traverse the storage and you're only comparing one item per game loop instead of potentially hundreds. You're also not looking at items you've already used, nor are you going to be looking at items later on than the next one (if you're only 2 minutes into the game, why are you caring about any of the gems with a 4 minute timestamp?)
|
# ? Nov 13, 2022 05:21 |
|
New Yorp New Yorp posted:Stacks are first in, last out.
|
# ? Nov 13, 2022 22:14 |
|
Fiend posted:* LIFO? Yeah wtf is wrong with me
|
# ? Nov 13, 2022 22:36 |
|
hello back with a stupid question :v I have a bit of code that does this (the below is pseudo code): code:
code:
Thanks Goons
|
# ? Nov 19, 2022 22:55 |
|
worms butthole guy posted:The issue i'm having is that if I run this code, I can see the "Activated" property being changed to true, however it doesn't persist outside of that function. I tried returning the gem object also but no dice....what am I missing? What do you mean by “doesn’t persist”? Does gem.Activated return false? If so, the gem object is encapsulated in the Sky class, is that being persisted? Or are you talking about something like a data binding not being updated? If that’s the case, it’s because the Activated property is not observable, so when its value changes bindings are not updated. It needs to implement INotifyPropertyChanged.
|
# ? Nov 20, 2022 00:42 |
|
That shouldn't happen based on the code you posted. I suspect that one of two things is happening: 1. you are setting gem.Activated somewhere else and that code is running before you inspect the state 2. you are overwriting Sky.gem somewhere else and that code is running before you inspect the state To test for (1), one approach you could take is to make gem.Activated's setter private*, build, and check all the lines that are broken. To test for (2), make Sky.gem readonly** and then do the same thing. * public bool Activated {get; private set;} ** private readonly Gem gem;
|
# ? Nov 20, 2022 00:46 |
|
doh I think I figured it out thanks to both of you - I realized i'm overwriting gem every draw update. I still haven't figured out the best way to spawn something and not have it keep spawning over itself but that's my bad lol. still need to figure out OOP better. Thanks you two!
|
# ? Nov 20, 2022 01:00 |
|
worms butthole guy posted:doh I think I figured it out thanks to both of you - I realized i'm overwriting gem every draw update. I still haven't figured out the best way to spawn something and not have it keep spawning over itself but that's my bad lol. still need to figure out OOP better. Add a flag to the object that holds your thing so you can do if (!thingHasSpawned && otherRelevantConditions) { spawnTheThing(); }; // we assume spawnTheThing() sets thingHasSpawned to true. If your program is particularly simple the flag could be the variable itself, like if (this.thing is null && otherRelevant conditions) { spawnTheThing(); };
|
# ? Nov 20, 2022 02:03 |
|
Kyte posted:Add a flag to the object that holds your thing so you can do if (!thingHasSpawned && otherRelevantConditions) { spawnTheThing(); }; // we assume spawnTheThing() sets thingHasSpawned to true. Thank you for this! Doing some research it seems like most things say to add your object to a List and render based off of that ala: code:
sorry for all the questions but you folks have been tremendously helpful in this little pet project of mine
|
# ? Nov 20, 2022 03:13 |
|
I don't know what framework you're using to implement this project so I can't really comment on the best way to use that framework. It seems to me, based on what you've posted, that you may be trying to keep track of the business logic of the game from within the graphics code and/or the user input code. I don't know what a Gem or a Sky represents so it's difficult to say that with confidence, but that is what it looks like. You might benefit from separating the state of the game world from the graphics and user interaction code more than you currently are. Hopefully your framework has an established way of doing that. Perhaps you can find documentation (from the framework authors or from other users) discussing this sort of thing. This idea of separating concerns is a well-established principle in modern programming and comes in various flavours. For example, in WPF it is common to use the MVVM (model-view-viewmodel) approach, and in web programming the MVC (model-view-controller) approach is well known. They are different, but similar in that the basic goal is to decouple presentation and user interaction from the core logic of the application.
|
# ? Nov 20, 2022 13:56 |
|
Huh yeah I deal with MVC daily in my professional life, not sure why I didn't apply it to this. That would seem to solve some of the issues lol. I guess that's also where the ECS system could come into play also. I did run into that stupid issue of things not updating again and i'm pretty sure it's now due to that and like you said - tieing it to the game logic instead of render logic. Sweet thanks all. I shouldve made my fun project learnign WPF lmao.
|
# ? Nov 20, 2022 14:21 |
|
Hammerite posted:I don't know what framework you're using to implement this project so I can't really comment on the best way to use that framework. omg you're a genious that did it. Everything just works now hell ya. I just had to put another layer in between the game itself (which is SKY) and the gems.
|
# ? Nov 20, 2022 18:59 |
|
|
# ? Jun 8, 2024 06:32 |
|
Hey all, got a question about the Command Pattern. https://refactoring.guru/design-patterns/command/csharp/example I'm trying to wrap my head around this. Someone on the gaming side said to equate it to the MVC pattern which was extremely helpful for me as a web dev, but one thing i'm not really getting is "the point" of receivers in this example. The way i'm reading it is you would have a command like "Punch". It would work as follows according to this (pseudocode): code:
code:
code:
|
# ? Jan 6, 2023 03:41 |