Jump to content

Phodex Games

Members
  • Posts

    275
  • Joined

  • Last visited

Posts posted by Phodex Games

  1. You could create a 2nd camera somewhere above the player and then render the camera to a texture. Something like this: http://leadwerks.wikidot.com/wiki:render-to-texture-security-cam

     

    Yes I know this method as well. But it is much more ressource heavy because you need to render everything twice. I also dont like that the minimap looks like ingame graphic. You also have the disadvantage that you only can create square maps. I would like to have my minimap in a specific, editable design.

  2. Hi community,

     

    I would like to talk about how to create a minimap. I made myself some thoughts latley how to realise a minimap. And I would like to collect some useful toughts here. I actually found a solution, so tell me what you think of it. It currently just works as a normal map, not as a minimap...

     

    Maybe it is very complicated what I do but thats why I created this post. Ok so I will start explaining.

     

    First of all I took a screenshot from the topview of my map. Out of this I made a simple Map, by exporting the shot to gimp or something similar. The important thing is that the map has the same propotions than the real map size. The main idea is to grab the players 3D Position and convert it to a 2D position fitting to the map size and displaying a rect at the converted 2D Position.

     

    The conversion works like this:

     

    I tell my script the real map size (you can find it out in the viewports) and the pixel size of my map. Because my map and the real map size are propotional, I can calculate a "minimap multiplier" by doing this calculation: real map size X / map size X = multiplier. Thats the first part of the puzzle I need. Second I would like to know where to draw the player start position on the minimap. Because I have nothing I can relate to, I create a "minimap origin" pivot in the scene setting it to the zero-point of our map (not the origin of the viewport!!). To convert the player start position to a 2D Vector we do the following trick explained by this code:

     

    self.playerPos = self.entity:GetPosition()
    local myPos = self.mapOrigin:GetPosition()
    self.mapOrigin:SetPosition(myPos.x, self.playerPos.y, self.playerPos.z)
    self.playerStartPos.x = self.mapOrigin:GetDistance(self.entity:GetParent())
    self.mapOrigin:SetPosition(self.playerPos.x, self.playerPos.y, myPos.z)
    self.playerStartPos.y = self.mapOrigin:GetDistance(self.entity:GetParent())
    self.mapOrigin:SetPosition(myPos)
    

     

    As you can see I move the map Origin to get the correct X and Y values for the needed 2D Vector. If you didnt forget to also tell the script where the map origin of the 2D Map is in screen space, then you can now draw the player start position correctly on your map. To calculate the movement of the player, better said his current position I do the following:

     

    self.playerOffset = Vec2((playerStartPos.x - currentPlayerPos.x) * self.minimapMultiplier, (currentPlayerPos.z - playerStartPos.z) * self.minimapMultiplier)
    

     

    Now you can correctly draw a rect on your map on the correct player position:

     

    local minimapOriginX = context:GetWidth() * 0.5 - (self.mapSize.x / 2) + 50
    local minimapOriginY = context:GetHeight() * 0.5 + (self.mapSize.y / 2) - 10
    local playerX = (minimapOriginX + (playerStartPos.x * self.minimapMultiplier) + self.playerOffset.x)
    local playerY = (minimapOriginY - (playerStartPos.y * self.minimapMultiplier) + self.playerOffset.y)
    context:SetColor(Vec4(0,0,0,255))
    context:DrawRect(playerX, playerY, 10, 10)
    

     

    Tell me what you think of this method? If you have ideas how to improve my script just let me know. After I was recieving some help from the community I wanted to give something back. However I you think this is a very bad solution, I would be glad to know what other methods there are, I am just an amateur coder smile.png

  3. The syntax is wrong for FileSystem:WriteFile(). The API example shows how to properly do this.

     

    But for your example, it would be like this:

    function Script:Start()

    local gamedata = {}

    gamedata.playerHealth = 100

    gamedata.playerWeapon = "Sword" --Note the quotes

    gamedata.playerPos = Vec3(10, 100, 53)

    local stream = FileSystem:WriteFile("gamedata.lua")

    stream:WriteLine(gamedata.playerHealth)

    stream:WriteLine(gamedata.playerWeapon)

    stream:WriteLine(gamedata.playerPos:ToString())

    end

     

    But this method will only write the value and not the key that is associated with that value. Another way to do this (as there are many), is to use System:SetProperty(key, value) which will write the key and value into the game's config file. Then use System:GetProperty(key) to read the value.

     

    I know that my code was wrong, it was just for visualization purpose. However the code you sent me, didnt work, it says stream is a nil value. That was what I wrote before, FileSystem:WriteFile() doesnt seem to work...

     

    However System:SetProperty() works fine :) and thats more what I searched for, but I would also like to know how to save new file, because I maybe would like to have various save files in the future...

  4. Hello,

     

    Because I made myself some thoughts about a saving mechanic for my current project, I searched the web and especially the Leadwerks site for how to save simple game data, like the players health or position. The only kind of useful thing I found which works for LUA was this: http://www.leadwerks.com/werkspace/topic/2103-save-data-to-lua-syntax-as-textcompressed/page__hl__save+data

     

    and this:

    http://www.leadwerks.com/werkspace/topic/1853-howto-using-lua-script-as-data-file/

     

    I actually was able to create a data file and read it into my code with "dofile". However I didnt find out how to create/save a file with lua yet. I searched the Leadwerks API and found the Stream and FileSystem Class.

     

    So I tried the following code:

     

    function Script:Start()
    local gamedata = FileSystem:WriteFile("Test.txt")
    end
    

     

    It didnt work, and I also dont know how it works. Where has the file been created? I searched my PC and the Projectsfolder but couldnt find such a file and I also dont get any kind of error message.

    I guess this is completely wrong, but I was just playing around, because I don't have that much experience with Lua and Leadwerks. The file you can download in the first thread I posted ("TStoreData.lua") doesnt work anymore and I cant find where he saves data.

     

    That you clearly undersand what I want. I would like to do something like this:

     

    function Script:Start()
    local gamedata = {}
    gamedata.playerHealth = 100
    gamedata.playerWeapon = "Sword"
    gamedata.playerPos = Vec3(10, 100, 53)
    FileSystem:WriteFile("gamedata.lua", gamedata)
    end
    

     

    This is just some code that you know what I mean. I know this doesnt work xD. So could you please help me out a little bit smile.png.

     

    PS.: I kind of understood what AndyGFX wrote in his post, I just couldnt find anything how to save a file.

  5. Hi,

     

    I was wondering that I couldn't find any tutorial about creating simple UI elements. I searched the web and the forum for a while, and because I couldnt find anything useful I started this thread.

     

    The problem is I dont get how to check whether my mouse cursor is hovering over an element or not. To give you an more exact example: I just finished a simple inventory generation system where you can choose how many columns and slots it has and some other stuff. This works very well. However now I want to implement that, if you click on one of the items collected and shown in the inventory, that they get used/activated.

     

    The method I know from previous game developing experience is that you cast a ray from your camera origin through the mouse position and grab the UI elements which get intersected.

     

    My questions so far:

     

    Info: I only code in LUA.

     

    - How to check if my mouse hovers an context object (for example an image drawn with context:DrawImage())

    - How to unlock my mouse so that I can move it around freely

     

    You would do me a great favor, if you tell me how this works in Leadwerks.

     

    Phoenix smile.png

  6. UPDATE: I merged all the models and made a single house model and it runs waaays smoother now. I am not done with the texturing yet, but I think the merging helped a lot. I attached a pic with much more houses than before and runs with smooth 60 FPS even in debug mode, thats awesome.

    post-17271-0-37128700-1464875900_thumb.jpg

  7. Ok thanks for all the help I think this will fix my problem. I once read that CSG brushes are better for performance than Models. Thats why I created a mixture of both. CSG brushes and some props I add to the Brushes. Well will try that out. I actually prefer to make a house just as a single model, this makes it easier for me smile.png. Thank you all again.

     

    P.S.: Stupid Question: How to disable Vsync in Leadwerks?

  8. @Josh

    That is what my log says:

    Syncing Workshop Items...

    Initializing OpenGL4 graphics driver...

    OpenGL version 450

    GLSL version 450

    Device: GeForce GTX 960/PCIe/SSE2

     

    So I think my GTX 960 is the active graphic device.

     

    I think what Crazycarpet wrote fixed my problem. I am not 100 % sure if the performance is alright now. In the first 10 - 20 seconds after I run my project I still get some fps drops and lagging but after a while I have constant 60 FPS. This is great smile.png, but I still am a bit sceptic. Maybe my eyes fool me but I seem to see micro framedrops, this may happen because my project was lagging all the time and I just think it lags...

    Well the future will show, when I added more assets and build a real small town.

     

    But what was the exact problem now??

     

    I will also post a link where you can download my project, containing my "city". Because I would like to see if it runs smooth on other systems aswell now.

     

    Grab it here: https://www.dropbox.com/s/kp5079mxejfmwse/ShareProject.zip?dl=0

     

    P.S.: I dont know if it is normal but in Debug mode I only get 20 - 30 FPS. The 60 FPS I was talking about are in normal Run mode.

    • Upvote 1
  9. First of all thank you for your replies smile.png.

     

    So after my last post I was able to fix some issues myself, but I still have problems with the performance. In my playerscript the multisamlpe mode was set to 16, decreasing it to 1 fixed my problem with the high video memory usage. Now I just have 70+ MB and it also improved my performance. With a single house I get my 60 FPS. But If I build, like 16 houses, I get massive FPS drops, lags an bad performance at all sad.png. I also tried to decrease my poly count but this didnt brought a improvement aswell.

     

    I will add some more screenshots.

     

    @cassius

    I have a maximum of 10 active pointlights in the town scene. My textures for the brushes are 512 x 512 and most textures for models are 1024 x 1024.

     

    @Thirsty Panther

    Thank you will give that a try if I have some time.

     

    @Josh

    I will create a project I can share with the others, but it can take a few days.

     

    @reepblue

    Thank you aswell will take a look at it smile.png

     

    So that is my current state. Furthermore I want to ask what the limitations of leadwerks are. Maybe you can tell me Josh. I you do everything right, are you able to build a city as big as in games like Skyrim or Oblivion? Whats the limit? I am very interested in this how capable Leadwerks is.

     

    Thank you all for your help.

    post-17271-0-51579100-1464779194_thumb.jpg

    post-17271-0-85053600-1464779199_thumb.jpg

  10. Hi there,

     

    I am wondering if I am doing something wrong, or if I expect too much from Leadwerks...

    I built a small medivial house, just to play around. Soon I recognized that I got trouble with perfromance, very low FPS in Debug and normal run mode. So I started testing Leadwerks Performance a bit. I dont have experience with other engines, Leadwerks is the first I get my hands on. Well to move on, I rebuilt the whole house, creating models with less polygons and I also disabled most of the shadows.

     

    I posted a view screenshots where you can see my poly count and fps rate. I dont really understand why its lagging. Even if I just place a single house I get only 30 FPS. Ok the textures need some optimization but about 500 MB memory usage in summary isnt that much, even if its much for those few houses. I am a bit disappointed. How should I ever create a livley city when the performance is that bad?

     

    I searched the web for what poly counts are common and found out that 10k polygons are ok for a detailed character, for a prop its suggested to be 500 -1.5k. So 7k for a whole house really isnt much. So am I doing something wrong? huh.png Because I cannot believe Leadwerks performance is that bad. dry.png

     

    I need to add that if I decrease the resolution of my project to standart (something like 1024 x 768) it runs smoother, but for the city map I still get FPS drops and a maximum of 30 - 40 FPS which is not optimal. But still it needs to run smooth on a 1920 x 1080 resolution! I also want to add that If I activate static shadows for all the props build around the house (Planks, Lamp, Windows, etc.) the framerate is like hell. I dont think I can do something so wrong with just a single house and some textures, but I am glad if I am wrong happy.png

     

    A few more Infos:

     

    - I dont use any extra shaders

    - there are two point lights per house

    - I set the screen resolution to 1920 x 1080

    - even if I export the game and run it I get 20 - 30 FPS (for the "city" map)

    - My specs: Intel Core i5-3570K CPU @ 3.40 GHz, 8 GB Ram, Windows 7 64 Bit, Nvidia Geforce GTX 960 4G (4 GB Vram)

    - I use specular and normalmaps for all textures

    - The houses dont have an interior

     

    I really appreciate if you are able to help me. If you need some more info please tell me. I just want to make a awesome game... rolleyes.gif

    post-17271-0-68360100-1464283100_thumb.jpg

    post-17271-0-43407100-1464283120_thumb.jpg

    post-17271-0-39588200-1464283132_thumb.jpg

    post-17271-0-03582000-1464283145_thumb.jpg

×
×
  • Create New...