301 Days

A year of gamedev experiments.

Day 7 - Housekeeping

| Comments

A little cleaning up before we proceed…


Careful and Precise Management of Resources

From our end-of-day-five list, we have two things left to clean up. First we’ll tackle “The location table doesn’t get cleared when we restart the game server.” It’s round 17, but we have NPC data from round 47 of a previous run still in the database. We should clear things out each time the server is restarted:

prApp_NPCLocation_ClearGitLab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
USE [dragonsspine]
GO

/****** Object:  StoredProcedure [dbo].[prApp_NPCLocation_Clear]    Script Date: 08/31/2015 22:40:33 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


----------------------------------------------------------------------------
-- Clear all entries from the NPCLocation table
----------------------------------------------------------------------------
CREATE PROC [dbo].[prApp_NPCLocation_Clear]

AS

DELETE NPCLocation

GO
DAL.DALNPC.ClearNPCLocationDataGitLab
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
internal static bool ClearNPCLocationData() {
    int result = 0;
    try {
        lock (lockObjectNpcLocationUpdate) {
            string sptouse = "prApp_NPCLocation_Clear";
            using (SqlConnection tempConnection = DataAccess.GetSQLConnection())
            using (SqlStoredProcedure sp = new SqlStoredProcedure(sptouse, tempConnection)) {
                result = sp.ExecuteNonQuery();
            }
            DAL.DBNPC.npcsToUpdate.Clear();
        }
    } catch (Exception e) {
        Utils.LogException(e);
        return false;
    }
    return (result >= 0);
}
NPC.ClearNPCLocationDataGitLab
592
593
594
public static void ClearNPCLocationData() {
    DAL.DBNPC.ClearNPCLocationData();
}

We’ll put the call in Main, during the server bring-up, between establishing spawn zones and loading the NPC catalog:

MainGitLab
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#region Establish Spawn Zones
if (!Facet.EstablishSpawnZones())
{
    Utils.Log("Facet.EstablishSpawnZones() failed.", Utils.LogType.SystemFatalError);
    return -1;
}
#endregion

#region Clear NPC Location Data
Utils.Log("Clearing NPC Location Data.", Utils.LogType.SystemGo);
NPC.ClearNPCLocationData();
#endregion

#region Create NPC Catalog
Utils.Log("Creating NPC Catalog.", Utils.LogType.SystemGo);
NPC.LoadNPCDictionary();
#endregion

And now, much tidier:

The next thing is to get the visualizer to only show current NPCs, but that will take a bit of doing. Tomorrow, then.


Day 7 code - server

Comments