[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus ./Rules.make.in src/action/action_die...
From: |
address@hidden |
Subject: |
[Stratagus-CVS] stratagus ./Rules.make.in src/action/action_die... |
Date: |
16 Jan 2004 02:15:10 +1100 |
CVSROOT: /home/strat
Module name: stratagus
Changes by: <address@hidden> 04/01/16 02:15:09
Modified files:
. : Rules.make.in
src/action : action_die.c action_upgradeto.c
src/include : map.h stratagus.h unit.h
src/unit : unit.c unitcache.c
Log message:
New unit cache.
Patches:
Index: stratagus/Rules.make.in
diff -u stratagus/Rules.make.in:1.21 stratagus/Rules.make.in:1.22
--- stratagus/Rules.make.in:1.21 Sat Jan 10 17:18:44 2004
+++ stratagus/Rules.make.in Fri Jan 16 02:15:06 2004
@@ -51,7 +51,7 @@
IFLAGS= -I$(TOPDIR)/src/include $(XIFLAGS)
-I$(TOPDIR)/src/movie/vp31/include
address@hidden@ @DEBUG_CFLAGS@ $(IFLAGS) \
- -DUNIT_ON_MAP -DUSE_LIBMODPLUG -DUSE_HP_FOR_XP -DMAP_REGIONS\
+ -DUSE_LIBMODPLUG -DUSE_HP_FOR_XP -DMAP_REGIONS \
@PROFILE_CFLAGS@ @DEBUG_CFLAGS@ @VIDEO_CFLAGS@ @BZ2_CFLAGS@ \
@OGG_CFLAGS@ @MAD_CFLAGS@ @FLAC_CFLAGS@ @CDAUDIO_CFLAGS@ \
@LUA_CFLAGS@ $(CCL) $(VERSION) $(COMP_CFLAGS) @SOUND_CFLAGS@ @PLATFORM@
\
Index: stratagus/src/action/action_die.c
diff -u stratagus/src/action/action_die.c:1.56
stratagus/src/action/action_die.c:1.57
--- stratagus/src/action/action_die.c:1.56 Thu Jan 15 09:31:01 2004
+++ stratagus/src/action/action_die.c Fri Jan 16 02:15:07 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_die.c,v 1.56 2004/01/14 22:31:01 nobody_ Exp $
+// $Id: action_die.c,v 1.57 2004/01/15 15:15:07 nobody_ Exp $
//@{
@@ -80,6 +80,9 @@
MapUnmarkUnitSight(unit);
unit->State = unit->Type->CorpseScript;
+
+ DebugCheck(unit->Type->TileWidth !=
unit->Type->CorpseType->TileWidth ||
+ unit->Type->TileHeight !=
unit->Type->CorpseType->TileHeight);
unit->Type = unit->Type->CorpseType;
CommandStopUnit(unit); // This clears all
order queues
Index: stratagus/src/action/action_upgradeto.c
diff -u stratagus/src/action/action_upgradeto.c:1.44
stratagus/src/action/action_upgradeto.c:1.45
--- stratagus/src/action/action_upgradeto.c:1.44 Thu Jan 15 09:31:01 2004
+++ stratagus/src/action/action_upgradeto.c Fri Jan 16 02:15:07 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_upgradeto.c,v 1.44 2004/01/14 22:31:01 nobody_ Exp $
+// $Id: action_upgradeto.c,v 1.45 2004/01/15 15:15:07 nobody_ Exp $
//@{
@@ -77,6 +77,9 @@
unit->HP += stats->HitPoints -
unit->Type->Stats[player->Player].HitPoints;
// don't have such unit now
player->UnitTypesCount[unit->Type->Type]--;
+
+ DebugCheck(unit->Type->TileWidth != type->TileWidth ||
+ unit->Type->TileHeight != type->TileHeight);
unit->Type = type;
unit->Stats = (UnitStats*)stats;
// and we have new one...
Index: stratagus/src/include/map.h
diff -u stratagus/src/include/map.h:1.115 stratagus/src/include/map.h:1.116
--- stratagus/src/include/map.h:1.115 Thu Jan 15 13:05:38 2004
+++ stratagus/src/include/map.h Fri Jan 16 02:15:07 2004
@@ -27,7 +27,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: map.h,v 1.115 2004/01/15 02:05:38 jsalmon3 Exp $
+// $Id: map.h,v 1.116 2004/01/15 15:15:07 nobody_ Exp $
#ifndef __MAP_H__
#define __MAP_H__
@@ -216,6 +216,9 @@
unsigned char VisCloak[PlayerMax]; /// Visiblity for cloaking.
#ifdef UNIT_ON_MAP
Unit* UnitCache; /// An unit on the map field
+#endif
+#ifdef NEW_UNIT_CACHE
+ UnitListItem* UnitCache; /// An unit on the map field
#endif
#ifdef HIERARCHIC_PATHFINDER
unsigned short RegId; /// Region to which the field belongs
Index: stratagus/src/include/stratagus.h
diff -u stratagus/src/include/stratagus.h:1.33
stratagus/src/include/stratagus.h:1.34
--- stratagus/src/include/stratagus.h:1.33 Thu Jan 15 13:05:38 2004
+++ stratagus/src/include/stratagus.h Fri Jan 16 02:15:08 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: stratagus.h,v 1.33 2004/01/15 02:05:38 jsalmon3 Exp $
+// $Id: stratagus.h,v 1.34 2004/01/15 15:15:08 nobody_ Exp $
#ifndef __STRATAGUS_H__
#define __STRATAGUS_H__
@@ -36,6 +36,12 @@
/*============================================================================
== Config definitions
============================================================================*/
+
+// Unit On Map cache
+#define UNIT_ON_MAP
+
+// New unit cache
+// #define NEW_UNIT_CACHE
//
// Default speed for many things, set it higher for faster
actions.
Index: stratagus/src/include/unit.h
diff -u stratagus/src/include/unit.h:1.245 stratagus/src/include/unit.h:1.246
--- stratagus/src/include/unit.h:1.245 Thu Jan 15 13:05:38 2004
+++ stratagus/src/include/unit.h Fri Jan 16 02:15:08 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.h,v 1.245 2004/01/15 02:05:38 jsalmon3 Exp $
+// $Id: unit.h,v 1.246 2004/01/15 15:15:08 nobody_ Exp $
#ifndef __UNIT_H__
#define __UNIT_H__
@@ -391,7 +391,6 @@
typedef struct _unit_ Unit; /// unit itself
typedef enum _unit_action_ UnitAction; /// all possible unit actions
-
struct _spell_type_; /// base
structure of a spell type
/**
@@ -490,6 +489,15 @@
LookingNW =7*32,
/// Unit looking north west
};
+
+ /// A linked list element.
+typedef struct _unit_list_item_ UnitListItem;
+struct _unit_list_item_ {
+ Unit* Unit;
/// Points to the unit it links
+ UnitListItem* Prev; ///
Previous item.
+ UnitListItem* Next; ///
Next item.
+};
+
#define NextDirection 32 /// Next
direction N->NE->E...
#define UnitNotSeen 0x7fffffff /// Unit not seen, used
by Unit::SeenFrame
@@ -498,16 +506,20 @@
// NOTE: int is faster than shorts
int Refs;
/// Reference counter
int Slot;
/// Assigned slot number
- Unit** UnitSlot; /// Slot
pointer of Units
- Unit** PlayerSlot; /// Slot
pointer of Player->Units
+ Unit** UnitSlot; /// Slot
pointer of Units
+ Unit** PlayerSlot; /// Slot
pointer of Player->Units
- Unit* Next; ///
Generic link pointer (on map)
+ Unit* Next;
/// Generic link pointer (on map)
+#ifdef NEW_UNIT_CACHE
+ UnitListItem* CacheLinks; ///
Link nodes for unit cache
+ unsigned CacheLock : 1; ///
Used to lock unit out of the cache.
+#endif
int InsideCount;
/// Number of units inside.
- Unit* UnitInside; /// Pointer to
one of the units inside.
- Unit* Container; /// Pointer to
the unit containing it (or 0)
- Unit* NextContained; /// Next unit
in the container.
- Unit* PrevContained; /// Previous
unit in the container.
+ Unit* UnitInside; /// Pointer to
one of the units inside.
+ Unit* Container; /// Pointer to
the unit containing it (or 0)
+ Unit* NextContained; ///
Next unit in the container.
+ Unit* PrevContained; ///
Previous unit in the container.
int X;
/// Map position X
int Y;
/// Map position Y
Index: stratagus/src/unit/unit.c
diff -u stratagus/src/unit/unit.c:1.357 stratagus/src/unit/unit.c:1.358
--- stratagus/src/unit/unit.c:1.357 Thu Jan 15 10:17:29 2004
+++ stratagus/src/unit/unit.c Fri Jan 16 02:15:08 2004
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.c,v 1.357 2004/01/14 23:17:29 nobody_ Exp $
+// $Id: unit.c,v 1.358 2004/01/15 15:15:08 nobody_ Exp $
//@{
@@ -280,6 +280,12 @@
*/
global void InitUnit(Unit* unit, UnitType* type)
{
+#ifdef NEW_UNIT_CACHE
+ int i;
+#endif
+
+ DebugCheck(!type);
+
// Refs need to be *increased* by 1, not *set* to 1, because if
InitUnit()
// is called from game loading code, Refs can already have a nonzero
// value (thanks to forward references in the save file). Incrementing
@@ -300,6 +306,14 @@
// Initialise unit structure (must be zero filled!)
//
unit->Type = type;
+#ifdef NEW_UNIT_CACHE
+ unit->CacheLinks = (UnitListItem *)malloc(type->TileWidth *
type->TileHeight * sizeof(UnitListItem));
+ for (i = 0; i < type->TileWidth * type->TileHeight; ++i) {
+ unit->CacheLinks[i].Prev = unit->CacheLinks[i].Next = 0;
+ unit->CacheLinks[i].Unit = unit;
+ }
+#endif
+
unit->Seen.Frame = UnitNotSeen; // Unit isn't
yet seen
unit->Frame = unit->Type->Animations->Still[0].Frame +
@@ -2843,6 +2857,8 @@
if (type->CorpseType) {
unit->State = unit->Type->CorpseScript;
+ DebugCheck(type->TileWidth !=
type->CorpseType->TileWidth ||
+ type->TileHeight !=
type->CorpseType->TileHeight);
type = unit->Type = type->CorpseType;
unit->IX = (type->Width -
VideoGraphicWidth(type->Sprite)) / 2;
@@ -3754,7 +3770,7 @@
int j;
CLprintf(file, "\n--- -----------------------------------------\n");
- CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.357 2004/01/14
23:17:29 nobody_ Exp $\n\n");
+ CLprintf(file, "--- MODULE: units $Id: unit.c,v 1.358 2004/01/15
15:15:08 nobody_ Exp $\n\n");
#if 0
//
Index: stratagus/src/unit/unitcache.c
diff -u stratagus/src/unit/unitcache.c:1.43 stratagus/src/unit/unitcache.c:1.44
--- stratagus/src/unit/unitcache.c:1.43 Thu Jan 15 11:56:29 2004
+++ stratagus/src/unit/unitcache.c Fri Jan 16 02:15:09 2004
@@ -30,7 +30,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unitcache.c,v 1.43 2004/01/15 00:56:29 jsalmon3 Exp $
+// $Id: unitcache.c,v 1.44 2004/01/15 15:15:09 nobody_ Exp $
//@{
@@ -43,19 +43,10 @@
#include <string.h>
#include "stratagus.h"
-
-#ifdef UNIT_ON_MAP
-
-/*----------------------------------------------------------------------------
--- Includes
-----------------------------------------------------------------------------*/
-
#include "unit.h"
#include "map.h"
-//*****************************************************************************
-// Convert calls to internal
-//****************************************************************************/
+#ifdef UNIT_ON_MAP
/**
** Insert new unit into cache.
@@ -236,3 +227,220 @@
}
#endif // } UNIT_ON_MAP
+
+#ifdef NEW_UNIT_CACHE
+
+/**
+** Insert new unit into cache.
+**
+** @param unit Unit pointer to place in cache.
+*/
+global void UnitCacheInsert(Unit* unit)
+{
+ int i;
+ int j;
+ MapField* mf;
+ UnitListItem* listitem;
+
+ DebugLevel3Fn("%d,%d %d %s\n" _C_ unit->X _C_ unit->Y _C_ unit->Slot
_C_ unit->Type->Name);
+ for (i = 0; i < unit->Type->TileHeight; ++i) {
+ for (j = 0; j < unit->Type->TileWidth; ++j) {
+ mf = TheMap.Fields + (i + unit->Y) * TheMap.Width + j +
unit->X;
+ listitem = unit->CacheLinks + i * unit->Type->TileWidth
+ j;
+
+ // Always add at the start of the list.
+ listitem->Next = mf->UnitCache;
+ listitem->Prev = 0;
+ // update Prev link if cache on tile is no empty
+ if (mf->UnitCache) {
+ mf->UnitCache->Prev = listitem;
+ }
+ mf->UnitCache = listitem;
+ }
+ }
+}
+
+/**
+** Remove unit from cache.
+**
+** @param unit Unit pointer to remove from cache.
+*/
+global void UnitCacheRemove(Unit* unit)
+{
+ int i;
+ int j;
+ MapField* mf;
+ UnitListItem* listitem;
+
+ DebugLevel3Fn("%d,%d %d %s\n" _C_ unit->X _C_ unit->Y _C_ unit->Slot
_C_ unit->Type->Name);
+ for (i = 0; i < unit->Type->TileHeight; ++i) {
+ for (j = 0; j < unit->Type->TileWidth; ++j) {
+ mf = TheMap.Fields + (i + unit->Y) * TheMap.Width + j +
unit->X;
+ listitem = unit->CacheLinks + i * unit->Type->TileWidth
+ j;
+
+ if (listitem->Next) {
+ listitem->Next->Prev = listitem->Prev;
+ }
+ if (listitem->Prev) {
+ listitem->Prev->Next = listitem->Next;
+ } else {
+ if (mf->UnitCache != listitem) {
+ DebugLevel0Fn("Try to remove unit not
in cache. It's ok, mostly.\n");
+ }
+ // item is head of the list.
+ mf->UnitCache = listitem->Next;
+ DebugCheck(mf->UnitCache &&
mf->UnitCache->Prev);
+ }
+
+ listitem->Next = listitem->Prev = 0;
+ }
+ }
+}
+
+/**
+** Change unit in cache.
+** FIXME: optimize, add destination to parameters
+**
+** @param unit Unit pointer to change in cache.
+*/
+global void UnitCacheChange(Unit* unit)
+{
+ UnitCacheRemove(unit);
+ UnitCacheInsert(unit);
+}
+
+/**
+** Select units in rectangle range.
+**
+** @param x1 Left column of selection rectangle
+** @param y1 Top row of selection rectangle
+** @param x2 Right column of selection rectangle
+** @param y2 Bottom row of selection rectangle
+** @param table All units in the selection rectangle
+**
+** @return Returns the number of units
found
+*/
+global int UnitCacheSelect(int x1, int y1, int x2, int y2, Unit** table)
+{
+ int i;
+ int j;
+ int n;
+ UnitListItem* listitem;
+
+ //
+ // Reduce to map limits. FIXME: should the caller check?
+ //
+ if (x1 < 0) {
+ x1 = 0;
+ }
+ if (y1 < 0) {
+ y1 = 0;
+ }
+ if (x2 > TheMap.Width) {
+ x2 = TheMap.Width;
+ }
+ if (y2 > TheMap.Height) {
+ y2 = TheMap.Height;
+ }
+ DebugLevel3Fn("%d,%d %d,%d\n" _C_ x1 _C_ y1 _C_ x2 _C_ y2);
+
+ n = 0;
+ for (i = y1; i < y2; ++i) {
+ for (j = x1; j < x2; ++j) {
+ listitem = TheMap.Fields[i * TheMap.Width +
j].UnitCache;
+ for (; listitem; listitem = listitem->Next) {
+ //
+ // To avoid getting an unit in multiple
times we use a cache lock.
+ // It should only be used in here, unless
you somehow want the unit
+ // to be out of cache.
+ //
+ if (!listitem->Unit->CacheLock) {
+ listitem->Unit->CacheLock = 1;
+ table[n++] = listitem->Unit;
+ }
+ }
+ }
+ }
+
+ //
+ // Clean the cache locks, restore to original situation.
+ //
+ for (i = 0; i < n; ++i) {
+ table[i]->CacheLock = 0;
+ }
+
+ return n;
+}
+
+/**
+** Select units on map tile.
+**
+** @param x Map X tile position
+** @param y Map Y tile position
+** @param table All units in the selection rectangle
+**
+** @return Returns the number of units
found
+*/
+global int UnitCacheOnTile(int x, int y, Unit** table)
+{
+ UnitListItem* listitem;
+ int n;
+
+ //
+ // Unlike in UnitCacheSelect, there's no way an unit can show up
twice,
+ // so there is no need for Cache Locks.
+ //
+ n = 0;
+ listitem = TheMap.Fields[y * TheMap.Width + x].UnitCache;
+ for (; listitem; listitem = listitem->Next) {
+ if (!listitem->Unit->CacheLock) {
+ table[n++] = listitem->Unit;
+ }
+ }
+
+ return n;
+}
+
+/**
+** Select unit on X,Y of type naval,fly,land.
+**
+** @param x Map X tile position.
+** @param y Map Y tile position.
+** @param type UnitType::UnitType, naval,fly,land.
+**
+** @return Unit, if an unit of correct
type is on the field.
+*/
+global Unit* UnitCacheOnXY(int x, int y, unsigned type)
+{
+ Unit* table[UnitMax];
+ int n;
+
+ n = UnitCacheOnTile(x, y, table);
+ while (n--) {
+ if ((unsigned)table[n]->Type->UnitType == type) {
+ break;
+ }
+ }
+ if (n > -1) {
+ return table[n];
+ } else {
+ return NoUnitP;
+ }
+}
+
+/**
+** Print unit-cache statistic.
+*/
+global void UnitCacheStatistic(void)
+{
+ // FIXME: stats about query sizes.. you can get the rest by profiling.
+}
+
+/**
+** Initialize unit-cache.
+*/
+global void InitUnitCache(void)
+{
+}
+
+#endif // } NEW_UNIT_CACHE
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus ./Rules.make.in src/action/action_die...,
address@hidden <=