Jump to content

gamecreator

Members
  • Posts

    4,937
  • Joined

  • Last visited

Posts posted by gamecreator

  1. Thanks.  As usual for sample code, I tried to make it as short and straightforward as possible, avoiding functions and classes and such.  I'm hoping it's not too hard to translate to Lua since I used Leadwerks functions where possible.  cout can be replaced with System:Print or removed altogether (it's just a sanity check).

    • Like 1
  2. Since this was a hot topic recently, I've written code to preload model files from a map and display a progress bar.  Then, when you load the map, it should load much faster since you already "preloaded" the models and the ones in the map will be instances (copies) of existing ones.

    This is an alternative to Map::Load's hook, which may be a better way to go about this.

    #include "Leadwerks.h"
    
    using namespace Leadwerks;
    
    
    std::string mapfile = "maps/map.map";
    string model_file[100];		//  Stores list of model files in map
    Model *preload_model[100];	//  Array to preload model files to
    int modelcount=0;		//  Counts total number of models found in map file
    
    
    int main(int argc, const char *argv[])
    {
    	Leadwerks::Window* window = Leadwerks::Window::Create();
    	Context* context = Context::Create(window);
    
    
    	//  Load map as just a file
    	Stream* stream = FileSystem::ReadFile(mapfile);
    	if(stream==NULL)
    	{
    		cout << "Could not open map file to read." << endl;
    		exit(1);
    	}
    
    
    	//  Put MDL paths/files in a list and get count
    	while(!stream->EOF())
    	{
    		string line = stream->ReadLine();
    
    		//  If what we read is a model line (ends with .mdl)
    		if(line.size()>3 && line.compare(line.size() - 4, 4, ".mdl") == 0)
    			model_file[modelcount++]=line;
    	}
    	stream->Release();
    
    
    	cout << "Number of model files in map: " << modelcount << endl;
    
    
    
    	for(int i=0; i<modelcount; i++)
    	{
    		cout << "Preloading file #" << i << ":" << model_file[i] << endl << endl;
    		preload_model[i]=NULL;
    		preload_model[i]=Model::Load(model_file[i]);
    
    
    		//  You can check if model was properly loaded here (should not be NULL)
    
    
    		preload_model[i]->Hide();  //  Preload model should not be seen
    
    
    		//  Draw progress bar
    		context->SetColor(0.0, 0.0, 0.0);
    		context->Clear();
    		context->SetColor(1.0, 0.0, 0.0);
    
    		float barwidth = (float)(context->GetWidth())-20.0;
    		barwidth *= (float)(i+1);
    		barwidth /= (float)modelcount;
    
    		context->DrawRect(10, 10, (int)barwidth, 20);
    
    
    		//  Remove the below delay line.  It's put in just to show progress bar effect
    		Sleep(500);
    
    
    		context->Sync();
    	}
    
    
    //	You can then load the map here and it should be much faster
    //	since you already loaded the models in it above
    //	Map::Load(mapfile);
    
    
    //	Game code here
    
    
    	return 0;
    }

     

    • Like 1
    • Thanks 1
  3. 25 minutes ago, Yue said:

    For a progress bar to be real, threads must be managed... this must be done on the c++ side... In the case of maps, if the map is very large, the bar will undoubtedly pause for a long time, until it is completely loaded.

    Can I ask why you wouldn't use the method I suggested above?  You can load models one-by-one ahead of time to a model array (and hide them) and update a progress bar after each one.  Then, when you load the map, since every model is already loaded, the map itself will load pretty fast.  Maybe I should share a sample C++ code of this.

  4. I want to say that someone had a resolution issue with something I released as well but I couldn't find it just now.  If I remember right, it made me look into a non-Leadwerks, Windows-specific function that returns the current resolution, which would typically be the desktop resolution (but I'm using C++).

    @Josh Is it possible to add a GetCurrentGraphicsMode function?

  5. Regarding the progress bar, you have two options:

    1.  Figure out how to use the hook in the Map:Load function (if it works).  It's supposed to call a script every time an entity is loaded and you can display a progress bar there.
    2.  Preload everything yourself and display the progress bar as you do it.  Meaning, if you 12 different trees and 8 textures and whatnot in your map, load those first, before you load your map.  As pseudocode, it would look like this:

    preload_model[0] = Model::Load("tree1.mdl")
    update and show progress bar
    preload_model[1] = Model::Load("tree2.mdl")
    update and show progress bar
    preload_model[2] = Model::Load("tree3.mdl")
    update and show progress bar
    etc.
    That's pretty much how I do my loading screen.

    • Like 2
  6. I don't have multiple monitors so I never got to play with this but what would devs and users want to do?  The dev should know about the monitors to start.  int CountMonitors();

    Put windows on the appropriate monitor(s)?  Maybe window->SetMonitors(0); or more than one, left to right: window->SetMonitors(2, 0, 1);  window->Create would then spread itself over the set monitors in full screen.

    What else would a user need?

  7. On 6/28/2019 at 1:50 AM, Josh said:

    You can multiply any time-dependent values by Time:GetSpeed() to make your game run at the same speed regardless of framerate.

    With the caveat that this is not exact.  I don't know about the character controller (after the latest updates) but if you're coding your own character movement, you are better off using a fixed framerate, or things like jumps won't be the same height on all computers, as per here.

  8. I don't know Lua but it looks like you might sometimes trigger more than one PlayAnimation function per frame.  Meaning, if you hold down both the W and D keys, the first if statement will be true and it will trigger that PlayAnimation AND the next if statement will also be true and will trigger its respective PlayAnimation.  So I think you'd be blending two animations together. Look into using elseif statements.  Something like this (again, I don't know Lua but this seems like it could work):

    if KeyDown(Key.W) and KeyDown(Key.D) then
      PlayAnimation(“^>”,0.02,100,0)
    elseif KeyDown(Key.W) and KeyDown(Key.A) then
      PlayAnimation(“^<”,0.02,100,0)
    elseif KeyDown(Key.W)
      PlayAnimation(“^”,0.02,100,0)
    end

    As for posting, if you have several questions at once, you probably want to use a single post for it.  If it's two or three that are unrelated topics, you may want to split them up.  But I'm not the Leadwerks police; that's just my preference.  Ideally you also search the forums first and you might find something that already covers your question and you can just continue the conversation in that thread.  That will help for anyone searching the forums for the same issue so they don't have to open 10 different threads to find their answer.

    • Thanks 1
  9. On 6/8/2019 at 11:55 PM, Josh said:

    We already include a statement in the executable that should indicate to the driver to use the discrete GPU.

    ...

    It should just work.

    Got a chance to test it and it didn't work for me.  When I went into the NVIDIA Control Panel, Manage 3D settings, Global Settings and chose Auto-select (the default, I believe) or Integrated graphics, it used my Intel(R) HD Graphics 4600.  I had to choose High-performance NVIDIA process manually to force the Leadwerks program to use my GTX 780M.

    Also interesting to note that with the Intel processor, the program starts up immediately.  With the GTX it takes about a second to initialize (or whatever it does) to show the screen.  I was using the DrawText example to test.

  10. 39 minutes ago, wadaltmon said:

    That's a bold claim, one that I'm sure comes with a few implied stipulations, but an intriguing one nonetheless. I'll be sure to test this out once Turbo is available in its full version for subscription. Thanks for the response.

    A speed test against both Leadwerks 4 and the top engine competitors would be very welcome (I'm aware that you didn't say you'd do all of that).

  11. Below is a simple example if you want to write your own system.

    void characterclass::animate()
    {
    	double lastanimframe = animframe; 
    	animframe += timesincelastframe * animationspeedvariable;
    
      
    	//  While animation frame is over the total length of the animation, reduce it  
      	//  so we always stay between 0 and the animation length - 1
    	while(animframe > (double)model->GetAnimationLength(animstate)-1)
    		animframe -= (double)model->GetAnimationLength(animstate)-1;
      
      
     	//  You can see if animation hit a specific frame to check for a sword hit on an enemy or whatever action you'd like
     	//  The below line checks if we're animating an attack and we hit or passed frame 10
    	if(animsate=="attack" && animframe >=10 && lastanimframe<10)
    	{
    		//  Do action here
    	} 
    
      
    	//  When animation ends...
    	if(animframe > (double)model->GetAnimationLength(animstate)-1)
    	{
    		//  You can change your animation state to whatever you'd like
    		//  For example, if a sword finished swinging, you can switch back to an idle animation
    	}
    
    
    	model->SetAnimationFrame(animframe, 0.7, animstate, true);
    }

     

×
×
  • Create New...