• What Do You Need Help With? V8
    1,074 replies, posted
So I followed this Python tutorial on YouTube, and I was wondering how I would calculate the value of a hand? For example if the player had a Jack and a 4, how would I add those cards? Excuse my messy code at the bottom. https://www.youtube.com/watch?v=t8YkjDH86Y4 import random class Card(object):     def __init__(self, suit, value):         self.suit = suit         self.value = value     def show(self):         print("{} of {}".format(self.value, self.suit)) class Deck(object):     def __init__(self):         self.cards = []         self.build()     def build(self):         for suit in ['Clubs', 'Hearts', 'Spades', 'Diamonds']:             values = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']             for value in values:                 self.cards.append(Card(suit, value))     def show(self):         for card in self.cards:             card.show()     def shuffle(self):         for i in range(len(self.cards)-1, 0, -1):             r = random.randint(0, i)             self.cards[i], self.cards[r] = self.cards[r], self.cards[i]     def draw(self):         return self.cards.pop() class Player(object):     def __init__(self, name):         self.name = name         self.hand = []     def draw(self, deck):         self.hand.append(deck.draw())         return self     def show_hand(self):         for card in self.hand:             card.show()     def discard(self):         return self.hand.pop()     def clear(self):         self.hand = [] # main player = Player('Player') deck = Deck() deck.shuffle() player.draw(deck) player.draw(deck) player.show_hand()
I'm looking to optimize my model rendering and I have a few ideas, but I wanted to check if they make sense to anyone or if they can be improved on. My current pipeline in a nutshell (per frame): list of visible objects->get model->bind model UBO->bind model VAO->glDrawArrays() It is my understanding that I can improve this by merging all the model's UBO's into a single one (in an array), this way only 1 UBO is bound per frame (as opposed to 'n' model's worth) Then, I would only have to modify a shader uniform variable for the correct index to be used per model/draw. However, if I were to use glMultiDraw, if I'm correct in my understanding, I could join many objects into a single VAO and then use glMultiDraw to specify all of the ranges I want to render, all in 1 draw call. If that is the case, then I have to change the way I index into the model's uniform buffer again. Assuming there is some gl_DrawID or something I can access in the shader, then I guess I would have to have a secondary buffer holding an array of the correct indices. Are any of my assumptions wrong or does any of this sound about right?
Hey guys, im running a soft launch of a software app ive been designing. Its a media sharing/collab app tailored for the film/tv industry. Could I have some feedback? getcruncher.com
Depends what you mean by value - you could give each card a notional numeric value and add each value together in the Player class, or if you're looking for something a bit more complex like a hand in Poker you'll probably need to define a set of rules somehow, run the hand against each set of rules and work out the highest valued hand a player's hand matches.
That's exactly what I'm trying to do. Would you be able to offer some guidance on how to do this please? Thanks.
Which approach do you mean? If you want a simple value then just add another member like self.value For a whole hand approach you could create a set of classes (one for each hand type) that take five cards in their constructors and have a method that tells you whether it is the given hand type (e.g. if all the cards are of the same suit, if there are four of a kind or whatever). Once you have these classes to work out what hand you have you'd run a hand through each rule in order of descending value and the first one that matches is the hand you have.
I meant the first way, just a single hand. To play blackjack for example.
Thanks for the help guys! After two days I'm actually making progress now. Much appreciated.
I'm a little stuck here, I could jump in and try work out a complicated solution to this, but why not use the internet? So I want to fill in the outside of this polygon with triangles, I have all the vertices, and the green is my own drawing over the top showing what I want. It seems simple, till you hit more complex shapes, mostly just, you can't just draw a triangle against the edge of a screen if the vertices dip inwards at all, because they will overlap the edges of another one and fill up some space that shouldn't be filled. Are there any known algorithms for something like this? It'd save me from spending unneeded time on it and likely be faster than what I come up with. https://files.facepunch.com/forum/upload/110080/23a028f0-be35-46ea-9955-a93b8eb60bc7/Untitled.png
If you only want something like shadows, you can draw the inside area to the stencil buffer and use it to mask out stuff that a full screen polygon shouldn't draw to.
I'm having trouble determining this online: Is there an arbitrary max size that a vertex buffer can hold? I'm trying to figure out if I can get away with creating 1 set of VBO's for 1 vertex array and just share it with all the geometry (of the same format) for my engine.
Yes there is a max size, the total size of the VRAM plus possibly RAM swap space.You can't query it directly, just try to allocate it and you might get an error.
Oh okay, so it isn't some arbitrary limit. That simplifies things then.
Jesus, for whatever reason my multiDrawIndirect calls are taking a very loing time, like ~55 ms
This doesn't sound right at all, because even my heaviest compute shader takes 5ms. This is weird. Also I'm not sure what the best practice is for vertex buffers. Grouping them into larger objects to reduce binding changes is good, yes, but I wonder if there's a limit on how large it can be before the advantages are lost.
Yeah, but I don't think I'm that close yet I'm currently pushing at most 784,734 triangles, or to put it another way my vbo's are roughly 10 megabytes
Weird. How frequently are committing to Git? I'd first identify and recent changes to code that could cause the slowdowns when issuing drawcalls. Then I'd start looking at if you have some kind of debug functionality involved, as that can severely slow down operations. Then maybe recent driver changes. Is your data arranged in a linear fashion that isn't going to cause cache coherency issues? Not sure if that's a problem but it might be I guess.
In Unity, how can I set the uvs of a mesh triangle to the world space positions of it's verticies? I want to tile textures without using a triplaner shader because the faces have different materials on them. Thank you guys for your time!
I'm using Farseer Physics to make a 2D top down game, and I'm trying to trace the tiles on the map to create the collision shapes. I've managed to implement a function to trace all of the edge paths for each chunk, and it works well, but now I realize that it doesn't work for hollow shapes, like a box surrounded by walls, because then the entire shape including the inside is filled with collision. This is the first time I've done anything like this, and need to find a way to recognize which paths are the inside paths of other shapes. I was planning on recording the inner tiles for each path, and matching those with filled inner tiles with those with empty inner tiles for create the shape, but I'm not sure how to go about actually finding the matching pairs, since there might be many layers of tiles between them. Any in some cases there might be more than 2 inside/outside paths. Because of this, and not knowing what to search for to find information on this, I am pretty lost. Here's the code I'm using for the first part, if its useful. It's a bit of a mess. Facepunch keeps merging together if/else/while in the formatting, not sure if it's just on my end. member self.RebuildCollisionTest () = //stores if we've visited a vertex size n + 1 * n + 1 (for corner points) let mutable vertices = Array2D.create (self.Data.GetLength 0 |> (+) 1) (self.Data.GetLength 1 |> (+) 1) false let inline isVisited x y = if vertices |> Vsys.Array2D.inRange x y then vertices.[x, y] else true let inline blockingAt x y = if self.Data |> Vsys.Array2D.inRange x y then self.Data.[x, y].Tile.IsBlocking else false let inline isBlockingNortheast x y = blockingAt x (y - 1) let inline isBlockingSoutheast x y = blockingAt x y let inline isBlockingSouthwest x y = blockingAt (x - 1) y let inline isBlockingNorthwest x y = blockingAt (x - 1) (y - 1) let mutable bodyPaths = NETList<NETList<Vector2>>() let mutable lastDirection = TileState.None //matches none let mutable startingVertex = 0, 0 while startingVertex <> (-1, -1) do let path = NETList<Vector2>() let rec solve x y = vertices.[x, y] <- true if (not <| isVisited x (y - 1)) && isBlockingNortheast x y <> isBlockingNorthwest x y then //both tiles don't have same collision type, so there must be an edge if lastDirection <> TileState.North then lastDirection <- TileState.North Vector2(float32 x, float32 y) |> path.Add solve x (y - 1) else if (not <| isVisited (x + 1) y) && isBlockingNortheast x y <> isBlockingSoutheast x y then if lastDirection <> TileState.East then lastDirection <- TileState.East Vector2(float32 x, float32 y) |> path.Add solve (x + 1) y else if (not <| isVisited x (y + 1)) && isBlockingSoutheast x y <> isBlockingSouthwest x y then if lastDirection <> TileState.South then lastDirection <- TileState.South Vector2(float32 x, float32 y) |> path.Add solve x (y + 1) else if (not <| isVisited (x - 1) y) && isBlockingSouthwest x y <> isBlockingNorthwest x y then if lastDirection <> TileState.West then lastDirection <- TileState.West Vector2(float32 x, float32 y) |> path.Add solve (x - 1) y solve (fst startingVertex) (snd startingVertex) if path.Count <> 0 then bodyPaths.Add path startingVertex <- vertices |> Vsys.Array2D.firstIndex false Thank you for any help.
I found the issue, but I don't understand it yet, and not well enough to fix it. I use 2 buffers for my multidraw indirect rendering of geometry. 1 is an array of structs to be used once per model, and another is an ordered list of indices into that previous list. The idea is each element of this visibility list gets used once, getting the index into the main array for shader calculations. In any case, this second buffer is VERY slow to access. Dropping it removes the 50ms draw time for a given object. I can't see any other way to tell the shader where to get its data for a given draw call, while still being multidraw. If that wasn't clear, here's the shader: struct Geometry_Struct { bool useBones; uint materialID; mat4 mMatrix; mat4 Bones[MAX_BONES]; }; // buffer of visible geometry elements, each element gets used once per frame, in sequence layout (std430, binding = 3) buffer Visibility_Buffer { uint geometries[]; }; // universal buffer of all geometry objects, the above buffer's elements index into this layout (std140, binding = 5) uniform Geometry_Buffer { Geometry_Struct buffers[10]; }; // Input attributes layout (location = 0) in vec3 vertex; ... more inputs ... void main() { const Geometry_Struct geometry = buffers[geometries[gl_DrawID]]; ... vertex logic ... gl_Position = pMatrix * vMatrix * geometry.mMatrix * BoneTransform * vec4(vertex,1.0); }
Okay so I'm mad now. I fixed my problem, but the root of it is so stupid and makes no sense (as far as I'm concerned). In the main method of my vertex shader, I was doing the following (simplified) void main() { const Geometry_Struct geometry = buffers[indicies[gl_DrawID]]; // Bunch of things that rely on this array element (omitting MANY) MaterialID = geometry.materialID; gl_Position = pMatrix * vMatrix * geometry.mMatrix * vec4(vertex,1.0); } However, not using the object "geometry" and referring to the whole buffer at the location OVER AND OVER actually improves my performance: void main() { // Bunch of things that rely on this array element (omitting MANY) MaterialID = buffers[indicies[gl_DrawID]].materialID; gl_Position = pMatrix * vMatrix * buffers[indicies[gl_DrawID]].mMatrix * vec4(vertex,1.0); } What the fuck?
Can you send me the FULL source code for both of these (maybe post in a gist)? Lemme run them through my SPIR-V compiler and then translate that compiled bytecode back into GLSL for you. This will probably explain the problem. I have a hunch on what it is, but don't want to make any early guesses.
Here's my shaders as they are now And here's the old vertex shader I'm using nVidia (gtx1070)
Here they are: link cus embed is fuckhuge Declaring a const struct like that makes the shader copy all of the values it seems - including all 100 of the bone weight values, lmao - into the local invocation of that vertex shader. That's going to be slow as hell, haha. You don't need to do this, and shouldn't do this, as you can just access the variables you need vs copying over the whole structure.
Ah gotcha. So since glsl has no concept of pointers, I'm guess I just have to keep accessing those elements the (literal) long way by indexing into both buffers every line. That kinda sucks, but at least I've learned to not do that anymore. I think I've been doing this thing in a few other shaders, so I can probably speed up a few other areas (on top of all the other optimizations I'm trying to implement )
I'm working on a raycaster. How do I render floors at different levels, like doom did with stairs and platforms, etc.? I get the math and logic behind casting textured floors, but how do you figure out what the height of the floor should be? Also how could I do stairs or even a ramp
Hey, check this out - I am now going back and checking my shaders for the very same, and I found a few instances already! In one of my compute shaders I was taking a copy of a structure instead of just reading the values - one would hope that this could be optimized away, but the compiler takes it literally and insists on a copy (even with optimizations enabled). So yeah, when in doubt - never take a copy of a shader structure!
Anybody well versed in Entity Framework? I've got this strange problem with a one-to-many relationship. Here are the models:     public class Entreprise     {         public Guid Id { get; set; }         [Required(ErrorMessage = "Please provide a nom")]         public string Nom { get; set; }         public ICollection<Contact> Contacts { get; set; }         public DateTimeOffset? DateCreation { get; set; }         public DateTimeOffset? DateModification { get; set; }     }     public class Contact     {         public Guid Id { get; set; }         [Required(ErrorMessage = "Please provide a nom")]         public string Nom { get; set; }         [Required(ErrorMessage = "Please provide a prenom")]         public string Prenom { get; set; }         [NotMapped]         public string NomComplet         {             get             {                 return Prenom + " " + Nom;             }         }         [Required(ErrorMessage = "Please provide a noTelephone")]         public string NoTelephone1 { get; set; }         public string NoTelephone2 { get; set; }         public string Email { get; set; }         public string Commentaire { get; set; }         public DateTimeOffset? DateCreation { get; set; }         public DateTimeOffset? DateModification { get; set; }         public Guid? EntrepriseId { get; set; }         public Entreprise Entreprise { get; set; }     } Here is the database update method: var contacts = newEntreprise.Contacts.Select(contact => GetContactForId(contact.Id)).ToList();                var deletedContacts = existingEntreprise.Contacts.Except(contacts).ToList(); var addedContacts = contacts.Except(existingEntreprise.Contacts).ToList();                 deletedContacts.ForEach(f => existingEntreprise.Contacts.Remove(f));                 foreach (var f in addedContacts)                 {                     if (_context.Entry(f).State == EntityState.Detached)                         _context.Contacts.Attach(f);                     existingEntreprise.Contacts.Add(f);                 }                 existingEntreprise.Nom = newEntreprise.Nom;                 existingEntreprise.DateModification = DateTimeOffset.UtcNow;                 _context.Entry(existingEntreprise).State = EntityState.Modified;             var saveResult = await _context.SaveChangesAsync(); How it happens: Let's we have two entities "entreprise", EntrepriseA and EntrepriseB. We have one entity "contact", we'll name him Bob. If I add Bob to EntrepriseA, he will be in EntrepriseA's contact list. Then, if I try to add Bob to EntrepriseB, Bob will disappear from EntrepriseA's contacts but will not appear in EntrepriseB's contacts. Am I doing something wrong?
Hoping there's a Monogame wizard here, not super optimistic though. Writing it out might help me rubber duck debug it. So I'm trying to draw only the visible portions of the screen using a polygon in the stencil buffer. So this is how I'm drawing the polygon to the stencil buffer, it's literally just a triangle at this point. //Setup VertexBuffer/Rasterizer effect.VertexColorEnabled = true; //effect is a stock standard AlphaTestEffect(see way below) graphics.SetVertexBuffer(Buffer); //Set vertices RasterizerState state = new RasterizerState() { //Shouldn't matter but might as well draw it from all directions. CullMode = CullMode.None }; //Don't need to actually draw the polygon. graphics.BlendState = new BlendState() { ColorWriteChannels = ColorWriteChannels.None }; //Always write to depth stencil, this is our mask. graphics.DepthStencilState = new DepthStencilState() { StencilEnable = true, StencilFunction = CompareFunction.Always, StencilPass = StencilOperation.Replace, //Replace whatevers there, we'll clear it anyway but still. ReferenceStencil = 1, DepthBufferEnable = false, }; //Clear and draw. graphics.Clear(ClearOptions.Target | ClearOptions.Stencil, Color.Transparent, 0, 0); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, triangleCount); } Now the main draw method. public override void Draw(GameTime gameTime) { var viewMatrix = camera.GetViewMatrix(); //Draw the polygon as a mask polygon.Draw(graphicsDeviceManager.GraphicsDevice, viewMatrix, alphaTestEffect); //Draw the rest spriteBatch.Begin(SpriteSortMode.Immediate, null, null, depthStencilState2, null, alphaTestEffect, viewMatrix); //Everything in here is just a standard spriteBatch.Draw(texture2D ...) coreController.Draw(spriteBatch); spriteBatch.End(); } The DepthStencilState used to draw everything other than the mask.' depthStencilState2 = new DepthStencilState { StencilEnable = true, StencilFunction = CompareFunction.LessEqual, StencilPass = StencilOperation.Keep, ReferenceStencil = 1, DepthBufferEnable = false, }; The AlphaTestEffect and projection matrix, everything draws right using these without using the stencil. projectionMatrix = Matrix.CreateOrthographicOffCenter(0, graphicsDeviceManager.GraphicsDevice.PresentationParameters.BackBufferWidth, graphicsDeviceManager.GraphicsDevice.PresentationParameters.BackBufferHeight, 0, 0, 1 ); alphaTestEffect = new AlphaTestEffect(graphicsDeviceManager.GraphicsDevice) { Projection = projectionMatrix };
Sorry, you need to Log In to post a reply to this thread.