amkamkamk

Optimization How to implement control of the state of ui buttons?

Recommended Posts

Hello everyone!


Im using mvc framework for wrapper. So i have UIController, UIView for this problem.

The object of type UIView is display object and works as container(like in ActionScript). So it holds some static buttons wich control sound,fullscreen and etc. and another dynamic controls wich control the state and current rules of the game.

When the game is in different states  the buttons can be active or inactive for pressing, can be with different texts over them, wich can cause different functionallity to be performed in the controller.

So i have around 10-13 states of the game in wich the ui buttons are in different state so:

  1. Control state of the buttons in the controller. It is not ok cuz the controller is more than 300 rows and its ugly for reading and understanding. It shouldnt be.
  2. To create custom object in the controller and to pass to it the ui buttons and with some function called changeState to set the appropriate appearance to the buttons.

How to structure and name that custom object to be enough descriptive. Or is there some well known pattern ? Or do u have better idea ?

Edited by amkamkamk
More descriptive

Share this post


Link to post
Share on other sites

Conceptually, I'd say the model contains button state, or provide values for them, if you can derive them from other data in the model. If their state cannit be derived fully, then yes, the controller should provide any missing data values such that the viewer can reflect that in the display.

If the controller is bad, then I'd suggest to clean it up first. It takes some time, but in my experience it pays for itself. Making further changes in the controller is easier, faster, and with less errors.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Announcements

  • Forum Statistics

    • Total Topics
      628401
    • Total Posts
      2982463
  • Similar Content

    • By Tanzan
      Hello all,
      My question is a bit hard to describe but hopefully it will do...
      I just wonder what you guys think is the 'best' way of getting info about the model in your view(s)..
      To clearify (i hope ;-) )
      If the model is updating itself every game-cycle and the  (deep) nested objects all do there jobs how do you get info where only the view is interested in?
      So my question is not how to do it but more what do you people think is the best way to do it ?
       
      Regards,
       
      Alex   
    • By aejt
      Sorry for making a new thread about this, but I have a specific question which I couldn't find an answer to in any of the other threads I've looked at.
      I've been trying to get the method shown here to work several days now and I've run out of things to try.
      I've more or less resorted to using the barebones example shown there (with some very minor modifications as it wouldn't run otherwise), but I still can't get it to work. Either I have misunderstood something completely, or there's a mistake somewhere.
       
      My shader code looks like this:
      Vertex shader:
      #version 330 core //Vertex shader //Half the size of the near plane {tan(fovy/2.0) * aspect, tan(fovy/2.0) } uniform vec2 halfSizeNearPlane; layout (location = 0) in vec3 clipPos; //UV for the depth buffer/screen access. //(0,0) in bottom left corner (1, 1) in top right corner layout (location = 1) in vec2 texCoord; out vec3 eyeDirection; out vec2 uv; void main() { uv = texCoord; eyeDirection = vec3((2.0 * halfSizeNearPlane * texCoord) - halfSizeNearPlane , -1.0); gl_Position = vec4(clipPos.xy, 0, 1); } Fragment shader:
      #version 330 core //Fragment shader layout (location = 0) out vec3 fragColor; in vec3 eyeDirection; in vec2 uv; uniform mat4 persMatrix; uniform vec2 depthrange; uniform sampler2D depth; vec4 CalcEyeFromWindow(in float windowZ, in vec3 eyeDirection, in vec2 depthrange) { float ndcZ = (2.0 * windowZ - depthrange.x - depthrange.y) / (depthrange.y - depthrange.x); float eyeZ = persMatrix[3][2] / ((persMatrix[2][3] * ndcZ) - persMatrix[2][2]); return vec4(eyeDirection * eyeZ, 1); } void main() { vec4 eyeSpace = CalcEyeFromWindow(texture(depth, uv).x, eyeDirection, depthrange); fragColor = eyeSpace.rbg; } Where my camera settings are: float fov = glm::radians(60.0f); float aspect = 800.0f / 600.0f; And my uniforms equal: uniform mat4 persMatrix = glm::perspective(fov, aspect, 0.1f, 100.0f) uniform vec2 halfSizeNearPlane = glm::vec2(glm::tan(fov/2.0) * aspect, glm::tan(fov/2.0)) uniform vec2 depthrange = glm::vec2(0.0f, 1.0f) uniform sampler2D depth is a GL_DEPTH24_STENCIL8 texture which has depth values from an earlier pass (if I linearize it and set fragColor = vec3(linearizedZ), it shows up like it should, so nothing seems wrong there).
      I can confirm that it's wrong because it doesn't give me similar results to what saving position in the G-buffer or reconstructing using inverse matrices does.
      Is there something obvious I'm missing? To me the logic seems sound, and from the description on the Khronos wiki I can't see where I go wrong.
      Thanks!
    • By JakNow
      Hello everyone!
      Right now I am writing my own physics engine in java for LWJGL3 3D game and I would like to consult my ideas with you guys. It's not about writing the actual code, but asking if my solution is good, and/or can it be better. And I would like to make it easy to refactor to much others render engine and "game-loop engine". So lets get started!
      The base game architecture looks like this:

      The Core holds just the information about the game itself, so whenever I decided to write some new game I would just have to edit this module.
      The render engine holds just the information about rendering the models, however it only gets the material and mesh data from the model.
      The Model module holds 4 basic information about model:
      Models - basic Model that holds only information about ModelView, position, rotation and scale. Other types of models inherits it and add unique params (AnimatedModel adds Animation mesh data). ModelView is build of ModelPart which are build from TexturedMeshes (will be explained later). Loaders - classes to load specific model type (i.e. Assimp loader for *.obj files) and process classes - to create necessary data to render model (ie. create Mesh which holds vboID, vertices/textures/normals arrays etc). Components - every model can have some component, ie. moveable - which allows to move the object arround the world. Materials - used together with Mesh to create TexturedMesh. Material holds information about diffuse, ambient, etc colors, diffuse, normal textures. PhysicsEngine module has the core (initiation of physics world), collision detection, CollidableComponent (inherit from BaseComponent) and Shapes (i.e AABB, Sphere, Cylinder, MeshCollider). This is the part I would like to discuss with you guys (however if you have something to say about other parts - please go for it!).
      Core: PhysicState - initiation of physics world, update methods, holds default data (i.e. Default narrow collision shape) Collision: Broad Phase Collision Detection (BPCD) and Narrow Phase Collision Detection (NPCD) CollidableComponent - component that can be added to model to make it collidable (in future I was planning to add other components such as: WindComponent for grass model - adds reaction to wind). Only models with CollidableComponent are checked in BPCD and NPCD, the rest are ignored. CollidableComponent has also a boolean isMoveable - i.e. Rock - it is collidable, but its never, ever gonna move. so it doesn't have to be checked with other non-moveable components at BPCD and NPCD.  Shapes - basic shapes and info about them (AABB - points min/max, Sphere - center, radius, etc.) More info are shown below on diagram:
      Right now it works like this:
      I create a model and add a CollidableComponent to it like this:
      public CollidableComponent(Model model, TypeOfShape typeOfShape, boolean isMoveable) TypeOfShape declares the basic Broad Phase Collision Shape (AABB, Sphere, Cylinder, Mesh). The Shape is created from the raw data of the model and transformed to actual data (position, rotation*, scale).If I want to I can add the Narrow Phase Collision Shape MAP - which declares the CollisionShape for each Model Part inside the ModelView. In most cases for me it's going to be MeshCollider (since the game I'm planning to create is in Low Poly Style). 
      IDEA 1: When the CollidableComponent is created it is automatically added to BPCD map to check its collision. Of course it's just temporary, later on I would have to set limit to the map size (i.e. to 500) or split the world to smaller parts and add just the entities which are in this world's part to BPCD. So this is the part where you guys could give me some advice
      IDEA 2: Collision Detection update:
      Right now the update works like this:
      public void update() { narrowPhase.narrowPhaseCollisionMap.clear(); if (!broadPhaseCollisionMap.isEmpty()) { for (Model model : broadPhaseCollisionMap.keySet()) { if ((model.getComponent(CollidableComponent.class)).isMoveable()) { for (Model model2 : broadPhaseCollisionMap.keySet()) { if (!model.equals(model2)) { CollisionShape cs1 = getCollisionShape(model); CollisionShape cs2 = getCollisionShape(model2); if (checkCollision(cs1, cs2)) { narrowPhase.narrowPhaseCollisionMap.add(model); narrowPhase.narrowPhaseCollisionMap.add(model2); } } } } } } if (!narrowPhase.narrowPhaseCollisionMap.isEmpty()) { narrowPhase.update(); } } so:
      1. It checks if the BPC Map is not empty, and if its not it proceed, else nothing happens.
      2. It loops through all the models inside the map and check if it's isMoveable - as I said, I ignore collision detection with objects that doesn't move
      3. 2nd loop throught models and check the model from 1st loop isn't the model from the 2nd loop. If they are - lets ignore it.
      4. If they are 2 different models it retrieve the BPC shapes from the models and if it is the moveable model it updates its CollisionShape data (by the current the position, rotation,* scale*)
      5. Check the intersection between these 2 shapes, and if it true it's added to NPC List
      6. After the BPCD loops if the NPC List is not empty it runs its update
      The NPCD update is pretty similar to BPCD with just 2 exceptions:
      1. It used the List<Models> instead of Map<Model,CollidableComponents> (from models I can retrieve the info about the CollidableComponent, so I might use the List in BPCD aswell instand of Map **)
      2. It checks the collision intersection same as for BPCD but for each ModelPart of Model_1 with each ModelPart of Model_2, returns true and/or excact collision point, etc, and breaks this model-model loop check (so it doesn't check if other parts of the models collide with each other).  
      With my calculations for 50 objects - 27 is static and 23are movable with random position (but some collides): the NP
      Took: 0.0ms for: 1224 collision checks and: 24 positive collisions for BPCD
      Took: 10. ms for: 55776 collision checks and: 576 positive  collisions for NPCD
      Took: 11.0ms in total for BPCD and NPCD
      I can see a huge space to improve the Collision Detection update methods, but I can't find them, so I hope you guys can help me out  Maybe not all models has to be checked in NPCD, i.e. check how far from camera they are, and after some point just ignore NP since it won't be anyhow visible?
      Well, that's all! Sorry for a bit long post, but I hope you at least enjoyed reading it  
       
      *Actually just forgot about adding it to calculation  
      **Just came to my head when I was writing this topic 
    • By NekoCode
      Hey everyone! Currently I am making my engine and I got one thing I am worried about. I am using text data format to store my assets (e.g. JSON objects or kinda "human-readable"
      formats), it requires to register every field I want to serialize and read it manually from file data:
      void Resource::Save(IFile* file) { file->Serialize("myField", myFieldValue); } void Resource::Load(IFile* file) { file->Deserialize("myField", &myFieldValue) .. and so on, manually, nothing else! } But I can't breathe calmly since I saw UE4 serialization/asset storage system, it uses rtti, it's MUCH easier to serialize objects and now I am unsure which method I should use: should I give all responsibility to rtti system(with lots of code hidden) or load everything I need manually just like first code example? I know I can code rtti that way so it will output "human-readable" files, but is it good thing to use?
    • By JimsonLima
      Hey devs!
      Want to get rid of all the bugs in your game?
      I co-own a video game QA company called Level_0 Studios, we perform professional QA testing for game developers. Our goal is to help you create bug free games your players will enjoy. Partnering with Level_0 allows you to focus more time towards game development while we find those pesky bugs.
      If you’re interested and in need of professional game testers contact us at contact@level0studios.com and check out our website at https://level0studios.com for more information.
  • Popular Now