Wintermute Engine Forum
Wintermute Engine => Technical forum => Topic started by: mylesblasonato on August 26, 2008, 04:27:00 AM
-
Hey guys for some reason when the game is run in Fullscreen it lags badly. When I move the mouse along the ground or on something that doesnt' have interaction/script it's good but as soon as I hover over an object that has a verb name and stuff it lags until I move back onto the floor or ceiling. The code for my scene objects are standard, lookAt, Take and Talk but with one extra interaction that i can't say right now. Can you guys tell me why it's lagging?
Cheers ::beer
Myles Blasonato.
-
Can you reproduce the behavior on WME demo? If not, then perhaps your interface code is doing some wrong or needlessly complex.
-
I couldn't re-create the problem in the demo. I have posted my code for an object which is below. I have put the word BLANK in place of things I can't show yet:
#include "scripts\base.inc"
////////////////////////////////////////////////////////////////////////////////
on "LookAt"
{
actor.GoToObject(this);
actor.Talk("-BLANK- fly because they take themselves lightly.");
}
////////////////////////////////////////////////////////////////////////////////
on "Take"
{
actor.GoToObject(this);
var randHere = Random(1,2);
if(randHere == 1)
{
actor.Talk("I’d rather leave the -BLANK- there.");
}else{
genRes.takeDis();
}
}
////////////////////////////////////////////////////////////////////////////////
on "Talk"
{
actor.GoToObject(this);
genRes.talkDis();
}
on "BLANK"
{
actor.GoToObject(this);
genRes.BLANKDis();
}
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
actor.GoToObject(this);
}
Also for the interactions, instead of using the menu.script, I made a seperate script for each of the interactions. I then attach the script through the window editor. Here is the code for one of those scripts, the rest are the same:
#include "scripts\base.inc"
global MenuObject;
global WinMenu;
on "LeftRelease"
{
WinMenu.Close();
if(MenuObject!=null)
{
if(MenuObject.CanHandleEvent("LookAt")) MenuObject.ApplyEvent("LookAt");
else actor.Talk("I don't know what to say about it.");
}
MenuObject = null;
}
The last thing is the game script which I edited to make it so the left click button needs to be held down for the interactions to pop up. I also added a LeftRelease because when you hover over an interaction and release the left click that interaction is executed, here is the code for that:
////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
rRel = false;
// what did we click?
var ActObj = Game.ActiveObject;
var timeLim = 400;
if(ActObj!=null && Game.InventoryVisible == false)
{
// clicking an inventory item
if(ActObj.Type=="item" && Game.SelectedItem==null)
{
Game.SelectedItem = ActObj;
}
// using an inventory item on another object
else if(Game.SelectedItem != null && Game.SelectedItem!=ActObj)
{
var Item = Game.SelectedItem;
if(ActObj.CanHandleEvent(Item.Name)) ActObj.ApplyEvent(Item.Name);
else if(Item.CanHandleEvent("default-use")) Item.ApplyEvent("default-use");
else if(ActObj.CanHandleEvent("default-use")) ActObj.ApplyEvent("default-use");
else actor.Talk("I can't use these things together.");
}
// just a simple click
else ActObj.ApplyEvent("LeftClick");
}
// else propagate the LeftClick event to a scene
else
{
Scene.ApplyEvent("LeftClick");
}
MenuObject = Game.ActiveObject;
if(Game.ActiveObject == "noClick"){
timeLim = 0;
}else{
timeLim = 400;
}
Sleep(timeLim);
if(rRel == false){
if(ActObj!=null)
{
// if the clicked object can handle any of the "verbs", display the right-click menu
if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") || ActObj.CanHandleEvent("LookAt"))
{
// store the clicked object in a global variable MenuObject
var Caption = WinMenu.GetWidget("caption");
Caption.Text = MenuObject.Caption;
// adjust menu's position
WinMenu.X = Game.MouseX - WinMenu.Width / 2;
if(WinMenu.X < 0) WinMenu.X = 0;
if(WinMenu.X+WinMenu.Width>Game.ScreenWidth) WinMenu.X = Game.ScreenWidth-WinMenu.Width;
WinMenu.Y = Game.MouseY - WinMenu.Height / 2;
if(WinMenu.Y<0) WinMenu.Y = 0;
if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight-WinMenu.Height;
//stop the actor from whatever he was going to do
actor.Reset();
// and show the right-click menu
WinMenu.Visible = true;
// no verbs supported, no menu is needed; just send the LeftClick event to the object
}else ActObj.ApplyEvent("LeftClick");
}
}
}
////////////////////////////////////////////////////////////////////////////////
on "LeftRelease"
{
rRel = true;
var ActObj = Game.ActiveObject;
if(WinMenu.Visible == true){
ActObj.ApplyEvent("LeftRelease");
WinMenu.Visible = false;
}
if(Game.InventoryVisible == true){
if(ActObj.Type=="item" && Game.SelectedItem==null)
{
Game.SelectedItem = ActObj;
}
}
}
////////////////////////////////////////////////////////////////////////////////
on "RightClick"
{
var ActObj = Game.ActiveObject;
if(Game.SelectedItem != null && Game.InventoryVisible == false){
Game.SelectedItem = null;
}else if(Game.SelectedItem != null && Game.InventoryVisible == true){
Game.SelectedItem = null;
}else if(Game.SelectedItem == null)
{
Game.InventoryVisible = false;
interface.Visible = false;
ingGUI = true;
}
}
Sorry for the long post guys. On someone elses computer it runs fine but on mine it doesn't and the machine I am using is the one that needs to run smooth because it has low specs this way everyone can play the game when released. No point of a beast being able to run the game if a low spec machine can't.
Thanks for the help.
Cheers ::beer
Myles Blasonato.
-
Hi guys, ok I have isolated the problem to a piece of code in the game_loop.script. I edited that to make the verbs appear on top of the screen and for the characters dialogue to appear at the bottom the screen. Here is the code:
// save the active object for later
var ActObj = Game.ActiveObject;
if(actor != null){
actor.SubtitlesPosRelative = false;
actor.SubtitlesWidth = 800;
actor.SubtitlesPosXCenter = "center";
actor.SubtitlesPosX = 110;
actor.SubtitlesPosY = 732;
}
// handle the standard floating caption
if(Game.Interactive && ActObj!=null)
{
if (Game.SelectedItem==null)
{
WinCaption.X = 180;
WinCaption.Y = -15;
WinCaption.TextAlign = TAL_CENTER;
WinCaption.Text = ActObj.Caption;
WinCaption.SetFont("fonts\VerbFont.font");
// keep the caption on screen
//WinCaption.SizeToFit();
// handle the caption when you want to use an object with another
}else {
var Item = Game.SelectedItem;
WinCaption.X = 180;
WinCaption.Y = -15;
WinCaption.TextAlign = TAL_CENTER;
WinCaption.Text = "Use " + Item.Caption + " with " + ActObj.Caption;
}
WinCaption.Visible = true;
WinCaption.Focus();
}
else WinCaption.Visible = false;
Thanks guys, I am pretty sure it doesn't like the repositioning of the text.
Cheers ::beer
Myles Blasonato
-
My guess is the SetFont call is the culprit. You really shouldn't set font in every loop, font initialization is relatively expensive process compared to the rest of the code.
-
Hey Mnemonic you were right. I removed it from the loop and just put it in the game.script and it all works except that now the first time I hover over the objects it lags and then it doesn't after that intial time.
Where can I put it to stop the lag.
Cheers ::beer
Myles Blasonato
-
I think it's a font problem. When I change the font it works great but then when put the one I want back on it lags. I am using True type font
Cheers ::beer
Myles Blasonato
-
just a quick guess:
load the font when you load the scene/game.
havent got time to get together how but i am relatively sure you will find a way :)
all the good for your game :)
greetings
manarius
-
Hi, Thanks for the info.
Basically it was the True type font, so I go rid of it and used a bitmap font that i exported with a black background so it looks smooth in game over the black bars. There is no lag what so ever now.
Cheers ::beer
Myles Blasonato