Renamed FrameCounter to GameCycle. Network timeouts, didn't block mouse and scrolling.

This commit is contained in:
johns 2002-03-28 00:49:59 +00:00
parent 7466c55811
commit a47f213588
31 changed files with 216 additions and 258 deletions

View file

@ -753,6 +753,9 @@
<LI>Split sound_server.c into wav.c, oss_audio.c and sdl_audio.c.
<LI>Ogg, mp3 audio format support added.
<LI>Randomize startpositions of network play (from Daniel Burrows).
<LI>Renamed FrameCounter to GameCycle.
<LI>Network timeout didn't block mouse movement and scrolling.
<LI>Removed WaitAndKeepSync from GameLoop.
<LI>+++
</UL>
</UL>

View file

@ -77,7 +77,7 @@ global void HandleActionBuild(Unit* unit)
if( unit->SubAction++<10 ) {
// To keep the load low, retry each 1/4 second.
// NOTE: we can already inform the AI about this problem?
unit->Wait=FRAMES_PER_SECOND/4+unit->SubAction;
unit->Wait=CYCLES_PER_SECOND/4+unit->SubAction;
return;
}
@ -122,7 +122,7 @@ global void HandleActionBuild(Unit* unit)
if( unit->SubAction++<10 ) {
// To keep the load low, retry each 1/4 second.
// NOTE: we can already inform the AI about this problem?
unit->Wait=FRAMES_PER_SECOND/4+unit->SubAction;
unit->Wait=CYCLES_PER_SECOND/4+unit->SubAction;
return;
}
@ -201,7 +201,7 @@ global void HandleActionBuild(Unit* unit)
build->Orders[0].Action=UnitActionBuilded;
build->Data.Builded.Sum=0; // FIXME: Is it necessary?
build->Data.Builded.Val=stats->HitPoints;
n=(stats->Costs[TimeCost]*FRAMES_PER_SECOND/6)/(SpeedBuild*5);
n=(stats->Costs[TimeCost]*CYCLES_PER_SECOND/6)/(SpeedBuild*5);
if( n ) {
build->Data.Builded.Add=stats->HitPoints/n;
} else { // No build time pops-up?
@ -215,7 +215,7 @@ global void HandleActionBuild(Unit* unit)
DebugLevel3Fn("Build Sum %d, Add %d, Val %d, Sub %d\n"
,build->Data.Builded.Sum,build->Data.Builded.Add
,build->Data.Builded.Val,build->Data.Builded.Sub);
build->Wait=FRAMES_PER_SECOND/6;
build->Wait=CYCLES_PER_SECOND/6;
//
// Building oil-platform, must remove oil-patch.

View file

@ -104,7 +104,7 @@ global void HandleActionFollow(Unit* unit)
//
if( unit->SubAction++<10 ) {
// To keep the load low, retry delayed.
unit->Wait=FRAMES_PER_SECOND/10+unit->SubAction;
unit->Wait=CYCLES_PER_SECOND/10+unit->SubAction;
break;
}
// FALL THROUGH

View file

@ -495,7 +495,7 @@ global void HandleActionMineGold(Unit* unit)
}
} else {
// To keep the load low, retry each 1/4 second.
unit->Wait=unit->SubAction+FRAMES_PER_SECOND/4;
unit->Wait=unit->SubAction+CYCLES_PER_SECOND/4;
}
} else {
unit->SubAction=64;
@ -530,7 +530,7 @@ global void HandleActionMineGold(Unit* unit)
}
} else {
// To keep the load low, retry each 1/4 second.
unit->Wait=unit->SubAction-64+FRAMES_PER_SECOND/4;
unit->Wait=unit->SubAction-64+CYCLES_PER_SECOND/4;
}
} else {
unit->SubAction=128;

View file

@ -14,8 +14,7 @@
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; either only 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -280,7 +279,7 @@ global void HandleActionMove(Unit* unit)
//
if( unit->SubAction++<10 ) {
// To keep the load low, retry delayed.
unit->Wait=FRAMES_PER_SECOND/10+unit->SubAction;
unit->Wait=CYCLES_PER_SECOND/10+unit->SubAction;
// FIXME: Now the units didn't defend themself :(((((((
break;
}

View file

@ -10,12 +10,11 @@
//
/**@name action_research.c - The research action. */
//
// (c) Copyright 1998,2000,2001 by Lutz Sammer
// (c) Copyright 1998,2000-2002 by Lutz Sammer
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -113,7 +112,7 @@ global void HandleActionResearch(Unit* unit)
}
unit->Reset=1;
unit->Wait=FRAMES_PER_SECOND/6;
unit->Wait=CYCLES_PER_SECOND/6;
// FIXME: should be animations here?
}

View file

@ -97,7 +97,8 @@ global void HandleActionReturnGoods(Unit* unit)
unit->Orders[0].X=unit->X;
unit->Orders[0].Y=unit->Y; // Return point to continue.
DebugLevel3("Return to %d=%d,%d\n"
,UnitNumber(destu),unit->Orders[0].X,unit->Orders[0].Y);
,UnitNumber(unit->Orders[0].Goal)
,unit->Orders[0].X,unit->Orders[0].Y);
unit->Orders[0].Action=UnitActionHarvest;
unit->Orders[0].Arg1=(void*)-1;
NewResetPath(unit);
@ -119,7 +120,8 @@ global void HandleActionReturnGoods(Unit* unit)
++destu->Refs;
}
DebugLevel3("Return to %d=%d,%d\n"
,UnitNumber(destu),unit->Orders[0].X,unit->Orders[0].Y);
,UnitNumber(unit->Orders[0].Goal)
,unit->Orders[0].X,unit->Orders[0].Y);
unit->Orders[0].Action=UnitActionHaulOil;
unit->Orders[0].Arg1=(void*)-1;
NewResetPath(unit);

View file

@ -10,12 +10,11 @@
//
/**@name action_still.c - The stand still action. */
//
// (c) Copyright 1998,2000,2001 by Lutz Sammer
// (c) Copyright 1998,2000-2002 by Lutz Sammer
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -63,7 +62,7 @@ global void ActionStillGeneric(Unit* unit,int ground)
if( unit->Removed ) { // Removed units, do nothing?
// If peon is in building or unit is in transporter it is removed.
unit->Wait=FRAMES_PER_SECOND/6;
unit->Wait=CYCLES_PER_SECOND/6;
return;
}

View file

@ -82,7 +82,7 @@ global void HandleActionTrain(Unit* unit)
unit->Data.Train.Ticks=unit->Data.Train.What[0]
->Stats[player->Player].Costs[TimeCost];
unit->Reset=1;
unit->Wait=FRAMES_PER_SECOND/6;
unit->Wait=CYCLES_PER_SECOND/6;
return;
}
@ -103,7 +103,7 @@ global void HandleActionTrain(Unit* unit)
unit->Data.Train.Ticks=unit->Data.Train.What[0]
->Stats[player->Player].Costs[TimeCost];
unit->Reset=1;
unit->Wait=FRAMES_PER_SECOND/6;
unit->Wait=CYCLES_PER_SECOND/6;
return;
}
@ -182,7 +182,7 @@ global void HandleActionTrain(Unit* unit)
}
unit->Reset=1;
unit->Wait=FRAMES_PER_SECOND/6;
unit->Wait=CYCLES_PER_SECOND/6;
}
//@}

View file

@ -10,12 +10,11 @@
//
/**@name action_upgradeto.c - The unit upgrading to new action. */
//
// (c) Copyright 1998,2000,2001 by Lutz Sammer
// (c) Copyright 1998,2000-2002 by Lutz Sammer
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -109,7 +108,7 @@ global void HandleActionUpgradeTo(Unit* unit)
}
unit->Reset=1;
unit->Wait=FRAMES_PER_SECOND/6;
unit->Wait=CYCLES_PER_SECOND/6;
}
//@}

View file

@ -10,12 +10,11 @@
//
/**@name actions.c - The actions. */
//
// (c) Copyright 1998,2000,2001 by Lutz Sammer
// (c) Copyright 1998,2000-2002 by Lutz Sammer
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -327,7 +326,7 @@ local void HandleUnitAction(Unit* unit)
}
/**
** Update the actions of all units each frame.
** Update the actions of all units each game cycle.
**
** IDEA: to improve the preformance use slots for waiting.
*/
@ -416,7 +415,7 @@ global void UnitActions(void)
fprintf(logf,";;;\tMap: %s\n\n",TheMap.Description);
}
fprintf(logf,"%d: ",FrameCounter);
fprintf(logf,"%d: ",GameCycle);
fprintf(logf,"%d %s S%d/%d-%d P%d Refs %d\n",
UnitNumber(unit),unit->Type ? unit->Type->Ident : "unit-killed",
unit->State,unit->SubAction,

View file

@ -776,15 +776,15 @@ local SCM CclAiSleep(SCM value)
{
int i;
DebugLevel3Fn("%d %d\n",FrameCounter,AiPlayer->SleepFrames);
DebugLevel3Fn("%lu %d\n",GameCycle,AiPlayer->SleepFrames);
if( AiPlayer->SleepFrames ) {
if( AiPlayer->SleepFrames<FrameCounter ) {
if( AiPlayer->SleepFrames<GameCycle ) {
AiPlayer->SleepFrames=0;
return SCM_BOOL_F;
}
} else {
i=gh_scm2int(value);
AiPlayer->SleepFrames=FrameCounter+i;
AiPlayer->SleepFrames=GameCycle+i;
}
return SCM_BOOL_T;

View file

@ -135,7 +135,7 @@ extern unsigned inline _FetchLE32(unsigned char **pp) {
#include <sys/types.h>
#else
#include <endian.h>
#endif /* __FreeBSD__ */
#endif // __FreeBSD__
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
#include <byteswap.h>

View file

@ -10,12 +10,11 @@
//
/**@name network.h - The network header file. */
//
// (c) Copyright 1998-2001 by Lutz Sammer
// (c) Copyright 1998-2002 by Lutz Sammer
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -41,7 +40,7 @@
-- Defines
----------------------------------------------------------------------------*/
#define NetworkMaxLag 250 /// Debuging network lag (# frames)
#define NetworkMaxLag 250 /// Debuging network lag (# game cycles)
#define NetworkDups 4 /// Repeat old commands
@ -105,7 +104,7 @@ typedef struct _ack_message_ {
*/
typedef struct _network_command_ {
unsigned char Type; /// Network command type.
unsigned char Frame; /// Destination frame.
unsigned char Cycle; /// Destination game cycle.
UnitRef Unit; /// Command for unit.
unsigned short X; /// Map position X.
unsigned short Y; /// Map position Y.
@ -126,7 +125,7 @@ typedef struct _network_packet_ {
** Network chat message.
*/
typedef struct _network_chat_ {
unsigned char Frame; /// Destination frame
unsigned char Cycle; /// Destination game cycle
unsigned char Type; /// Network command type
unsigned char Player; /// Sending player
char Text[7]; /// Message bytes
@ -139,8 +138,8 @@ typedef struct _network_chat_ {
extern int NetworkNumInterfaces; /// Network number of interfaces
extern int NetworkFildes; /// Network file descriptor
extern int NetworkInSync; /// Network is in sync
extern int NetworkUpdates; /// Network update each # frames
extern int NetworkLag; /// Network lag (# frames)
extern int NetworkUpdates; /// Network update each # game cycles
extern int NetworkLag; /// Network lag (# game cycles)
/*----------------------------------------------------------------------------
-- Functions

View file

@ -112,7 +112,7 @@ struct _palette_link_ {
};
/// MACRO defines speed of colorcycling FIXME: should be made configurable
#define COLOR_CYCLE_SPEED (FRAMES_PER_SECOND/4)
#define COLOR_CYCLE_SPEED (CYCLES_PER_SECOND/4)
// FIXME: not quite correct for new multiple palette version
/// System-Wide used colors.
@ -435,9 +435,9 @@ extern global VMemType8* VideoFindNewPalette8( const VMemType8 *cube,
/**
** Video synchronization speed. Synchronization time in prozent.
** If =0, video framerate is not synchronized. 100 is exact
** FRAMES_PER_SECOND (30). Game will try to redraw screen within
** CYCLES_PER_SECOND (30). Game will try to redraw screen within
** intervals of VideoSyncSpeed, not more, not less.
** @see FRAMES_PER_SECOND @see VideoInterrupts
** @see CYCLES_PER_SECOND @see VideoInterrupts
*/
extern int VideoSyncSpeed;

View file

@ -14,8 +14,7 @@
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of

View file

@ -104,8 +104,8 @@ local void CommandLog(const char* name,const Unit* unit,int flag,
//
// Frame, unit, (type-ident only for better readable.
//
fprintf(logf,"(log %d 'U%d '%s '%s '%s",
FrameCounter,UnitNumber(unit),unit->Type->Ident,name,
fprintf(logf,"(log %lu 'U%d '%s '%s '%s",
GameCycle,UnitNumber(unit),unit->Type->Ident,name,
flag ? "flush" : "append");
//
@ -599,7 +599,7 @@ global void ParseCommand(unsigned short msgnr,UnitRef unum,
Unit *unit, *dest;
int id, status;
DebugLevel3Fn(" %d frame %d\n", msgnr, FrameCounter);
DebugLevel3Fn(" %d cycle %lu\n", msgnr, GameCycle);
unit=UnitSlots[unum];
DebugCheck( !unit );

View file

@ -643,7 +643,8 @@ char *ncconstatenames[] = {
#endif
/**
** Send a message to the server, but only if the last packet was a while ago
** Send a message to the server, but only if the last packet was a while
** ago
**
** @param msg The message to send
** @param msecs microseconds to delay
@ -664,7 +665,8 @@ local void NetworkSendRateLimitedClientMessage(InitMessage *msg, long msecs)
}
n = NetworkSendICMessage(NetworkServerIP, htons(NetworkServerPort), msg);
DebugLevel0Fn("Sending Init Message (%s:%d): %d:%d(%d) %d.%d.%d.%d:%d\n",
ncconstatenames[NetLocalState], NetStateMsgCnt, msg->Type, msg->SubType, n,
ncconstatenames[NetLocalState], NetStateMsgCnt, msg->Type,
msg->SubType, n,
NIPQUAD(ntohl(NetworkServerIP)), NetworkServerPort);
}
}

View file

@ -117,10 +117,10 @@
**
** @li [IP Header - 20 bytes]
** @li [UDP Header - 8 bytes]
** @li [Type 1 byte][Frame 1 byte][Data 8 bytes] - Slot 0
** @li [Type 1 byte][Frame 1 byte][Data 8 bytes] - Slot 1
** @li [Type 1 byte][Frame 1 byte][Data 8 bytes] - Slot 2
** @li [Type 1 byte][Frame 1 byte][Data 8 bytes] - Slot 3
** @li [Type 1 byte][Cycle 1 byte][Data 8 bytes] - Slot 0
** @li [Type 1 byte][Cycle 1 byte][Data 8 bytes] - Slot 1
** @li [Type 1 byte][Cycle 1 byte][Data 8 bytes] - Slot 2
** @li [Type 1 byte][Cycle 1 byte][Data 8 bytes] - Slot 3
**
** @subsection internals Putting it together
**
@ -129,8 +129,8 @@
** some time to reach the other clients (lag), so the command is not
** executed immediatly on the local computer, it is stored in a delay
** queue and send to all other clients. After a delay of ::NetworkLag
** frames the commands of the other players are received and executed
** together with the local command. Each ::NetworkUpdates frames there
** game cycles the commands of the other players are received and executed
** together with the local command. Each ::NetworkUpdates game cycles there
** must a package send, to keep the clients in sync, if there is no user
** command, a dummy sync package is send.
** To avoid too much trouble with lost packages, a package contains
@ -174,7 +174,7 @@
** It would be better to transfer the group first and than only a
** single command for the complete group.
**
** @li The frame is transfered for each slot, this is not needed. We
** @li The game cycles is transfered for each slot, this is not needed. We
** can save some bytes if we compress this.
**
** @li We can sort the command by importants, currently all commands are
@ -265,8 +265,8 @@ typedef struct _network_command_queue_ {
global int NetworkNumInterfaces; /// Network number of interfaces
global int NetworkFildes = -1; /// Network file descriptor
global int NetworkInSync = 1; /// Network is in sync
global int NetworkUpdates = 5; /// Network update each # frames
global int NetworkLag = 5; /// Network lag in # frames
global int NetworkUpdates = 5; /// Network update each # game cycles
global int NetworkLag = 5; /// Network lag in # game cycles
local char NetMsgBuf[128][PlayerMax]; /// Chat message buffers
local int NetMsgBufLen[PlayerMax]; /// Stored chat message length
@ -353,7 +353,7 @@ local void NetworkSendPacket(const NetworkCommandQueue *ncq)
IfDebug( ++NetworkSendPackets );
DebugLevel3Fn("In frame %d sending: ",FrameCounter);
DebugLevel3Fn("In cycle %lu sending: ",GameCycle);
//
// Build packet of 4 messages.
@ -486,7 +486,7 @@ global void InitNetwork2(void)
for (i = 0; i <= NetworkLag; i += NetworkUpdates) {
for (n = 0; n < HostsCount; ++n) {
NetworkIn[i][Hosts[n].PlyNr].Time = i;
NetworkIn[i][Hosts[n].PlyNr].Data.Frame = i;
NetworkIn[i][Hosts[n].PlyNr].Data.Cycle = i;
NetworkIn[i][Hosts[n].PlyNr].Data.Type = MessageSync;
}
}
@ -528,7 +528,7 @@ global void NetworkSendCommand(int command, const Unit *unit, int x, int y,
ncq = malloc(sizeof(NetworkCommandQueue));
dl_insert_first(CommandsIn, ncq->List);
ncq->Time = FrameCounter;
ncq->Time = GameCycle;
ncq->Data.Type = command;
if (status) {
ncq->Data.Type |= 0x80;
@ -614,9 +614,9 @@ global void NetworkEvent(void)
if (nc->Type == MessageResend) {
const NetworkCommandQueue *ncq;
// Destination frame (time to execute).
n = ((FrameCounter + 128) & ~0xFF) | nc->Frame;
if (n > FrameCounter + 128) {
// Destination cycle (time to execute).
n = ((GameCycle + 128) & ~0xFF) | nc->Cycle;
if (n > GameCycle + 128) {
DebugLevel3Fn("+128 needed!\n");
n -= 0x100;
}
@ -661,9 +661,9 @@ global void NetworkEvent(void)
continue;
}
// Destination frame (time to execute).
n = ((FrameCounter + 128) & ~0xFF) | nc->Frame;
if (n > FrameCounter + 128) {
// Destination cycle (time to execute).
n = ((GameCycle + 128) & ~0xFF) | nc->Cycle;
if (n > GameCycle + 128) {
DebugLevel3Fn("+128 needed!\n");
n -= 0x100;
}
@ -672,14 +672,14 @@ global void NetworkEvent(void)
// FIXME: must support compressed sync slots.
}
if (NetworkIn[nc->Frame][player].Time != n) {
if (NetworkIn[nc->Cycle][player].Time != n) {
DebugLevel3Fn("Command %3d for %8d(%02X) got\n",
nc->Type, n, nc->Frame);
nc->Type, n, nc->Cycle);
}
// Place in network in
NetworkIn[nc->Frame][player].Time = n;
NetworkIn[nc->Frame][player].Data = *nc;
NetworkIn[nc->Cycle][player].Time = n;
NetworkIn[nc->Cycle][player].Data = *nc;
}
//
@ -687,7 +687,7 @@ global void NetworkEvent(void)
//
if (!NetworkInSync) {
NetworkInSync = 1;
n = ((FrameCounter) / NetworkUpdates) * NetworkUpdates + NetworkUpdates;
n = ((GameCycle) / NetworkUpdates) * NetworkUpdates + NetworkUpdates;
DebugLevel3Fn("wait for %d - ", n);
for (player = 0; player < HostsCount; ++player) {
if (NetworkIn[n & 0xFF][Hosts[player].PlyNr].Time != n) {
@ -695,7 +695,7 @@ global void NetworkEvent(void)
break;
}
}
DebugLevel3("%d in sync %d\n", FrameCounter, NetworkInSync);
DebugLevel3("%lu in sync %d\n", GameCycle, NetworkInSync);
}
}
@ -707,7 +707,7 @@ global void NetworkQuit(void)
NetworkCommand nc;
nc.Type = MessageQuit;
nc.Frame = FrameCounter & 0xFF;
nc.Cycle = GameCycle & 0xFF;
NetworkBroadcast(&nc, sizeof(NetworkCommand));
// FIXME: if lost? Need an acknowledge for QuitMessages.
@ -761,9 +761,9 @@ local void ParseNetworkCommand(const NetworkCommandQueue *ncq)
case MessageSync:
ply = ntohs(ncq->Data.X) << 16;
ply |= ntohs(ncq->Data.Y);
if (ply != NetworkSyncSeeds[FrameCounter & 0xFF]
if (ply != NetworkSyncSeeds[GameCycle & 0xFF]
|| ntohs(ncq->Data.Unit)
!= NetworkSyncHashs[FrameCounter & 0xFF]) {
!= NetworkSyncHashs[GameCycle & 0xFF]) {
DebugLevel0Fn("\n\aNetwork out of sync!\n\n");
}
return;
@ -811,12 +811,12 @@ local void NetworkResendCommands(void)
// Build packet of 4 messages.
//
packet.Commands[0].Type = MessageResend;
packet.Commands[0].Frame =
(FrameCounter / NetworkUpdates) * NetworkUpdates + NetworkUpdates;
packet.Commands[0].Cycle =
(GameCycle / NetworkUpdates) * NetworkUpdates + NetworkUpdates;
DebugLevel2Fn("In frame %d for frame %d(%x):", FrameCounter,
(FrameCounter / NetworkUpdates) * NetworkUpdates + NetworkUpdates,
packet.Commands[0].Frame);
DebugLevel2Fn("In cycle %lu for cycle %lu(%x):", GameCycle,
(GameCycle / NetworkUpdates) * NetworkUpdates + NetworkUpdates,
packet.Commands[0].Cycle);
ncq = (NetworkCommandQueue *)(CommandsOut->last);
@ -871,8 +871,8 @@ local void NetworkSendCommands(void)
dl_insert_first(CommandsOut, ncq->List);
// Fill in the time
ncq->Time = FrameCounter + NetworkLag;
ncq->Data.Frame = ncq->Time & 0xFF;
ncq->Time = GameCycle + NetworkLag;
ncq->Data.Cycle = ncq->Time & 0xFF;
DebugLevel3Fn("sending for %d\n", ncq->Time);
NetworkSendPacket(ncq);
@ -900,12 +900,12 @@ local void NetworkExecCommands(void)
while (!dl_empty(CommandsOut)) {
ncq = (NetworkCommandQueue *)(CommandsOut->last);
// FIXME: how many packets must be kept exactly?
// if (ncq->Time + NetworkLag + NetworkUpdates >= FrameCounter)
// THIS is too much if (ncq->Time >= FrameCounter)
if (ncq->Time + NetworkLag > FrameCounter) {
// if (ncq->Time + NetworkLag + NetworkUpdates >= GameCycle)
// THIS is too much if (ncq->Time >= GameCycle)
if (ncq->Time + NetworkLag > GameCycle) {
break;
}
DebugLevel3Fn("remove %d,%d\n", FrameCounter, ncq->Time);
DebugLevel3Fn("remove %lu,%d\n", GameCycle, ncq->Time);
dl_remove_last(CommandsOut);
free(ncq);
}
@ -914,8 +914,8 @@ local void NetworkExecCommands(void)
//
ncq = (NetworkCommandQueue *)(CommandsOut->last);
while (ncq->List->prev) {
if (ncq->Time == FrameCounter) {
DebugLevel3Fn("execute loc %d,%d\n", FrameCounter, ncq->Time);
if (ncq->Time == GameCycle) {
DebugLevel3Fn("execute loc %lu,%d\n", GameCycle, ncq->Time);
ParseNetworkCommand(ncq);
break;
}
@ -925,14 +925,14 @@ local void NetworkExecCommands(void)
//
// Remove external commands.
//
ncq = &NetworkIn[FrameCounter & 0xFF][i];
ncq = &NetworkIn[GameCycle & 0xFF][i];
if (ncq->Time) {
DebugLevel3Fn("execute net %d,%d(%x),%d\n",
FrameCounter, i, FrameCounter & 0xFF, ncq->Time);
if (ncq->Time != FrameCounter) {
DebugLevel2Fn("frame %d idx %d time %d\n",
FrameCounter, FrameCounter & 0xFF, ncq->Time);
DebugCheck(ncq->Time != FrameCounter);
DebugLevel3Fn("execute net %lu,%d(%lx),%d\n",
GameCycle, i, GameCycle & 0xFF, ncq->Time);
if (ncq->Time != GameCycle) {
DebugLevel2Fn("cycle %lu idx %lu time %d\n",
GameCycle, GameCycle & 0xFF, ncq->Time);
DebugCheck(ncq->Time != GameCycle);
}
ParseNetworkCommand(ncq);
}
@ -953,16 +953,16 @@ local void NetworkSyncCommands(void)
// Check if all next messages are available.
//
NetworkInSync = 1;
n = FrameCounter + NetworkUpdates;
n = GameCycle + NetworkUpdates;
for (i = 0; i < HostsCount; ++i) {
DebugLevel3Fn("sync %d\n", Hosts[i].PlyNr);
ncq = &NetworkIn[n & 0xFF][Hosts[i].PlyNr];
DebugLevel3Fn("sync %d==%d\n", ncq->Time, n);
if (ncq->Time != n) {
NetworkInSync = 0;
NetworkDelay = NetworkUpdates;
NetworkDelay = FrameCounter + NetworkUpdates;
// FIXME: should send a resent request.
DebugLevel3Fn("%d not in sync %d\n", FrameCounter, n);
DebugLevel3Fn("%lu not in sync %d\n", GameCycle, n);
break;
}
}
@ -977,8 +977,8 @@ global void NetworkCommands(void)
//
// Send messages to all clients (other players)
//
if (!(FrameCounter % NetworkUpdates)) {
DebugLevel3Fn("Update %d\n", FrameCounter);
if (!(GameCycle % NetworkUpdates)) {
DebugLevel3Fn("Update %lu\n", GameCycle);
NetworkSendCommands();
NetworkExecCommands();
@ -993,11 +993,10 @@ global void NetworkCommands(void)
global void NetworkRecover(void)
{
// Got no message just resent our oldest messages
// FIXME: must remove the use of VideoInterrupts!
if (NetworkDelay < VideoInterrupts) {
if (FrameCounter > NetworkDelay) {
NetworkDelay += NetworkUpdates;
if (!dl_empty(CommandsOut)) {
DebugLevel3Fn("%d %d\n", FrameCounter, VideoInterrupts);
DebugLevel3Fn("cycle %lu vi %d\n", GameCycle, VideoInterrupts);
NetworkResendCommands();
}
}

View file

@ -627,17 +627,18 @@ global int AStarNextPathElement(Unit* unit,int* pxd,int *pyd)
*/
global int NextPathElement(Unit* unit,int* pxd,int *pyd)
{
static int LastFrameCounter;
static int LastGameCycle;
static int UnreachableCounter;
int result;
//
// Reduce the load, stop handling pathes if too many UNREACHABLE results.
//
if( FrameCounter!=LastFrameCounter ) {
LastFrameCounter=FrameCounter;
if( GameCycle!=LastGameCycle ) {
LastGameCycle=GameCycle;
UnreachableCounter=3;
}
// FIXME: Can use the time left in frame.
if( !UnreachableCounter ) {
DebugLevel0Fn("Done too much %d.\n",UnitNumber(unit));
return PF_WAIT;

View file

@ -210,7 +210,6 @@ local void MixMusicToStereo32(int* buffer, int size)
if (n) { // End reached
SCM cb;
DebugLevel3Fn("End of music %d\n", i);
PlayingMusic = 0;
if (ModFile) {
ModPlug_Unload(ModFile);
@ -979,7 +978,7 @@ global void WriteSound(void)
audio_buf_info info;
ioctl(SoundFildes,SNDCTL_DSP_GETOSPACE,&info);
DebugLevel0("%d Free bytes %d\n",FrameCounter,info.bytes);
DebugLevel0("%lu Free bytes %d\n",GameCycle,info.bytes);
if( info.bytes<sizeof(buffer) ) {
return;
}

View file

@ -52,6 +52,7 @@
#include "deco.h"
#include "trigger.h"
#include "campaign.h"
#include "sound_server.h"
#if defined(USE_SDLCD) || defined(USE_LIBCDA)
#include "sound_server.h"
@ -308,7 +309,7 @@ global void UpdateDisplay(void)
{ int f;
f=(168*(NextFrameTicks-GetTicks()))
/((100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed);
/((100*1000/CYCLES_PER_SECOND)/VideoSyncSpeed);
if( f<0 || f>168 ) {
f=168;
}
@ -452,9 +453,18 @@ local void EnableDrawRefresh(void)
*/
global void GameMainLoop(void)
{
#if defined(USE_SDLCD) || defined(USE_LIBCDA)
int counter = 30;
#endif
EventCallback callbacks;
callbacks.ButtonPressed=(void*)HandleButtonDown;
callbacks.ButtonReleased=(void*)HandleButtonUp;
callbacks.MouseMoved=(void*)HandleMouseMove;
callbacks.MouseExit=(void*)HandleMouseExit;
callbacks.KeyPressed=HandleKeyDown;
callbacks.KeyReleased=HandleKeyUp;
callbacks.NetworkEvent=NetworkEvent;
callbacks.SoundReady=WriteSound;
SetVideoSync();
EnableDrawRefresh();
@ -462,11 +472,12 @@ global void GameMainLoop(void)
GameRunning=1;
for( ; GameRunning; ) {
// FIXME: The mouse and network should continue in pause mode!
if(!GamePaused) {
++FrameCounter;
if( !FrameCounter ) {
// FIXME: tests with frame counters now fails :(
//
// Game logic part
//
if (!GamePaused && NetworkInSync) {
if( !++GameCycle ) {
// FIXME: tests with game cycle counter now fails :(
// FIXME: Should happen in 68 years :)
fprintf(stderr,"FIXME: *** round robin ***\n");
fprintf(stderr,"FIXME: *** round robin ***\n");
@ -476,14 +487,8 @@ global void GameMainLoop(void)
NetworkCommands(); // Get network commands
UnitActions(); // handle units
MissileActions(); // handle missiles
PlayersEachFrame(); // handle players
TriggersEachFrame(); // handle triggers
#if defined(USE_SDLCD) || defined(USE_LIBCDA)
if (counter --== 0) {
CDRomCheck();
counter = 30; // every second
}
#endif
PlayersEachCycle(); // handle players
TriggersEachCycle(); // handle triggers
MustRedraw&=~RedrawMinimap; // FIXME: this a little hack!
//
@ -496,7 +501,7 @@ global void GameMainLoop(void)
// Check game goals.
// Check rescue of units.
//
switch( FrameCounter%FRAMES_PER_SECOND ) {
switch( GameCycle%CYCLES_PER_SECOND ) {
case 0:
UnitIncrementMana(); // magic units
break;
@ -518,13 +523,19 @@ global void GameMainLoop(void)
case 6: // overtaking units
RescueUnits();
break;
case 7:
case 7: // show order some time
if( ShowOrdersCount ) {
ShowOrdersCount--;
}
break;
#if defined(USE_SDLCD) || defined(USE_LIBCDA)
case 8: // Check cd-rom
CDRomCheck();
break;
#endif
}
}
//
// Map scrolling
//
@ -563,7 +574,10 @@ global void GameMainLoop(void)
CheckVideoInterrupts(); // look if already an interrupt
WaitEventsAndKeepSync();
WaitEventsOneFrame(&callbacks);
if( !NetworkInSync ) {
NetworkRecover(); // recover network
}
}
//

View file

@ -749,15 +749,15 @@ global void PlayersInitAi(void)
}
/**
** Handle AI of all players each frame.
** Handle AI of all players each game cycle.
*/
global void PlayersEachFrame(void)
global void PlayersEachCycle(void)
{
int player;
for( player=0; player<NumPlayers; ++player ) {
if( Players[player].AiEnabled ) {
AiEachFrame(&Players[player]);
AiEachCycle(&Players[player]);
}
}
}
@ -771,7 +771,7 @@ global void PlayersEachSecond(void)
int res;
for (player = 0; player < NumPlayers; ++player) {
if ((FrameCounter / FRAMES_PER_SECOND) % 10 == 0) {
if ((GameCycle / CYCLES_PER_SECOND) % 10 == 0) {
for (res = 0; res < MaxCosts; res++) {
Players[player].Revenue[res] =
Players[player].Resources[res] -

View file

@ -339,7 +339,7 @@ local void SpellWhirlwindController(Missile *missile)
//
// Every 1/10s 1 points damage on tornado periphery
//
if (!(missile->TTL % (FRAMES_PER_SECOND/10))) {
if (!(missile->TTL % (CYCLES_PER_SECOND/10))) {
n = SelectUnits(x - 1, y - 1, x + 1, y + 1, table);
DebugLevel3Fn("Damage on %d,%d-%d,%d = %d\n",x-1,y-1,x+1,y+1,n);
for (i = 0; i < n; ++i) {
@ -625,7 +625,7 @@ global int CanCastSpell(const Unit* unit, const SpellType* spell,
case SpellActionSlow:
// slow didn't work on buildings
if (target && !target->Type->Building
&& target->Slow < spell->TTL / FRAMES_PER_SECOND) {
&& target->Slow < spell->TTL / CYCLES_PER_SECOND) {
return 1;
}
return 0;
@ -641,7 +641,7 @@ global int CanCastSpell(const Unit* unit, const SpellType* spell,
case SpellActionInvisibility:
// invisible didn't work on buildings
if (target && !target->Type->Building
&& target->Invisible < spell->TTL / FRAMES_PER_SECOND) {
&& target->Invisible < spell->TTL / CYCLES_PER_SECOND) {
return 1;
}
return 0;
@ -662,7 +662,7 @@ global int CanCastSpell(const Unit* unit, const SpellType* spell,
case SpellActionBloodlust:
if (target && target->Type->Organic
&& target->Bloodlust < spell->TTL / FRAMES_PER_SECOND) {
&& target->Bloodlust < spell->TTL / CYCLES_PER_SECOND) {
return 1;
}
// FIXME: should we support making bloodlust in range?
@ -680,7 +680,7 @@ global int CanCastSpell(const Unit* unit, const SpellType* spell,
case SpellActionHaste:
if (target && !target->Type->Building
&& target->Haste < spell->TTL / FRAMES_PER_SECOND) {
&& target->Haste < spell->TTL / CYCLES_PER_SECOND) {
return 1;
}
return 0;
@ -693,7 +693,7 @@ global int CanCastSpell(const Unit* unit, const SpellType* spell,
case SpellActionUnholyArmor:
if (target && !target->Type->Building
&& target->UnholyArmor < spell->TTL / FRAMES_PER_SECOND) {
&& target->UnholyArmor < spell->TTL / CYCLES_PER_SECOND) {
return 1;
}
return 0;
@ -758,8 +758,8 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
target->HP = 0;
target->X = x;
target->Y = y;
target->TTL=FrameCounter+FRAMES_PER_SECOND+FRAMES_PER_SECOND/2;
//target->TTL=FrameCounter+target->Type->DecayRate*6*FRAMES_PER_SECOND;
target->TTL=GameCycle+CYCLES_PER_SECOND+CYCLES_PER_SECOND/2;
//target->TTL=GameCycle+target->Type->DecayRate*6*CYCLES_PER_SECOND;
CheckUnitToBeDrawn(target);
break;
@ -845,10 +845,10 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
case SpellActionSlow:
if (target && !target->Type->Building
&& target->Slow < spell->TTL/FRAMES_PER_SECOND) {
&& target->Slow < spell->TTL/CYCLES_PER_SECOND) {
// get mana cost
unit->Mana -= spell->ManaCost;
target->Slow = spell->TTL/FRAMES_PER_SECOND; // about 25 sec
target->Slow = spell->TTL/CYCLES_PER_SECOND; // about 25 sec
target->Haste = 0;
CheckUnitToBeDrawn(target);
@ -964,7 +964,7 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
case SpellActionInvisibility:
if (target && !target->Type->Building
&& target->Invisible < spell->TTL/FRAMES_PER_SECOND) {
&& target->Invisible < spell->TTL/CYCLES_PER_SECOND) {
// get mana cost
unit->Mana -= spell->ManaCost;
if( target->Type->Volatile ) {
@ -976,7 +976,7 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
x*TileSizeX+TileSizeX/2, y*TileSizeY+TileSizeY/2 );
} else {
// about 50 sec
target->Invisible = spell->TTL/FRAMES_PER_SECOND;
target->Invisible = spell->TTL/CYCLES_PER_SECOND;
CheckUnitToBeDrawn(target);
}
@ -1077,7 +1077,7 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
DropOutOnSide(target,LookingW,0,0);
// set life span
target->TTL=FrameCounter+target->Type->DecayRate*6*FRAMES_PER_SECOND;
target->TTL=GameCycle+target->Type->DecayRate*6*CYCLES_PER_SECOND;
CheckUnitToBeDrawn(target);
PlayGameSound(spell->Casted.Sound,MaxSampleVolume);
@ -1088,10 +1088,10 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
case SpellActionBloodlust:
if (target && target->Type->Organic
&& target->Bloodlust < spell->TTL/FRAMES_PER_SECOND) {
&& target->Bloodlust < spell->TTL/CYCLES_PER_SECOND) {
// get mana cost
unit->Mana -= spell->ManaCost;
target->Bloodlust = spell->TTL/FRAMES_PER_SECOND; // about 25 sec
target->Bloodlust = spell->TTL/CYCLES_PER_SECOND; // about 25 sec
CheckUnitToBeDrawn(target);
PlayGameSound(spell->Casted.Sound,MaxSampleVolume);
@ -1195,11 +1195,11 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
case SpellActionHaste:
if (target && !target->Type->Building
&& target->Haste < spell->TTL/FRAMES_PER_SECOND) {
&& target->Haste < spell->TTL/CYCLES_PER_SECOND) {
// get mana cost
unit->Mana -= spell->ManaCost;
target->Slow = 0;
target->Haste = spell->TTL/FRAMES_PER_SECOND; // about 25 sec
target->Haste = spell->TTL/CYCLES_PER_SECOND; // about 25 sec
CheckUnitToBeDrawn(target);
PlayGameSound(spell->Casted.Sound,MaxSampleVolume);
@ -1227,8 +1227,8 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
target=MakeUnitAndPlace(x, y, UnitTypeByIdent("unit-skeleton"),
unit->Player);
// set life span
target->TTL=FrameCounter+
target->Type->DecayRate*6*FRAMES_PER_SECOND;
target->TTL=GameCycle+
target->Type->DecayRate*6*CYCLES_PER_SECOND;
CheckUnitToBeDrawn(target);
ReleaseUnit( Units[i] );
@ -1267,7 +1267,7 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
case SpellActionUnholyArmor:
if (target && !target->Type->Building
&& target->UnholyArmor < spell->TTL/FRAMES_PER_SECOND) {
&& target->UnholyArmor < spell->TTL/CYCLES_PER_SECOND) {
// get mana cost
unit->Mana -= spell->ManaCost;
if( target->Type->Volatile ) {
@ -1279,7 +1279,7 @@ global int SpellCast(Unit * unit, const SpellType * spell, Unit * target,
x*TileSizeX+TileSizeX/2, y*TileSizeY+TileSizeY/2 );
} else {
// about 13 sec
target->UnholyArmor = spell->TTL/FRAMES_PER_SECOND;
target->UnholyArmor = spell->TTL/CYCLES_PER_SECOND;
CheckUnitToBeDrawn(target);
}

View file

@ -400,7 +400,7 @@ local void WaitForInput(int timeout)
RealizeVideoMemory();
WaitNoEvent=1;
timeout*=FRAMES_PER_SECOND;
timeout*=CYCLES_PER_SECOND;
while( timeout-- && WaitNoEvent ) {
WaitEventsOneFrame(&callbacks);
}

View file

@ -613,7 +613,7 @@ global void DrawResources(void)
// FIXME: move messages to console code.
#define MESSAGES_TIMEOUT FRAMES_PER_SECOND*5 /// Message timeout 5 seconds
#define MESSAGES_TIMEOUT (FRAMES_PER_SECOND*5) /// Message timeout 5 seconds
local int MessageFrameTimeout; /// frame to expire message
@ -1044,8 +1044,8 @@ global void DrawInfoPanel(void)
VideoDrawText(x,y,GameFont,"FreeCraft");
y+=16;
VideoDrawText(x,y,GameFont,"Cycle:");
VideoDrawNumber(x+48,y,GameFont,FrameCounter);
VideoDrawNumber(x+110,y,GameFont,FRAMES_PER_SECOND*VideoSyncSpeed/100);
VideoDrawNumber(x+48,y,GameFont,GameCycle);
VideoDrawNumber(x+110,y,GameFont,CYCLES_PER_SECOND*VideoSyncSpeed/100);
y+=20;
for( i=0; i<PlayerMax; ++i ) {

View file

@ -130,7 +130,7 @@ global void FreeUnitMemory(Unit* unit)
*/
global void ReleaseUnit(Unit* unit)
{
DebugLevel2Fn("%d:Unit %p %d `%s'\n",FrameCounter,
DebugLevel2Fn("%lu:Unit %p %d `%s'\n",GameCycle,
unit,UnitNumber(unit),unit->Type->Ident);
DebugCheck( !unit->Type ); // already free.
@ -157,7 +157,7 @@ global void ReleaseUnit(Unit* unit)
unit->Destroyed=1; // mark as destroyed
RefsDebugCheck( !unit->Refs );
if( --unit->Refs>0 ) {
DebugLevel2Fn("%d:More references of %d #%d\n",FrameCounter
DebugLevel2Fn("%lu:More references of %d #%d\n",GameCycle
,UnitNumber(unit),unit->Refs);
return;
}
@ -185,10 +185,10 @@ global void ReleaseUnit(Unit* unit)
//
*ReleasedTail=unit;
ReleasedTail=&unit->Next;
unit->Refs=FrameCounter+NetworkMaxLag; // could be reuse after this.
unit->Refs=GameCycle+NetworkMaxLag; // could be reuse after this.
IfDebug(
DebugLevel2Fn("%d:No more references %d\n",
FrameCounter,UnitNumber(unit));
DebugLevel2Fn("%lu:No more references %d\n",
GameCycle,UnitNumber(unit));
unit->Type=NULL; // for debugging.
);
}
@ -222,13 +222,13 @@ global Unit* MakeUnit(UnitType* type,Player* player)
//
// Can use released unit?
//
if( ReleasedHead && ReleasedHead->Refs<FrameCounter ) {
if( ReleasedHead && ReleasedHead->Refs<GameCycle ) {
unit=ReleasedHead;
ReleasedHead=unit->Next;
if( ReleasedTail==&unit->Next ) { // last element
ReleasedTail=&ReleasedHead;
}
DebugLevel2Fn("%d:Release %p %d\n",FrameCounter,unit,UnitNumber(unit));
DebugLevel2Fn("%lu:Release %p %d\n",GameCycle,unit,UnitNumber(unit));
slot=UnitSlots+unit->Slot;
memset(unit,0,sizeof(*unit));
// FIXME: can release here more slots, reducing memory needs.
@ -1263,8 +1263,8 @@ global void UnitIncrementMana(void)
//
// Look if the time to live is over.
//
if( unit->TTL && unit->TTL<FrameCounter ) {
DebugLevel0Fn("Unit must die %d %d!\n",unit->TTL,FrameCounter);
if( unit->TTL && unit->TTL<GameCycle ) {
DebugLevel0Fn("Unit must die %d %lu!\n",unit->TTL,GameCycle);
//if( !--unit->HP ) { FIXME: must reduce hp the last seconds of life
LetUnitDie(unit);
//}
@ -3027,7 +3027,7 @@ global void HitUnit(Unit* attacker,Unit* target,int damage)
if( !target->Attacked ) {
// NOTE: perhaps this should also be moved into the notify?
if( target->Player==ThisPlayer ) {
static int LastFrame;
static int LastCycle;
static int LastX;
static int LastY;
@ -3035,11 +3035,11 @@ global void HitUnit(Unit* attacker,Unit* target,int damage)
// One help cry each 2 second is enough
// If on same area ignore it for 2 minutes.
//
if( LastFrame<FrameCounter ) {
if( LastFrame+FRAMES_PER_SECOND*120<FrameCounter ||
if( LastCycle<GameCycle ) {
if( LastCycle+CYCLES_PER_SECOND*120<GameCycle ||
target->X<LastX-14 || target->X>LastX+14
|| target->Y<LastY-14 || target->Y>LastY+14 ) {
LastFrame=FrameCounter+FRAMES_PER_SECOND*2;
LastCycle=GameCycle+CYCLES_PER_SECOND*2;
LastX=target->X;
LastY=target->Y;
PlayUnitSound(target,VoiceHelpMe);

View file

@ -14,8 +14,7 @@
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -125,9 +124,9 @@ global void SetVideoSync(void)
}
itv.it_interval.tv_sec=itv.it_value.tv_sec=
(100/FRAMES_PER_SECOND)/VideoSyncSpeed;
(100/CYCLES_PER_SECOND)/VideoSyncSpeed;
itv.it_interval.tv_usec=itv.it_value.tv_usec=
(100000000/FRAMES_PER_SECOND)/VideoSyncSpeed-
(100000000/CYCLES_PER_SECOND)/VideoSyncSpeed-
itv.it_value.tv_sec*100000;
if( setitimer(ITIMER_REAL,&itv,NULL) ) {
fprintf(stderr,"Can't set itimer\n");

View file

@ -10,12 +10,11 @@
//
/**@name sdl.c - SDL video support. */
//
// (c) Copyright 1999-2001 by Lutz Sammer
// (c) Copyright 1999-2002 by Lutz Sammer
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -76,61 +75,6 @@ global SDL_Surface *Screen; /// internal screen
-- Sync
----------------------------------------------------------------------------*/
#if 0
/*
** The timer resolution is 10ms, which make the timer useless for us.
*/
/**
** Called from another thread or what ever SDL uses..
**
** @param unused Need by library: interval of the timer.
** @param param Parameter passed in by library.
*/
local Uint32 VideoSyncHandler(Uint32 unused,void* param)
{
DebugLevel3("Interrupt %d - %d\n"
,VideoInterrupts,(100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed);
++VideoInterrupts;
// FIXME: this solves the timer problem with WIN32
// WSACancelBlockingCall();
// kill(0,SIGALRM);
return (100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed;
}
/**
** Initialise video sync.
**
** @note SDL has only a maximum resolution of 10 ms.
**
** @see VideoSyncSpeed
*/
global void SetVideoSync(void)
{
static SDL_TimerID id;
if( id ) { // Cancel old timer.
SDL_RemoveTimer(id);
id=NULL;
}
if( !VideoSyncSpeed ) {
return;
}
id=SDL_AddTimer((100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed,
VideoSyncHandler,NULL);
// DebugLevel1("Timer installed\n");
}
#else
/**
** Initialise video sync.
**
@ -138,11 +82,9 @@ global void SetVideoSync(void)
*/
global void SetVideoSync(void)
{
DebugLevel0Fn("%d\n",(100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed);
DebugLevel0Fn("%d\n",(100*1000/CYCLES_PER_SECOND)/VideoSyncSpeed);
}
#endif
/*----------------------------------------------------------------------------
-- Video
----------------------------------------------------------------------------*/
@ -578,6 +520,15 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
}
#endif
if( !++FrameCounter ) {
// FIXME: tests with frame counter now fails :(
// FIXME: Should happen in 68 years :)
fprintf(stderr,"FIXME: *** round robin ***\n");
fprintf(stderr,"FIXME: *** round robin ***\n");
fprintf(stderr,"FIXME: *** round robin ***\n");
fprintf(stderr,"FIXME: *** round robin ***\n");
}
ticks=SDL_GetTicks();
if( ticks>NextFrameTicks ) { // We are too slow :(
++SlowFrameCounter;
@ -594,7 +545,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
}
while( ticks>=NextFrameTicks ) {
++VideoInterrupts;
NextFrameTicks+=(100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed;
NextFrameTicks+=(100*1000/CYCLES_PER_SECOND)/VideoSyncSpeed;
}
//
@ -613,10 +564,6 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
maxfd=NetworkFildes;
}
FD_SET(NetworkFildes,&rfds);
if( !NetworkInSync ) {
DebugLevel0Fn("recover-network\n");
NetworkRecover(); // recover network
}
}
#ifndef USE_SDLA
@ -679,7 +626,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
//
// Not more input and time for frame over: return
//
if( !i && NetworkInSync && VideoInterrupts ) {
if( !i && VideoInterrupts ) {
break;
}
}
@ -715,6 +662,7 @@ global void WaitEventsAndKeepSync(void)
callbacks.NetworkEvent=NetworkEvent;
callbacks.SoundReady=WriteSound;
DebugLevel0Fn("Don't use this function\n");
WaitEventsOneFrame(&callbacks);
}

View file

@ -10,12 +10,11 @@
//
/**@name svgalib.c - svgalib support. */
//
// (c) Copyright 1999-2001 by Jarek Sobieszek
// (c) Copyright 1999-2002 by Jarek Sobieszek
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -127,9 +126,9 @@ global void SetVideoSync(void)
}
itv.it_interval.tv_sec=itv.it_value.tv_sec=
(100/FRAMES_PER_SECOND)/VideoSyncSpeed;
(100/CYCLES_PER_SECOND)/VideoSyncSpeed;
itv.it_interval.tv_usec=itv.it_value.tv_usec=
(100000000/FRAMES_PER_SECOND)/VideoSyncSpeed-
(100000000/CYCLES_PER_SECOND)/VideoSyncSpeed-
itv.it_value.tv_sec*100000;
if( setitimer(ITIMER_REAL,&itv,NULL) ) {
fprintf(stderr,"Can't set itimer\n");

View file

@ -10,12 +10,11 @@
//
/**@name wince.c - WinCE video support. */
//
// (c) Copyright 2001 by
// (c) Copyright 2001,2002 by
//
// FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the License,
// or (at your option) any later version.
// by the Free Software Foundation; only version 2 of the License.
//
// FreeCraft is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -71,7 +70,7 @@
*/
global void SetVideoSync(void)
{
DebugLevel0Fn("%d\n",(100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed);
DebugLevel0Fn("%d\n",(100*1000/CYCLES_PER_SECOND)/VideoSyncSpeed);
}
/*----------------------------------------------------------------------------
@ -153,7 +152,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
i=WinCE_GetTicks();
while( i>=LastTick ) {
++VideoInterrupts;
LastTick+=(100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed;
LastTick+=(100*1000/CYCLES_PER_SECOND)/VideoSyncSpeed;
}
#endif
@ -289,7 +288,7 @@ global void WaitEventsAndKeepSync(void)
i=WinCE_GetTicks();
while( i>=LastTick ) {
++VideoInterrupts;
LastTick+=(100*1000/FRAMES_PER_SECOND)/VideoSyncSpeed;
LastTick+=(100*1000/CYCLES_PER_SECOND)/VideoSyncSpeed;
}
//